////////////////////////////////////////////////////////////////////// // 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 *pfnFFView )( HWND, void*, int, int, void*, void* ); int ( __stdcall *pfnFFTiffServices )( int, HANDLE, void*, int, int ); int ( __stdcall *pfnFFComp )( HGLOBAL, int, HANDLE, int, int ); ////////////////////////////////////////////////////////////////////// // 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 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 ); } // load the address of FFTiffServices pfnFFTiffServices = ( int ( __stdcall *)( int, HANDLE, void*, int, int ) ) GetProcAddress ( FFLibDllHandle, "FFTiffServices" ); if ( pfnFFTiffServices == NULL ) { MessageBox ( NULL, "GetProcAddress:\nFFTiffServices not found.", "Errore FS 003", MB_SYSTEMMODAL ); PostQuitMessage ( 0 ); } // load the address of FFComp (group IV-2d CCITT compressor) pfnFFComp = ( int ( __stdcall *)( HGLOBAL, int, HANDLE, int, int ) ) GetProcAddress ( FFLibDllHandle, "FFComp" ); if ( pfnFFComp == NULL ) { MessageBox ( NULL, "GetProcAddress:\nFFComp not found.", "Errore FS 003", MB_SYSTEMMODAL ); PostQuitMessage ( 0 ); } ////////////////////////////////////////////////////////////////////// // SECTION TWO --- SCAN A PAGE ////////////////////////////////////////////////////////////////////// // INFORMATION: an A4 sheet is 210 by 297 millimeters. At 200 dpi its // width is 1664 pixels and its length is 2336 lines // allocate a buffer for one A4 image at 1 *bit* per pixel int frameSize; // frame size in bytes frameSize = 1664 * 2336 / 8; // at 1 *bit* per pixel HGLOBAL pFrame1bpp = GlobalAlloc ( GMEM_FIXED, frameSize ); // scan the A4 page b&w from the flatbed (5th parameter = 0) pfnFFScan ( Application -> Handle, pFrame1bpp, 1664, 2336, 0, 128, 0, 6, 0 ); ////////////////////////////////////////////////////////////////////// // SECTION THREE --- DISPLAY THE SCANNED PAGE ////////////////////////////////////////////////////////////////////// // INFORMATION: even if the image is b&w the image display routine (pointed // to by pfnFFView) should be represented at 1 byte per pixel. For this // reason now it is necessary to expand the image from 1 bit per pixel to // 1 byte per pixel // allocate a buffer for one A4 image at 1 *byte* per pixel frameSize = 1664 * 2336; HGLOBAL pFrame8bpp = GlobalAlloc ( GMEM_FIXED, frameSize ); // expand the image from 1 bit per pixel to 1 byte per pixel; in the expanded // frame buffer 0x00 means a black pixel and 0xFF means a white pixel pfnFFExpand1bpp8bpp ( pFrame1bpp, 1664/8*2336, pFrame8bpp ); // call the image display routine to see the just scanned image Form1 -> WindowState = wsMinimized; pfnFFView ( Application -> Handle, pFrame8bpp, 1664/8, 2336, 0, 0 ); Form1 -> WindowState = wsNormal; ////////////////////////////////////////////////////////////////////// // SECTION FOUR --- PUT THE IMAGE OF THE SCANNED PAGE INTO A TIFF FILE ////////////////////////////////////////////////////////////////////// // prepare the name of the TIFF file that will contain the image // (you can use whatever name you want) char szTiffFile [ 1024 ]; strcpy ( szTiffFile, "C:\\LAVORI\\SITO2\\SCAN\\MY_FILE.TIF" ); // create and start writing the TIFF file HANDLE handle; // then cast "handle" to an int (int) handle = pfnFFTiffServices ( 6, szTiffFile, "any comment", 1664, 2336 ); if ( handle == 0 ) { MessageBox ( NULL, "Can't create TIFF output file.", "Errore FS 018", MB_SYSTEMMODAL ); PostQuitMessage ( 0 ); } // compress the image from the frame buffer into the file pfnFFComp ( pFrame8bpp, 0, handle, 1664/8, 2336 ); // finish writing the TIFF file and close it pfnFFTiffServices ( 7, handle, NULL, NULL, NULL ); ////////////////////////////////////////////////////////////////////// // SECTION FIVE --- FINAL OPERATIONS ////////////////////////////////////////////////////////////////////// // free the memory in reverse order GlobalFree ( pFrame8bpp ); GlobalFree ( pFrame1bpp ); // stop ASPI support pfnFFAspiStop ( ); // free the DLL if ( FFLibDllHandle != 0 ) FreeLibrary ( FFLibDllHandle );