home *** CD-ROM | disk | FTP | other *** search
/ C Programming Starter Kit 2.0 / SamsPublishing-CProgrammingStarterKit-v2.0-Win31.iso / bc45 / owlsrc.pak / LIBMAIN.CPP < prev    next >
Encoding:
C/C++ Source or Header  |  1997-07-24  |  2.5 KB  |  94 lines

  1. //----------------------------------------------------------------------------
  2. // ObjectWindows
  3. // (C) Copyright 1991, 1994 by Borland International, All Rights Reserved
  4. //
  5. //   Default implementation of LibMain() for user DLLs
  6. //----------------------------------------------------------------------------
  7. #include <owl/owlpch.h>
  8. #include <owl/applicat.h>
  9.  
  10. DIAG_DEFINE_GROUP_INIT(OWL_INI, OwlMain, true, 0);
  11.  
  12. #if defined(BI_PLAT_WIN32)
  13.  
  14. int WINAPI
  15. DllEntryPoint(HINSTANCE hInstance, uint32 reason, LPVOID)
  16. {
  17.   TRACEX(OwlMain, 0, "DllEntryPoint(" << hInstance << ", " << reason << ", " <<
  18.          ") called");
  19.   
  20.   switch (reason) {
  21.     case DLL_PROCESS_ATTACH:
  22.       // If no global ::Module ptr exists yet, provide a default now
  23.       //
  24.       if (!::Module) {
  25.         static TModule module(0, hInstance);
  26.         ::Module = &module;
  27.       }
  28.       TApplication::SetWinMainParams(hInstance, 0, 0, SW_SHOWNORMAL);
  29.  
  30.       TRY {
  31.         int retVal = OwlMain(0, 0);
  32.         TRACEX(OwlMain, 0, "DllEntryPoint() returns " << retVal);
  33.         return retVal == 0;
  34.       }
  35.       CATCH( (xmsg& x) {return ::HandleGlobalException(x, 0) == 0;} )
  36.   }
  37.   return true;
  38. }
  39.  
  40. #else   // !defined(BI_PLAT_WIN32)
  41.  
  42. //
  43. // Make sure that the DLLs we use stay in memory while we perform static
  44. // destructor cleanup
  45. //
  46. #if defined(_OWLDLL)
  47.  
  48. static HINSTANCE BidsInst;
  49. static HINSTANCE OwlInst;
  50. void lockDlls()
  51. {
  52.   BidsInst = ::LoadLibrary("BIDS45.DLL");  // load lowlevel to hilevel order
  53.   OwlInst = ::LoadLibrary("OWL252.DLL");
  54. }
  55. #pragma startup lockDlls 0
  56.  
  57. void unlockDlls()
  58. {
  59.   ::FreeLibrary(OwlInst);  // unload hilevel to lowlevel order (reversed)
  60.   ::FreeLibrary(BidsInst);
  61. }
  62. #pragma exit unlockDlls 0
  63.  
  64. #endif
  65.  
  66. int
  67. FAR PASCAL
  68. LibMain(HINSTANCE   hInstance,
  69.         uint16    /*wDataSeg*/,
  70.         uint16    /*cbHeapSize*/,
  71.         char far*   cmdLine)
  72. {
  73.   TRACEX(OwlMain, 0, "LibMain(" << hex << uint(hInstance) << ", " << 
  74.                                   TResId(cmdLine)  << ") called");
  75.  
  76.   // If no global ::Module ptr exists yet, provide a default now
  77.   //
  78.   if (!::Module) {
  79.     static TModule module(0, hInstance);
  80.     ::Module = &module;
  81.   }
  82.  
  83.   TApplication::SetWinMainParams(hInstance, 0, cmdLine, SW_SHOWNORMAL);
  84.  
  85.   TRY {
  86.     int retVal = OwlMain(0, 0);
  87.     TRACEX(OwlMain, 0, "LibMain() returns " << retVal);
  88.     return retVal == 0;
  89.   }
  90.   CATCH( (xmsg& x) {return ::HandleGlobalException(x, 0) == 0;} )
  91. }
  92.  
  93. #endif  // defined(BI_PLAT_WIN32)
  94.