Enumerate WIA Devices

✎ NOTE

The purpose of this WIA tutorial is to provide you a quick and easy way to enumerate WIA devices. For more in-depth WIA programming, refer to the WIA demo.

To enumerate the WIA devices installed on your machine:

  1. Create a new directory in the \Examples\CDLL directory called WiaTutorial.

  2. Copy everything in the SimpleLoad directory into the WiaTutorial directory.

  3. Compile the project as it is and run SimpleLoad.exe to familiarize yourself with the basic program.

  4. In the Imports.cpp, add the following lines:

    #if defined(WIN64) 
       #pragma comment(lib, "..\\..\\..\\Lib"L_VER_DESIGNATOR"\\CDLL\\x64\\Ltwia_x.lib") 
    #else 
       #pragma comment(lib, "..\\..\\..\\Lib"L_VER_DESIGNATOR"\\CDLL\\Win32\\Ltwia_u.lib") 
    #endif // #if defined(WIN64) 

  5. Add the following line in StdAfx.h in the WiaTutorial directory:

    #include "..\..\..\include\ltwia.h" 

  6. Define the following global variable in Ezfunc.h in the WiaTutorial directory:

        HWIASESSION hSession = NULL; 

    Also, add the following defines:

        #define IDM_ENUMERATE_WIA_DEVICES        200 

  7. Edit EZFUNC.RC file in the WiaTutorial directory and add the following lines:

    #include "EZFUNC.H" 
     
    MAIN_MENU   MENU 
    BEGIN 
       MENUITEM "Enumerate WIA Devices"   IDM_ENUMERATE_WIA_DEVICES 
    END 

  8. In the InitApplication function change the line:

        wcWindowClass.lpszMenuName = NULL;  /* No menu */ 

    to be

        wcWindowClass.lpszMenuName = TEXT("MAIN_MENU"); 

  9. In the MainWndProc function and before the handling of the WM_PALETTECHANGED message add the following code:

    case WM_COMMAND: 
    { 
       switch (LOWORD(wParam)) 
       { 
          case IDM_ENUMERATE_WIA_DEVICES: 
          { 
          } 
          break; 
       } 
    } 
    break; 

  10. In the WM_CREATE message handler add the following code at the end of it (after SendMessage(hWnd, WM_QUERYNEWPALETTE, 0, 0L);):

    nRet = L_WiaInitSession(WiaVersion1, &hSession); 
    if (nRet != WIA_SUCCESS) 
       return FALSE; 

  11. In the WM_DESTROY message handler add the following code at the end of it (before the PostQuitMessage(0);):

    L_WiaEndSession(hSession); 

  12. In the IDM_ENUMERATE_WIA_DEVICES menu handler add the following code:

    case IDM_ENUMERATE_WIA_DEVICES: 
    { 
       nRet = L_WiaEnumDevices(hSession, WiaEnumDevicesCB, NULL); 
       if (nRet != WIA_SUCCESS) 
          return FALSE; 
    } 
    break; 

  13. In Ezfunc.cpp file, add the following function before MainWndProc function:

    L_INT CALLBACK WiaEnumDevicesCB(HWIASESSION hSession, pLWIADEVICEID pDeviceID, L_VOID * pUserData) 
    { 
       UNREFERENCED_PARAMETER(hSession); 
       UNREFERENCED_PARAMETER(pUserData); 
       L_TCHAR szDeviceInfo[MAX_PATH] = TEXT(""); 
       wsprintf(szDeviceInfo, 
          TEXT("Device ID: %s\nDevice Name: %s\nDevice Desc.:%s"), 
          pDeviceID->pszDeviceId, 
          pDeviceID->pszDeviceName, 
          pDeviceID->pszDeviceDesc); 
       MessageBox(NULL, 
          szDeviceInfo, 
          TEXT("Available WIA Devices"), 
          MB_OK | MB_ICONINFORMATION); 
       return WIA_SUCCESS; 
    } 

  14. Compile and test the program.

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

LEADTOOLS WIA C API Help
Products | Support | Contact Us | Intellectual Property Notices
© 1991-2021 LEAD Technologies, Inc. All Rights Reserved.