// BDE - (C) Copyright 1995 by Borland International // Callback.C #include "snipit.h" static const DBIPATH szTblName = "CUST2"; static const char szTblType[] = szDBASE; pCHAR CallBackData2; CBRType DBIFN _export CallBackFunc2(CBType ecbType, UINT32 iClientData, pVOID pCbInfo); //===================================================================== // Function: // InputReqCallback(); // // Description: // This example shows how to access a dBASE table which is missing // it's .MDX file. This is accomplished with the use of the // cbINPUTREQ callback. Note that this method can also be used // to access FOX and CLIPPER tables. //===================================================================== void InputReqCallback(void) { hDBIDb hDb; // Handle to the database hDBICur hCur; // Handle to the table UINT16 uNumOfRecs = 5; // No. of records to display CBInputDesc CbInfo; // Variable which is used within // the callback DBIResult rslt; // Return value from IDAPI // functions Screen("*** Open Table CallBack Example ***\r\n"); BREAK_IN_DEBUGGER(); Screen(" Initializing IDAPI..."); if (InitAndConnect(&hDb) != DBIERR_NONE) { Screen("*** End of Example ***"); return; } Screen(" Setting the database directory..."); rslt = DbiSetDirectory(hDb, (pCHAR) szTblDirectory); ChkRslt(rslt, "SetDirectory"); Screen(" ERROR expected opening the %s table: \r\n" " 'Index does not exist'...", szTblName); rslt = DbiOpenTable(hDb, (pCHAR) szTblName, (pCHAR) szTblType, NULL, NULL, 0, dbiREADONLY, dbiOPENSHARED, xltFIELD, FALSE, NULL, &hCur); ChkRslt(rslt, "OpenTable"); if (hCur) { Screen(" Display the %s table...", szTblName); DisplayTable(hCur, uNumOfRecs); Screen("\r\n Close the %s table...", szTblName); DbiCloseCursor(&hCur); } // Allocate enough space for the data passed to the callback function. CallBackData2 = (pCHAR)malloc(100 * sizeof(CHAR)); if (CallBackData2 == NULL) { CloseDbAndExit(&hDb); Screen("\r\n*** End of Example ***"); return; } // Register the callback. rslt = DbiRegisterCallBack(NULL, cbINPUTREQ, (UINT32) CallBackData2, sizeof(CBInputDesc), &CbInfo, CallBackFunc2); if(ChkRslt(rslt, "RegisterCallback") != DBIERR_NONE) { free(CallBackData2); CloseDbAndExit(&hDb); Screen("\r\n*** End of Example ***"); return; } Screen("\r\n Open the %s table...", szTblName); rslt = DbiOpenTable(hDb, (pCHAR) szTblName, (pCHAR) szTblType, NULL, NULL, 0, dbiREADONLY, dbiOPENSHARED, xltFIELD, FALSE, NULL, &hCur); ChkRslt(rslt, "OpenTable"); if (hCur) { Screen(" Display the Table..."); DisplayTable(hCur, uNumOfRecs); Screen("\r\n Close the %s table...", szTblName); rslt = DbiCloseCursor(&hCur); ChkRslt(rslt, "CloseCursor"); } // Unregister the callback by passing in NULL for the function. rslt = DbiRegisterCallBack(NULL, cbINPUTREQ, NULL, 0, NULL, NULL); if (ChkRslt(rslt, "RegisterCallBack") != DBIERR_NONE) { free(CallBackData2); CloseDbAndExit(&hDb); Screen("\r\n*** End of Example ***"); return; } free(CallBackData2); Screen("\r\n Close the database and exit IDAPI..."); CloseDbAndExit(&hDb); Screen("\r\n*** End of Example ***"); } //====================================================================== // Name: CallBackFunc2(ecbType, iClientData, pCbInfo) // // Input: ecbType - Callback type // iClientData - Pointer to client information that is passed into // the callback function // pCbInfo - The callback structure that holds the information // about the current state // // Return: The action that should be taken // // Description: // This function will be called from the BDE during the process // of opening the table. //====================================================================== CBRType DBIFN CallBackFunc2 (CBType ecbType, UINT32 iClientData, pVOID pCbInfo) { CBInputDesc *eCBInputDesc; // Variable to contain passed-in // information int i; // Set to stop an unused variable warning. iClientData = iClientData; switch (ecbType) { // In case this is a restructure progress callback, display the // information. case cbINPUTREQ: eCBInputDesc = (CBInputDesc far *)pCbInfo; Screen("\r\n ### In the Callback function...\r\n"); Screen(" ### %s", eCBInputDesc->szMsg); Screen("\r\n Options are:"); for (i = 0; i < eCBInputDesc->iCount; i++) { Screen(" ### %s: %s", eCBInputDesc->acbEntry[i].szKeyWord, eCBInputDesc->acbEntry[i].szHelp); } Screen(" ### Default: %s", eCBInputDesc->acbEntry[eCBInputDesc->iSelection].szKeyWord); if (eCBInputDesc->eCbInputId == cbiMDXMISSING) { i = 0; while (i < eCBInputDesc->iCount) { if (!strcmp(eCBInputDesc->acbEntry[i].szKeyWord, "Open Read Only")) { Screen("\r\n ### Open the table read only...\r\n"); eCBInputDesc->iSelection = i + 1; eCBInputDesc->bSave = FALSE; break; } } } break; default: Screen("### In the callback function"); } return cbrCHKINPUT; }