////////////////////////////////////////////////////////////////////// // 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 ); void ( __stdcall *pfnFFAsciiWrite)( void*, int, int, void*, int, int, int ); int ( __stdcall *pfnFFView )( HWND, void*, int, int, void*, void* ); 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 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 FFAsciiWrite pfnFFAsciiWrite = ( void ( __stdcall *)( void*, int, int, void*, int, int, int ) ) GetProcAddress ( FFLibDllHandle, "FFAsciiWrite" ); if ( pfnFFAsciiWrite == NULL ) { MessageBox ( NULL, "GetProcAddress:\nFFAsciiWrite not found.", "Error 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 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 --- OPEN AND DECOMPRESS A TIFF FILE ////////////////////////////////////////////////////////////////////// // set the name of the image to be decompressed and viewed char filePathAndName [ 256 ]; strcpy ( filePathAndName, "C:\\A.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 + 1 ); // allocate a bit more than the strict necessary 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 --- WRITE SOMETHING AND VIEW THE IMAGE ////////////////////////////////////////////////////////////////////// // prepare the string to write and print it on the image char myComments [ 1024 ]; strcpy ( myComments, "0123456789-ABCDEFGHIJKLMNOPQRSTUVWXYXZ" ); pfnFFAsciiWrite ( pFrame, width, height, myComments, 0, 800, 600 ); // call the image display routine Form1 -> WindowState = wsMinimized; pfnFFView ( Application -> Handle, pFrame, width/8, height, 0, 0 ); Form1 -> WindowState = wsNormal; ////////////////////////////////////////////////////////////////////// // SECTION FIVE --- PACK AGAIN THE TIFF FILE WITH THE MODIFIED IMAGE ////////////////////////////////////////////////////////////////////// // 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:\\A.TIF" ); // create and start writing the TIFF file handle; // then cast "handle" to an int (int) handle = pfnFFTiffServices ( 6, szTiffFile, "any comment", width, height ); 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 ( pFrame, 0, handle, width/8, height ); // finish writing the TIFF file and close it pfnFFTiffServices ( 7, handle, NULL, NULL, NULL ); ////////////////////////////////////////////////////////////////////// // SECTION SIX --- FINAL OPERATIONS ////////////////////////////////////////////////////////////////////// // free the memory GlobalFree ( pFrame ); // free the DLL if ( FFLibDllHandle != 0 ) FreeLibrary ( FFLibDllHandle );