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

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 2005, 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.

 

c.

Click the Finish button.

4.

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

5.

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):

#include "c:\Program Files\LEAD Technologies\LEADTOOLS 15\include\ClassLib\LtWrappr.h"

6.

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, "E:\\Program Files\\LEAD Technologies\\LEADTOOLS 15\\Lib\\API\\Win32\\Ltwvc_u.lib")

7.

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

 

ID

Caption

 

IDC_FILEINFO

File Info

8.

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]="E:\\Program Files\\LEAD Technologies\\LEADTOOLS 15\\Images\\IMAGE3.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(szMessage, "File Information", MB_OK);

LSettings::UnloadLibraries
(LT_FIL);

9.

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

10.

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