home *** CD-ROM | disk | FTP | other *** search
/ QBasic & Borland Pascal & C / Delphi5.iso / C / BC_502 / OWLSRC.PAK / INITDLL.CPP < prev    next >
Encoding:
C/C++ Source or Header  |  1997-05-06  |  2.2 KB  |  85 lines

  1. //----------------------------------------------------------------------------
  2. // ObjectWindows
  3. // Copyright (c) 1991, 1997 by Borland International, All Rights Reserved
  4. //
  5. //$Revision:   10.3  $
  6. //
  7. // Default OwlMain to satisfy LibMain in DLLs that aren't components
  8. //----------------------------------------------------------------------------
  9. #include <owl/pch.h>
  10. #if !defined(OWL_DEFS_H)
  11. # include <owl/defs.h>
  12. #endif
  13. #if !defined(OWL_MODULE_H)
  14. # include <owl/module.h>
  15. #endif
  16. #if !defined(OWL_APPLICAT_H)
  17. # include <owl/applicat.h>
  18. #endif
  19.  
  20. OWL_DIAGINFO;
  21. DIAG_DECLARE_GROUP(OwlMain);
  22.  
  23. // Lock BIDS and OWL when building user DLL - 16-bit Windows may/does not
  24. // always unload DLLs in proper order.
  25. //      
  26. #if defined(_OWLDLL) && !defined(BI_PLAT_WIN32)
  27.                
  28. static char BidsDllName[] = BIDS_DLLNAME ".DLL";
  29. static char OwlDllName[] = OWL_DLLNAME ".DLL";
  30.  
  31. static HINSTANCE BidsInst = 0;
  32. static HINSTANCE OwlInst = 0;
  33.  
  34. //
  35. // Add extra ref. counts on BIDS and OWL DLLs since Windows may (does) unload
  36. // DLLs in 'wrong' order causing a crash at shut-down.
  37. //
  38. void lockDlls()
  39. {
  40.   BidsInst = ::LoadLibrary(BidsDllName);  
  41.   OwlInst = ::LoadLibrary(OwlDllName);
  42. }
  43. #pragma startup lockDlls 0
  44.  
  45. //
  46. // Remove extra ref. counts on BIDS and OWL DLLs
  47. //
  48. void unlockDlls()
  49. {
  50.   if (OwlInst > HINSTANCE(HINSTANCE_ERROR))
  51.     ::FreeLibrary(OwlInst);  
  52.   if (BidsInst > HINSTANCE(HINSTANCE_ERROR))
  53.     ::FreeLibrary(BidsInst);
  54. }
  55. #pragma exit unlockDlls 0
  56.  
  57. #endif
  58.  
  59. // Routine which initializes an OWL User DLL..
  60. // NOTE: Must be explicitly invoked if your DLL provides it's own
  61. //       LibMain, DllEntryPoint (or DllMain).
  62. //
  63. bool
  64. OWLInitUserDLL(HINSTANCE hInstance, LPSTR cmdLine)
  65. {
  66.   // If no global ::Module ptr exists yet, provide a default now
  67.   //
  68.   if (!::Module) {
  69.     static TModule module(0, hInstance);
  70.     ::Module = &module;
  71.   }
  72.  
  73.   // Store away information about this instance
  74.   //
  75.   TApplication::SetWinMainParams(hInstance, 0, cmdLine, SW_SHOWNORMAL);
  76.  
  77.   TRY {
  78.     int retVal = OwlMain(0, 0);
  79.     TRACEX(OwlMain, 0, "DllEntryPoint() returns " << retVal);
  80.     return retVal == 0;
  81.   }
  82.   CATCH( (xmsg& x) {return ::HandleGlobalException(x, 0) == 0;} )
  83. }
  84.  
  85.