////////////////////////////////////////////////////////////////////// // PUT THE FOLLOWING DECLARATIONS IN THE HEADER FILE ////////////////////////////////////////////////////////////////////// int ( __stdcall *pfnFFTiffServices )( int, HANDLE, void*, int, int ); void* ( __stdcall *pfnFFTiffMServices )( int, int, int, int, int ); int ( __stdcall *pfnFFDec )( HANDLE, int, void*, int, 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 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 FFTiffMServices pfnFFTiffMServices = ( void* ( __stdcall *)( int, int, int, int, int ) ) GetProcAddress ( FFLibDllHandle, "FFTiffMServices" ); if ( pfnFFTiffMServices == NULL ) { MessageBox ( NULL, "GetProcAddress:\nFFTiffMServices not found.", "Error FS 003", MB_SYSTEMMODAL ); break; } // 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 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 --- CREATE THE ATTACH (Borland C++ Builder 3 code ready) ////////////////////////////////////////////////////////////////////// // set the hourglass (just in case...) Screen -> Cursor = crHourGlass; Application -> ProcessMessages ( ); // prepare the comment to the attachment file char* comment = "...some comment..."; // this is the name of the attachment (multi page TIFF file) char mTiffPathAndName [ 1024 ]; strcpy ( mTiffPathAndName, "C:\\ATTACHMENT.TIF" ); // start creating the attachment HANDLE hTiff; hTiff = pfnFFTiffMServices ( 1, (int)mTiffPathAndName, NULL, NULL, NULL ); // some initialization required ProgressBar1 -> Position = 0; ProgressBar1 -> Max = TotalPages; char pageName [ 1024 ]; HANDLE handle; int mark, width, height; HGLOBAL pFrame; // add one image at a time for ( int page = 1; page <= TotalPages; page++ ) { // prepare the file name of each page to add to the attachment file strcpy ( pageName, ...the name of each page... ); strcat ( pageName, ".TIF" ); // open the file handle = CreateFileA ( string, GENERIC_READ, FILE_SHARE_READ, NULL, OPEN_EXISTING, FILE_ATTRIBUTE_NORMAL, NULL ); if ( handle == INVALID_HANDLE_VALUE ) { MessageBox ( NULL, pageName, "File doesn't open:", MB_SYSTEMMODAL ); break; } // check it is TIFF rc = pfnFFTiffServices ( 1, handle, NULL, NULL, NULL ); // get width width = pfnFFTiffServices ( 2, NULL, NULL, NULL, NULL ); // get height height = pfnFFTiffServices ( 3, NULL, NULL, NULL, NULL ); // position to the beginning of the compressed data rc = pfnFFTiffServices ( 5, handle, NULL, NULL, NULL ); // allocate an image buffer (width or height might have changed, // hence it is necessary to reallocate the memory each time) pFrame = GlobalAlloc ( GMEM_FIXED, width * height ); // decompress the data rc = pfnFFDec ( handle, 1, pFrame, width/8, 0, height ); // now the image is in memory, close the file CloseHandle ( handle ); // start writing a page into the attachment and record the // position of the file pointer (void*)mark = pfnFFTiffMServices ( 2, NULL, NULL, NULL, NULL ); // compress the contents of the memory buffer pfnFFComp ( pFrame, 0, hTiff, width/8, height ); // stop writing the page into the attachment pfnFFTiffMServices ( 3, (int)comment, width/8, height, mark ); // update the progress bar ProgressBar1 -> Position += 1; // free the image buffer if ( pFrame != 0 ) { GlobalFree ( pFrame ); } } // close the output attachment file (void*)ATTACH_LEN = pfnFFTiffMServices ( 4, NULL, NULL, NULL, NULL ); // restore the screen cursor Screen -> Cursor = crDefault; ////////////////////////////////////////////////////////////////////// // SECTION THREE --- FINAL OPERATIONS ////////////////////////////////////////////////////////////////////// // free the DLL if ( FFLibDllHandle != 0 ) FreeLibrary ( FFLibDllHandle );