home *** CD-ROM | disk | FTP | other *** search
- // BDE - (C) Copyright 1995 by Borland International
-
- // initeng.c
- #include "snipit.h"
-
- //========================================================================
- // Function:
- // InitEngSample();
- //
- // Description:
- // This code snipit will initialize IDAPI with a NULL
- // environment structure, connect to a standard database (used by
- // Paradox and dBASE tables), then clean up before returning.
- // Initializing IDAPI with a NULL environment structure will
- // force IDAPI to scan for the needed configuration file. The
- // search will follow this search hierarchy:
- // 1. Use the configuration file specified in the DBIEnv structure
- // (not supplied by this example.)
- // 2. Check for a defined configuration file in the WIN.INI file
- // located in your Windows directory. The entry checked for
- // is "[IDAPI]" with a sub-entry of "CONFIGFILE01."
- // 3. Check for the configuration file in the startup directory.
- // 4. When all else fails, IDAPI will initialize with a
- // predefined set of configuration settings. The default
- // settings include no locking of Paradox or dBASE tables,
- // no network access to tables, and no SQL databases.
- //========================================================================
- void
- InitEngSample (void)
- {
- hDBIDb hDb; // Handle to the database
- DBIResult rslt; // Return value from IDAPI functions
-
- Screen("*** Initializing IDAPI ***\r\n");
-
- BREAK_IN_DEBUGGER();
-
- Screen(" Initializing IDAPI...");
-
- rslt = DbiInit(NULL);
- if (ChkRslt(rslt, "Init") == DBIERR_NONE)
- {
- Screen(" Enable the output of trace information to SNIPIT.INF"
- " if the debug\r\n layer DLL is selected...");
- DbiDebugLayerOptions(DEBUGON | OUTPUTTOFILE, "SNIPIT.INF");
-
- Screen(" Set the private directory (where temporary tables are"
- " placed)...");
- rslt = DbiSetPrivateDir(szPrivDirectory);
- ChkRslt(rslt, "SetPrivateDir");
-
- // IDAPI initialized. Now open a Standard database (used to
- // access Paradox, dBASE, and Text tables), by using a NULL
- // database type.
- Screen(" Opening a Standard database...");
-
- rslt = DbiOpenDatabase(NULL, NULL, dbiREADWRITE, dbiOPENSHARED,
- NULL, 0, NULL, NULL, &hDb);
- if (ChkRslt(rslt, "OpenDatabase") != DBIERR_NONE)
- {
- DbiDebugLayerOptions(0, NULL);
-
- rslt = DbiExit();
- ChkRslt(rslt, "Exit");
- }
-
- Screen(" Set the working directory...");
- rslt = DbiSetDirectory(hDb, (pCHAR)szTblDirectory);
- ChkRslt(rslt, "SetDirectory");
-
- Screen(" Closing the database...");
- rslt = DbiCloseDatabase(&hDb);
- ChkRslt(rslt, "DbClose");
-
- // Shut down the debug layer.
- DbiDebugLayerOptions(0, NULL);
-
- Screen(" Exiting IDAPI...");
- rslt = DbiExit();
- ChkRslt(rslt, "Exit");
- }
- else
- {
- Screen(" Error - Could not initialize IDAPI");
- }
-
- Screen("\r\n*** End of Example ***");
- }
-