////////////////////////////////////////////////////////////////////// // PUT THE FOLLOWING DECLARATIONS IN THE HEADER FILE ////////////////////////////////////////////////////////////////////// HINSTANCE FFLibDllHandle; int ( __stdcall *pfnFFTiffServices )( int, HANDLE, void*, int, int ); int ( __stdcall *pfnFFDec )( HANDLE, int, void*, int, int, int ); 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 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 FFDec (group IV-2d CCITT decompressor) pfnFFDec = ( int ( __stdcall *)( HANDLE, int, void*, int, int, int ) ) GetProcAddress ( FFLibDllHandle, "FFDec" ); if ( pfnFFDec == NULL ) { MessageBox ( NULL, "GetProcAddress:\nFFDec 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 --- OPEN AND DECOMPRESS A TIFF FILE ////////////////////////////////////////////////////////////////////// // set the name of the image to be decompressed and viewed char filePathAndName [ 256 ]; strcpy ( filePathAndName, "C:\\Lavori\\Sito2\\TESTIMG.TIF" ); HANDLE handle = CreateFileA ( filePathAndName, GENERIC_READ, FILE_SHARE_READ, NULL, OPEN_EXISTING, FILE_ATTRIBUTE_NORMAL, NULL ); if ( handle == INVALID_HANDLE_VALUE ) { MessageBox ( NULL, filePathAndName, "TIFF file doesn't open, or doesn't exist:", MB_SYSTEMMODAL ); return; // file TIFF doesn't open } // check whether it is a true TIFF file (rc==1) int rc = pfnFFTiffServices ( 1, handle, NULL, NULL, NULL ); // get the width and the height of the image int width = pfnFFTiffServices ( 2, NULL, NULL, NULL, NULL ); int height = pfnFFTiffServices ( 3, NULL, NULL, NULL, NULL ); // get the comment, if any char* comment; (int) comment = pfnFFTiffServices ( 4, handle, NULL, NULL, NULL ); // then position file pointer to the beginning of the compressed data rc = pfnFFTiffServices ( 5, handle, NULL, NULL, NULL ); // allocate a buffer for the image according to its size int frameSize = width * height; HGLOBAL pFrame = GlobalAlloc ( GMEM_FIXED, frameSize ); // decompress the image and close the file rc = pfnFFDec ( handle, 1, pFrame, width/8, 0, height ); CloseHandle ( handle ); ////////////////////////////////////////////////////////////////////// // SECTION FOUR --- VIEW THE IMAGE ////////////////////////////////////////////////////////////////////// // call the image display routine Form1 -> WindowState = wsMinimized; pfnFFView ( Application -> Handle, pFrame, width/8, height, 0, 0 ); Form1 -> WindowState = wsNormal; ////////////////////////////////////////////////////////////////////// // SECTION FIVE --- FINAL OPERATIONS ////////////////////////////////////////////////////////////////////// // free the memory GlobalFree ( pFrame ); // free the DLL if ( FFLibDllHandle != 0 ) FreeLibrary ( FFLibDllHandle );