home *** CD-ROM | disk | FTP | other *** search
- // BDE - (C) Copyright 1995 by Borland International
-
- // Callback.C
- #include "snipit.h"
-
- static const DBIPATH szTblName = "security";
- static const char szTblType[] = szDBASE;
- pCHAR CallBackData3;
-
- CBRType DBIFN _export CallBackFunc3(CBType ecbType, UINT32 iClientData,
- pVOID pCbInfo);
-
- //=====================================================================
- // Function:
- // LoginCallback();
- //
- // 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
- LoginCallback (void)
- {
- hDBIDb hDb; // Handle to the database
- hDBICur hCur; // Handle to the table
- UINT16 uNumOfRecs = 5; // No. of records to display
- CBLoginDesc 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(" Attempt to open the %s table: \r\n"
- " Error Expected: 'Encrypted dBASE tables not supported'...",
- 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);
- }
-
- Screen("\r\n Register the Login Callback...");
-
- // Allocate enough space for the data passed to the callback function.
- CallBackData3 = (pCHAR)malloc(100 * sizeof(CHAR));
- if (CallBackData3 == NULL)
- {
- CloseDbAndExit(&hDb);
- Screen("\r\n*** End of Example ***");
- return;
- }
-
- // Register the callback.
- rslt = DbiRegisterCallBack(NULL, cbDBASELOGIN, (UINT32) CallBackData3,
- sizeof(CBLoginDesc), &CbInfo, CallBackFunc3);
- if(ChkRslt(rslt, "RegisterCallback") != DBIERR_NONE)
- {
- free(CallBackData3);
- 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(CallBackData3);
- CloseDbAndExit(&hDb);
- Screen("\r\n*** End of Example ***");
- return;
- }
-
- free(CallBackData3);
-
- Screen("\r\n Close the database and exit IDAPI...");
- CloseDbAndExit(&hDb);
-
- Screen("\r\n*** End of Example ***");
- }
-
- //======================================================================
- // Name: CallBackFunc3(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
- CallBackFunc3 (CBType ecbType, UINT32 iClientData, pVOID pCbInfo)
- {
- CBLoginDesc *eCBInputDesc; // Variable to contain passed-in
- // information
-
- // Set to stop an unused variable warning.
- iClientData = iClientData;
-
- switch (ecbType)
- {
- // In case this is a restructure progress callback, display the
- // information.
- case cbDBASELOGIN:
-
- eCBInputDesc = (CBLoginDesc far *)pCbInfo;
-
- strcpy(eCBInputDesc->szUserName, "TEST");
- strcpy(eCBInputDesc->szGroupName, "TEST");
- strcpy(eCBInputDesc->szUserPassword, "TEST");
- break;
-
- default:
- Screen("### In the callback function");
- }
-
- return cbrCHKINPUT;
- }
-