Acquire Images from a WIA Source

Note: The purpose of this WIA tutorial is to provide you a quick and easy way to acquire images from a WIA source. For more in-depth WIA programming, refer to the WIA demo.

To acquire images from a WIA source:

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_SELECT_SOURCE        200
#define IDM_ACQUIRE              201
 

7.

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

#include "EZFUNC.H"
 
MAIN_MENU   MENU
BEGIN
   MENUITEM "Select Source"   IDM_SELECT_SOURCE
   MENUITEM "Acquire"         IDM_ACQUIRE 
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_SELECT_SOURCE: 
            {
            }
            break; 
         case IDM_ACQUIRE: 
            {
            }
            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_SELECT_SOURCE menu handler add the following code:

 

case IDM_SELECT_SOURCE:
   {
      nRet = L_WiaSelectDeviceDlg(hSession, hWnd, WiaDeviceTypeDefault, L_WIA_SELECT_DEVICE_NODEFAULT);
   }
   break; 

13.

In the IDM_ACQUIRE menu handler add the following code:

case IDM_ACQUIRE: 
{
nRet = L_WiaAcquire(hSession, hWnd, L_WIA_SHOW_USER_INTERFACE|L_WIA_DEVICE_DIALOG_USE_COMMON_UI, NULL, NULL, NULL, NULL, WiaAcquireCB, NULL);
if (nRet != WIA_SUCCESS) 
return nRet; 
InvalidateRect (hWnd, NULL, FALSE); 
}
break; 

14.

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

 

L_INT CALLBACK WiaAcquireCB(HWIASESSION hSession, pBITMAPHANDLE pBitmap, L_TCHAR * pszFilename, L_UINT32 uPercent, L_UINT32 uFlags, L_VOID * pUserData)

{
   UNREFERENCED_PARAMETER(hSession);
   UNREFERENCED_PARAMETER(pUserData);
   UNREFERENCED_PARAMETER(pszFilename);
   UNREFERENCED_PARAMETER(uPercent);
   UNREFERENCED_PARAMETER(uFlags);
   if(pBitmap)
   {
      if(pBitmap->Flags.Allocated)
      {
        if (LeadBitmap.Flags.Allocated)
         L_FreeBitmap(&LeadBitmap);
               L_CopyBitmap(&LeadBitmap, pBitmap, sizeof(BITMAPHANDLE));
        L_FreeBitmap(pBitmap);
        pBitmap = NULL;
      }
   }
   return WIA_SUCCESS;
}

15.

Compile and test the program.