Products | Support | Send comments on this topic. | Email a link to this topic. | Back to Getting Started | Help Version 18.0.6.11
LEADTOOLS Raster imaging C++ Class library help

Using the UNICODE version of LEADTOOLS in a non-UNICODE Application (C++ 5.0 and later)

Show in webframe

Take the following steps to create and run a program that uses the UNICODE version of LEADTOOLS in a non-UNICODE application.

1.

Start a new project as follows:

 

Run Microsoft Visual Studio, select the File >New menu option, and do the following:

 

a.

Click the Projects menu item.

 

b.

In the New Project dialog, select Visual C++\MFC AppWizard (exe) as the project type and select "MFC Application" for the template.

 

c.

In the Project name text box, specify a name (for example "chartest").

 

d.

In the Location text box, specify the path of the project.

 

e.

Click the OK button.

2.

In the Step 1 dialog box, do the following: Click Next on the next wizard.

 

a.

Select Dialog based.

 

b.

Click the Finish button.

3.

From the main menu, select Project->Properties. Under Configuration\General, set the "Character Set" to "Not Set". Click OK button.

4.

Edit the stdafx.h and add to the end of the file the following code (Note: you will have to change the path of ltwrappr.h to match the LEADTOOLS installation directory on your system):

// Define the version of LEADTOOLS you are using
#define LTV18_CONFIG
// Force using UNICODE version of LEADTOOLS (we will need to convert all strings)
#define _LEAD_FORCE_UNICODE
// Include the LEADTOOLS C++ Class Library header file
#include "C:\LEADTOOLS 18\Include\ClassLib\LtWrappr.h"
// Utility macro - Note: You may have to change the path to match your system.
#define MAKE_IMAGE_PATH(pFileName) TEXT("C:\\Users\\Public\\Documents\\LEADTOOLS Images\\")pFileName

5.

Edit stdafx.cpp and replace the contents of the file with the following code (Note: you will have to change the path to the .lib files to match your system):

// stdafx.cpp : source file that includes just the standard includes
// chartest2.pch will be the pre-compiled header
// stdafx.obj will contain the pre-compiled type information
#include "stdafx.h"
#pragma comment(lib, "C:\\LEADTOOLS 18\\Lib\\CDLL\\Win32\\Ltwvc_u.lib")

6.

Add a command button to your form and name it as follows:

 

ID

Caption

 

IDC_FILEINFO

File Info

7.

Double Click on the new button and Add the following code:

L_INT nRet;
FILEINFO FileInfo; /* LEAD File Information structure. */
LFile File;
char szMessage[1024]; /* Buffer to hold information for display. */
char szInputFile[_MAX_PATH]=MAKE_IMAGE_PATH("IMAGE1.CMP");

LSettings::LoadLibraries
(LT_FIL);
/* Convert non-UNICODE to UNICODE */
L_TCHAR wcsInputFile[_MAX_PATH]=L"\0";
mbstowcs(wcsInputFile, szInputFile, _MAX_PATH);

/* Get the file information */
FileInfo.uStructSize = sizeof(FileInfo);
File.SetFileName(wcsInputFile);
nRet = File.GetInfo(&FileInfo, sizeof(FILEINFO), 0, NULL);
if(nRet != SUCCESS)
return;

/* Convert UNICODE to non-UNICODE */
char szName[16];
wcstombs(szName, FileInfo.Name, 16);
char szCompression[20];
wcstombs(szCompression, FileInfo.Compression, 20);

/* Format the message string with data from the FILEINFO structure */
wsprintf(szMessage, "Filename: %s\n\n"
"Format: %d\n\n"
"Width: %d\n\n"
"Height: %d\n\n"
"BitsPerPixel: %d\n\n"
"Size On Disk: %ld\n\n"
"Size In Memory: %ld\n\n"
"Compression: %s",
szName,
FileInfo.Format,
FileInfo.Width,
FileInfo.Height,
FileInfo.BitsPerPixel,
FileInfo.SizeDisk,
FileInfo.SizeMem,
szCompression );
/* Display the message string */
MessageBox(NULL, szMessage, "File Information", MB_OK);

LSettings::UnloadLibraries
(LT_FIL);

8.

On the main menu, select Build > Build chartest.exe to build the project.

9.

On the main menu, select Build > Execute chartest.exe to run the project.

Products | Support | Contact Us | Copyright Notices
© 2006-2014 All Rights Reserved. LEAD Technologies, Inc.