home *** CD-ROM | disk | FTP | other *** search
/ C Programming Starter Kit 2.0 / SamsPublishing-CProgrammingStarterKit-v2.0-Win31.iso / bde / snipit.pak / INITENG.C < prev    next >
Encoding:
C/C++ Source or Header  |  1997-07-24  |  3.3 KB  |  89 lines

  1. // BDE - (C) Copyright 1995 by Borland International
  2.  
  3. // initeng.c
  4. #include "snipit.h"
  5.  
  6. //========================================================================
  7. //  Function:
  8. //          InitEngSample();
  9. //
  10. //  Description:
  11. //          This code snipit will initialize IDAPI with a NULL
  12. //          environment structure, connect to a standard database (used by
  13. //          Paradox and dBASE tables), then clean up before returning.
  14. //          Initializing IDAPI with a NULL environment structure will
  15. //          force IDAPI to scan for the needed configuration file. The
  16. //          search will follow this search hierarchy:
  17. //          1. Use the configuration file specified in the DBIEnv structure
  18. //             (not supplied by this example.)
  19. //          2. Check for a defined configuration file in the WIN.INI file
  20. //             located in your Windows directory. The entry checked for
  21. //             is "[IDAPI]" with a sub-entry of "CONFIGFILE01."
  22. //          3. Check for the configuration file in the startup directory.
  23. //          4. When all else fails, IDAPI will initialize with a
  24. //             predefined set of configuration settings. The default
  25. //             settings include no locking of Paradox or dBASE tables,
  26. //             no network access to tables, and no SQL databases.
  27. //========================================================================
  28. void
  29. InitEngSample (void)
  30. {
  31.     hDBIDb      hDb;    // Handle to the database
  32.     DBIResult   rslt;   // Return value from IDAPI functions
  33.  
  34.     Screen("*** Initializing IDAPI ***\r\n");
  35.  
  36.     BREAK_IN_DEBUGGER();
  37.  
  38.     Screen("    Initializing IDAPI...");
  39.  
  40.     rslt = DbiInit(NULL);
  41.     if (ChkRslt(rslt, "Init") == DBIERR_NONE)
  42.     {
  43.         Screen("    Enable the output of trace information to SNIPIT.INF"
  44.                " if the debug\r\n      layer DLL is selected..."); 
  45.         DbiDebugLayerOptions(DEBUGON | OUTPUTTOFILE, "SNIPIT.INF");
  46.         
  47.         Screen("    Set the private directory (where temporary tables are"
  48.                " placed)..."); 
  49.         rslt = DbiSetPrivateDir(szPrivDirectory);
  50.         ChkRslt(rslt, "SetPrivateDir");
  51.  
  52.         // IDAPI initialized. Now open a Standard database (used to
  53.         //   access Paradox, dBASE, and Text tables), by using a NULL
  54.         //   database type.
  55.         Screen("    Opening a Standard database...");
  56.  
  57.         rslt = DbiOpenDatabase(NULL, NULL, dbiREADWRITE, dbiOPENSHARED,
  58.                                NULL, 0, NULL, NULL, &hDb);
  59.         if (ChkRslt(rslt, "OpenDatabase") != DBIERR_NONE)
  60.         {
  61.             DbiDebugLayerOptions(0, NULL);
  62.  
  63.             rslt = DbiExit();
  64.             ChkRslt(rslt, "Exit");
  65.         }
  66.  
  67.         Screen("    Set the working directory...");
  68.         rslt = DbiSetDirectory(hDb, (pCHAR)szTblDirectory);
  69.         ChkRslt(rslt, "SetDirectory");
  70.  
  71.         Screen("    Closing the database...");
  72.         rslt = DbiCloseDatabase(&hDb);
  73.         ChkRslt(rslt, "DbClose");
  74.  
  75.         // Shut down the debug layer.
  76.         DbiDebugLayerOptions(0, NULL);
  77.  
  78.         Screen("    Exiting IDAPI...");
  79.         rslt = DbiExit();
  80.         ChkRslt(rslt, "Exit");
  81.     }
  82.     else
  83.     {
  84.         Screen("        Error - Could not initialize IDAPI");
  85.     }
  86.  
  87.     Screen("\r\n*** End of Example ***");
  88. }
  89.