// prototypes int ( __stdcall *pfnFFNtxOpen )( char* ); int ( __stdcall *pfnFFNtxGetCount)( char* ); int ( __stdcall *pfnFFNtxGetFirst)( void ); int ( __stdcall *pfnFFNtxGetNext)( void ); void ( __stdcall *pfnFFNtxClose )( void ); int ( __stdcall *pfnFFDbfOpen )( char* ); char* ( __stdcall *pfnFFDbfGetRecord)( int ); void ( __stdcall *pfnFFDbfClose )( void ); // load FFLIB.DLL HINSTANCE FFLibDllHandle = 0; FFLibDllHandle = LoadLibrary ( "FFLIB.DLL" ); if ( FFLibDllHandle == 0 ) { MessageBox ( NULL, "LoadLibrary:\nFFLIB.DLL not found.", "Error FS 001", MB_SYSTEMMODAL ); return; } // load the address of FFNtxOpen pfnFFNtxOpen = ( int ( __stdcall *)( char* ) ) GetProcAddress ( FFLibDllHandle, "FFNtxOpen" ); if ( pfnFFNtxOpen == NULL ) { MessageBox ( NULL, "GetProcAddress:\nFFNtxOpen not found.", "Error FS 003", MB_SYSTEMMODAL ); return; } // load the address of FFNtxGetCount pfnFFNtxGetCount = ( int ( __stdcall *)( char* ) ) GetProcAddress ( FFLibDllHandle, "FFNtxGetCount" ); if ( pfnFFNtxGetCount == NULL ) { MessageBox ( NULL, "GetProcAddress:\nFFNtxGetCount not found.", "Error FS 003", MB_SYSTEMMODAL ); return; } // load the address of FFNtxGetFirst pfnFFNtxGetFirst = ( int ( __stdcall *)( void ) ) GetProcAddress ( FFLibDllHandle, "FFNtxGetFirst" ); if ( pfnFFNtxGetFirst == NULL ) { MessageBox ( NULL, "GetProcAddress:\nFFNtxGetFirst not found.", "Error FS 003", MB_SYSTEMMODAL ); return; } // load the address of FFNtxGetNext pfnFFNtxGetNext = ( int ( __stdcall *)( void ) ) GetProcAddress ( FFLibDllHandle, "FFNtxGetNext" ); if ( pfnFFNtxGetNext == NULL ) { MessageBox ( NULL, "GetProcAddress:\nFFNtxGetNext not found.", "Error FS 003", MB_SYSTEMMODAL ); return; } // load the address of FFNtxClose pfnFFNtxClose = ( void ( __stdcall *)( void ) ) GetProcAddress ( FFLibDllHandle, "FFNtxClose" ); if ( pfnFFNtxClose == NULL ) { MessageBox ( NULL, "GetProcAddress:\nFFNtxClose not found.", "Error FS 003", MB_SYSTEMMODAL ); return; } // load the address of FFDbfOpen pfnFFDbfOpen = ( int ( __stdcall *)( char* ) ) GetProcAddress ( FFLibDllHandle, "FFDbfOpen" ); if ( pfnFFDbfOpen == NULL ) { MessageBox ( NULL, "GetProcAddress:\nFFDbfOpen not found.", "Error FS 003", MB_SYSTEMMODAL ); return; } // load the address of FFDbfGetRecord pfnFFDbfGetRecord = ( char* ( __stdcall *)( int ) ) GetProcAddress ( FFLibDllHandle, "FFDbfGetRecord" ); if ( pfnFFDbfGetRecord == NULL ) { MessageBox ( NULL, "GetProcAddress:\nFFDbfGetRecord not found.", "Error FS 003", MB_SYSTEMMODAL ); return; } // load the address of FFDbfClose pfnFFDbfClose = ( void ( __stdcall *)( void ) ) GetProcAddress ( FFLibDllHandle, "FFDbfClose" ); if ( pfnFFDbfClose == NULL ) { MessageBox ( NULL, "GetProcAddress:\nFFDbfClose not found.", "Error FS 003", MB_SYSTEMMODAL ); return; } // open the index file (and get the key length) int keyLength = pfnFFNtxOpen ( "C:\\LAVORI\\SITO2\\DBFNTX\\GROUPS.NTX" ); // search the key "Rolling Stones " and get the number of matching records int numberOfMatchingRecords = pfnFFNtxGetCount ( "Rolling Stones " ); if ( numberOfMatchingRecords == 0 ) { return; } // NOTE: if the key length is not exactly equal to keyLength (the return value of // pfnFFNtxOpen) it should be right padded with blanks to reach the exact keyLength; // in the case of the "Rolling Stones" above the key length is 20, and for this // reason the key to search is "Rolling Stones " // allocate an array of integers int* keyRecNos = new int [ numberOfMatchingRecords ]; // get the record number of the first record with the key field matching the key keyRecNos [ 0 ] = pfnFFNtxGetFirst ( ); // get the record number of the remaining records with the key field matching the key for ( int x = 1; x < numberOfMatchingRecords; x++ ) { keyRecNos [ x ] = pfnFFNtxGetNext ( ); } // close the index file pfnFFNtxClose ( ); // open the DBF int RecCount = pfnFFDbfOpen ( "C:\\LAVORI\\SITO2\\DBFNTX\\FOO.DBF" ); // note: if RecCount == 0 the file is busy ! // declare a record number and a record int recno; char* myrec; // declare the fields char type [ 3 ]; char date [ 9 ]; char disk [ 9 ]; char track [ 6 ]; // fetch all the records with the key field matching the key for ( int x = 0; x < numberOfMatchingRecords; x++ ) { // set the record number... recno = keyRecNos [ x ]; // ...and retrieve the corresponding record myrec = pfnFFDbfGetRecord ( recno ); // check whether the record is deleted if ( myrec [ 0 ] == 42 ) { continue; } // get the 1st field (type) int i = 0; for ( int j = 1; j < 3; j++ ) { type [ i ] = myrec [ j ]; i++; } type [ i ] = 0; // get the 2nd field (date) i = 0; for ( int j = 3; j < 11; j++ ) { date [ i ] = myrec [ j ]; i++; } date [ i ] = 0; // get the 3rd field (disk) i = 0; for ( int j = 11; j < 19; j++ ) { disk [ i ] = myrec [ j ]; i++; } disk [ i ] = 0; // get the 4th field (track) i = 0; for ( int j = 19; j < 24; j++ ) { track [ i ] = myrec [ j ]; i++; } track [ i ] = 0; } // close the DBF pfnFFDbfClose ( ); // unload the library FreeLibrary ( FFLibDllHandle );