home *** CD-ROM | disk | FTP | other *** search
/ PC World Komputer 1996 February / PCWK0296.iso / po7_win / object10 / oosd.cpp < prev    next >
Encoding:
C/C++ Source or Header  |  1994-12-21  |  2.8 KB  |  125 lines

  1. /* Copyright (c) Oracle Corporation 1994.  All Rights Reserved */
  2.  
  3. /*
  4.     This source code is provided as a debugging aid for developers
  5.     who have purchased Oracle Objects for OLE    .  Please see the
  6.     online help for documentation of these classes.
  7. */
  8.  
  9. /*
  10.     Oracle Objects for OLE     C++ Classes
  11.     
  12.     This file implements OStartup, OShutdown and several internal utility functions
  13.                            
  14.     CREATED    ********   11/22/94
  15.  
  16. */
  17.  
  18. #include "windows.h"
  19. #include <ole2.h>
  20. #include <olenls.h>       
  21. #include <dispatch.h>  
  22.  
  23. #ifndef ORACL_ORACLE
  24. #include "oracl.h"
  25. #endif
  26.  
  27. #ifndef ORAOBJI_ORACLE
  28. #include "oraobji.h"
  29. #endif
  30.  
  31. // ----- OStartup -----------------------------------------------
  32.  
  33. oboolean OStartup(void)
  34. {
  35.     oglobal *ogp = ssoo4wGetGlobal();  // probably allocates memory
  36.     
  37.     if (ogp->ogtried)
  38.         return(FALSE);  // have already tried to startup
  39.     
  40.     // initialize OLE
  41.     ogp->ogtried = TRUE;
  42.     HRESULT hr = OleInitialize(0);
  43.     SCODE sc = GetScode(hr);
  44.     if (sc == S_OK)
  45.     {
  46.         ogp->ogdid = 1;  // we initialized 
  47.         return(TRUE);
  48.     }
  49.     else if (sc == S_FALSE)   
  50.     {
  51.         ogp->ogdid = 2;  // we didn't, but its running
  52.         return(TRUE);
  53.     }
  54.     else
  55.     {
  56.         ogp->ogdid = 0;  // no ole (some error)    
  57.         return(FALSE);
  58.     }
  59. }
  60.  
  61. // ----- OShutdown -----------------------------------------------
  62.  
  63. void OShutdown(void)
  64. {
  65.     oglobal *ogp = ssoo4wGetGlobal();
  66.     
  67.     // shutdown ole, if needed
  68.     if (ogp->ogtried && ogp->ogdid == 1)
  69.     { // we initialized, we should uninitialize
  70.         OleUninitialize();
  71.     }
  72.     
  73.     // go ahead and free the global state
  74.     ssoo4wfree();
  75.     
  76.     return;
  77. }
  78.  
  79. // ----- Check for Initialization -----------------------------------------------
  80.  
  81. // check to make sure library is initialized 
  82. /*
  83.     We only need to check whether OLE is initialized from the creation
  84.     of an OSession.  Because if that doesn't result in an open OSession,
  85.     nothing else will get to the point of calling OLE.
  86. */
  87.  
  88. oboolean CheckOLE(void)
  89. {
  90.     oglobal *ogp = ssoo4wGetGlobal();
  91.     
  92.     if (ogp->ogtried && ogp->ogdid)
  93.         return(TRUE);
  94.     else
  95.         return(FALSE);
  96. }
  97.  
  98.  
  99. // ----- String Utilities -----------------------------------------------
  100.  
  101. // for the Windows version this needs to use OLE routines 
  102.  
  103. char *OObjectAllocString(const char *instr)
  104. {
  105.     return((char *) SysAllocString(instr));
  106. }
  107.  
  108. void OObjectFreeString(char *instr)
  109. {
  110.     SysFreeString((BSTR) instr);
  111. }
  112.  
  113. char *OObjectAllocStringLen(char *instr, unsigned int slen)
  114. {
  115.     // allocate string by length (takes care of embedded nulls) 
  116.     
  117.     return((char *) SysAllocStringLen(instr, slen));
  118. }
  119.  
  120. unsigned int OObjectStringLen(char *instr)
  121. {
  122.     return(SysStringLen((BSTR) instr));
  123. }
  124.  
  125.