////////////////////////////////////////////////////////////////////// // PUT THE FOLLOWING DECLARATIONS IN THE HEADER FILE ////////////////////////////////////////////////////////////////////// HINSTANCE FFLibDllHandle; bool ( __stdcall *pfnFFAspiStart )( HWND ); void ( __stdcall *pfnFFAspiStop )( void ); void ( __stdcall *pfnFFScan )( HANDLE, void*, int, int, int, int, int, int, int ); void ( __stdcall *pfnFFExpand1bpp8bpp )( void*, int, void* ); int ( __stdcall *pfnFFOMR )( int, int, int, int, int, int, int, int, int, int, int, void*, char* ); int ( __stdcall *pfnFFView )( HWND, void*, int, int, void*, void* ); ////////////////////////////////////////////////////////////////////// // SECTION ONE --- PRELIMINARY OPERATIONS ////////////////////////////////////////////////////////////////////// // load the DLL FFLibDllHandle = 0; FFLibDllHandle = LoadLibrary ( "FFLIB.DLL" ); if ( FFLibDllHandle == 0 ) { MessageBox ( NULL, "LoadLibrary:\nFFLIB.DLL not found.", "Error FS 001", MB_SYSTEMMODAL ); PostQuitMessage ( 0 ); } // load FFAspiStart address pfnFFAspiStart = ( bool ( __stdcall *)( HWND ) ) GetProcAddress ( FFLibDllHandle, "FFAspiStart" ); if ( pfnFFAspiStart == NULL ) { MessageBox ( NULL, "GetProcAddress:\nFFAspiStart not found.", "Error FS 002", MB_SYSTEMMODAL ); PostQuitMessage ( 0 ); } // check ASPI support if ( pfnFFAspiStart ( Application -> Handle ) == false ) { MessageBox ( NULL, "No ASPI support.", "Error FS 005", MB_SYSTEMMODAL ); PostQuitMessage ( 0 ); } // load FFAspiStop address pfnFFAspiStop = ( void ( __stdcall *)( void ) ) GetProcAddress ( FFLibDllHandle, "FFAspiStop" ); if ( pfnFFAspiStop == NULL ) { MessageBox ( NULL, "GetProcAddress:\nFFAspiStop not found.", "Error FS 004", MB_SYSTEMMODAL ); PostQuitMessage ( 0 ); } // load the address of FFScan pfnFFScan = ( void ( __stdcall *)( HANDLE, void*, int, int, int, int, int, int, int ) ) GetProcAddress ( FFLibDllHandle, "FFScan" ); if ( pfnFFScan == NULL ) { MessageBox ( NULL, "GetProcAddress:\nFFScan not found.", "Errore FS 003", MB_SYSTEMMODAL ); PostQuitMessage ( 0 ); } // load the address of FFExpand1bpp8bpp pfnFFExpand1bpp8bpp = ( void ( __stdcall *)( void*, int, void* ) ) GetProcAddress ( FFLibDllHandle, "FFExpand1bpp8bpp" ); if ( pfnFFExpand1bpp8bpp == NULL ) { MessageBox ( NULL, "GetProcAddress:\nFFExpand1bpp8bpp not found.", "Errore FS 003", MB_SYSTEMMODAL ); PostQuitMessage ( 0 ); } // load the address of FFOMR pfnFFOMR = ( int ( __stdcall *)( int, int, int, int, int, int, int, int, int, int, int, void*, char* ) ) GetProcAddress ( FFLibDllHandle, "FFOMR" ); if ( pfnFFOMR == NULL ) { MessageBox ( NULL, "GetProcAddress:\nFFOMR not found.", "Errore FS 003", MB_SYSTEMMODAL ); PostQuitMessage ( 0 ); } // load the address of FFView pfnFFView = ( int ( __stdcall *)( HWND, void*, int, int, void*, void* ) ) GetProcAddress ( FFLibDllHandle, "FFView" ); if ( pfnFFView == NULL ) { MessageBox ( NULL, "GetProcAddress:\nFFView not found.", "Errore FS 003", MB_SYSTEMMODAL ); PostQuitMessage ( 0 ); } ////////////////////////////////////////////////////////////////////// // SECTION TWO --- SCAN THE IMAGE ////////////////////////////////////////////////////////////////////// // allocate a one-bit-per-pixel buffer to accomodate the data coming from // the scanner HGLOBAL pFrame1bpp = GlobalAlloc ( GMEM_FIXED, 1664/8 * 2336 ); // scan a page (5th parameter: 0=flatbed, 1=AutimaticDocumentFeeder) pfnFFScan ( Application -> Handle, pFrame1bpp, 1664, 2336, 0, 128, 0, 6, 0 ); // allocate a one-byte-per-pixel buffer to expand the image from one bit per // pixel to one byte per pixel; in fact both pfnOMR and pfnView *expect* this // latter format (0x00 and 0xFF being respectively a black and a white pixels) HGLOBAL pFrame8bpp = GlobalAlloc ( GMEM_FIXED, 1664 * 2336 ); // expand the data from the first buffer to the second buffer pfnFFExpand1bpp8bpp ( pFrame1bpp, 1664/8*2336, pFrame8bpp ); ////////////////////////////////////////////////////////////////////// // SECTION THREE --- RECOGNIZE THE MARKS ////////////////////////////////////////////////////////////////////// // there are 18 rows and 3 columns of potential marks in the sample test form // provided in my web page, hence allocate the proper buffer char szResult [ ( 18 * 3 ) + 1 ]; // call the recognition function (if rc != 0 the recognition has gone wrong) int rc = pfnFFOMR ( 1664/8, 2336, 1, 18, 3, 1196, 426, 240, 1604, 6, 20, pFrame8bpp, szResult ); // REMEMBER to examine the string szResult to get the recognized marks: it is a // series of ASCII 1s and 0s, respectively meaning mark found and not found. Think // of the recognition grid (see above) as a matrix: each byte in the string is a // potential mark position, top to down, left to right. In this example the matrix // is 18 rows by 3 columns, hence szResult will yeld 54 bytes (plus the final // ASCIIZ zero byte, of course) ////////////////////////////////////////////////////////////////////// // SECTION FOUR --- DISPLAY THE RESULTS ////////////////////////////////////////////////////////////////////// // call the image display function to see the results Form1 -> WindowState = wsMinimized; pfnFFView ( Application -> Handle, pFrame8bpp, 1664/8, 2336, 0, 0 ); Form1 -> WindowState = wsNormal; ////////////////////////////////////////////////////////////////////// // SECTION FIVE --- FINAL OPERATION ////////////////////////////////////////////////////////////////////// // free the memory in reverse order GlobalFree ( pFrame8bpp ); GlobalFree ( pFrame1bpp ); // stop ASPI support pfnFFAspiStop ( ); // free the DLL if ( FFLibDllHandle != 0 ) FreeLibrary ( FFLibDllHandle );