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:

    1. Click the Projects menu item.
    2. In the New Project dialog, select Visual C++\MFC AppWizard (exe) as the project type and select "MFC Application" for the template.
    3. In the Project name text box, specify a name (for example "chartest").
    4. In the Location text box, specify the path of the project.
    5. Click the OK button.
  2. In the Step 1 dialog box, do the following: Click Next on the next wizard.

    1. Select Dialog based.
    2. 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. (keep in mind, to change the XX to current LEADTOOLS version) 
    #define LTVXX_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:\LEADTOOLS21\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:\\LEADTOOLS21\\Resources\\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:\\LEADTOOLS21\\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.

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

LEADTOOLS Raster Imaging C++ Class Library Help
Products | Support | Contact Us | Intellectual Property Notices
© 1991-2021 LEAD Technologies, Inc. All Rights Reserved.