// BDE - (C) Copyright 1995 by Borland International // session.c #include "snipit.h" //===================================================================== // Function: // SessionIO(); // // Description: // This example will demonstrate how to start more than one // session. The example also shows how to switch between // sessions. //===================================================================== void SessionIO (void) { DBIResult rslt; // Value returned from IDAPI functions phDBISes phSession = NULL; // Handle to the session pSESInfo pSesInfo = NULL; // Session descriptor UINT16 i; // Loop variable const UINT uNumOfSessions = 4 ; // The number of sessions to open Screen("*** Session I/O Example ***\r\n"); BREAK_IN_DEBUGGER(); Screen(" Initializing IDAPI...\r\n"); rslt = DbiInit(NULL); if (ChkRslt(rslt, "Init") != DBIERR_NONE) { Screen("\r\n*** End of Example ***"); return; } // Turn on trace information if the debug layer is anabled (DLLSWAP.EXE). DbiDebugLayerOptions(DEBUGON | OUTPUTTOFILE, "SNIPIT.INF"); // Specify where temporary files are placed. rslt = DbiSetPrivateDir(szPrivDirectory); ChkRslt(rslt, "SetPrivateDir"); // Allocate memory for uNumOfSessions sessions. These // will be pointers to sessions once we start them. phSession = (phDBISes) malloc(uNumOfSessions * sizeof(hDBISes)); // Allocate memory for the session information pointers. pSesInfo = (pSESInfo) malloc(uNumOfSessions * sizeof(SESInfo)); if ((phSession == NULL) || (pSesInfo == NULL)) { if (phSession) free(phSession); if (pSesInfo) free(pSesInfo); Screen(" Error - Out of memory"); DbiDebugLayerOptions(0, NULL); rslt = DbiExit(); ChkRslt(rslt, "Exit"); Screen("\r\n*** End of Example ***"); return; } // Acquire the initial session handle. A session is started for you // when the engine is initialized. Screen(" Getting session #1 (opened automatically by DbiInit)..."); rslt = DbiGetCurrSession( &(phSession[0]) ); ChkRslt(rslt, "GetCurrSession"); // Start new sessions and display the number of open sessions on the // screen. Having already opened the first one, start the second // session through the uNumOfSessions - 1 session. for (i=0; i<(uNumOfSessions - 1); i++) { Screen("\r\n Opening session #%d...",i+2); rslt = DbiStartSession("", &(phSession[i+1]), NULL); ChkRslt(rslt, "StartSession"); } // Now iterate through each of the sessions and get the current // settings. The settings include the session number, the number of // open databases and the number of open cursors, among other things. for (i=0; i