Provides a quick and easy way to enumerate WIA devices.
Note For more in-depth WIA programming, refer to the WIA demo.
Create a new directory in the Examples\Scanning\CDLL directory called WiaTutorial.
Copy everything in the \Examples\FileFormats\CDLL\SimpleLoad directory into the WiaTutorial directory.
Compile the project as it is and run SimpleLoad.exe to familiarize yourself with the basic program.
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)
Add the following line in StdAfx.h in the WiaTutorial directory:
#include "..\..\..\include\ltwia.h"
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
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
In the InitApplication function change the line:
wcWindowClass.lpszMenuName = NULL; /* No menu */
to be
wcWindowClass.lpszMenuName = TEXT("MAIN_MENU");
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;
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;
In the WM_DESTROY message handler add the following code at the end of it (before the PostQuitMessage(0);
):
L_WiaEndSession(hSession);
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;
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;
}
Compile and test the program.