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, 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) 
// Include the LEADTOOLS C++ Class Library header file   
#include "C:\LEADTOOLS 20\Include\ClassLib\LtWrappr.h"   
// Utility macro - Note: You might have to change the path to match your system.   
#define MAKE_IMAGE_PATH(pFileName) TEXT("C:\\Users\\Public\\Documents\\LEADTOOLS Images\\")pFileName   


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 20\\Lib\\CDLLVC10\\Win32\\Ltwvc_u.lib") 

6. Add a command button to your form and name it as follows:
  ID Caption
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);   
nRet = File.GetInfo(&FileInfo, sizeof(FILEINFO), 0, NULL);   
if(nRet != SUCCESS)   
/* 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",   
szCompression );   
/* Display the message string */   
MessageBox(NULL, szMessage, "File Information", MB_OK);    
LSettings::UnloadLibraries (LT_FIL); 


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


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

Help Version 20.0.2020.4.5
Products | Support | Contact Us | Intellectual Property Notices
© 1991-2020 LEAD Technologies, Inc. All Rights Reserved.

LEADTOOLS Raster Imaging C++ Class Library Help