home *** CD-ROM | disk | FTP | other *** search
/ Tricks of the Windows Gam…ming Gurus (2nd Edition) / Disc2.iso / vc98 / atl / src / atl.cpp next >
Encoding:
C/C++ Source or Header  |  1998-06-16  |  3.4 KB  |  121 lines

  1. // atl.cpp : Implementation of DLL Exports.
  2.  
  3. // You will need the NT SUR Beta 2 SDK or VC 4.2 or higher in order to build
  4. // this project.  This is because you will need MIDL 3.00.15 or higher and new
  5. // headers and libs.  If you have VC 4.2 installed, then everything should
  6. // already be configured correctly.
  7.  
  8. // Note: Proxy/Stub Information
  9. //      To build a separate proxy/stub DLL,
  10. //      run nmake -f atlps.mak in the project directory.
  11.  
  12. #include "stdafx.h"
  13. #include "resource.h"
  14. #include "RegObj.h"
  15.  
  16. #define _ATLBASE_IMPL
  17. #include <atlbase.h>
  18. #define _ATLCOM_IMPL
  19. #include <atlcom.h>
  20. #define _ATLWIN_IMPL
  21. #include <atlwin.h>
  22. #define _ATLCTL_IMPL
  23. #include <atlctl.h>
  24. #define _ATLCONV_IMPL
  25. #include <atlconv.h>
  26. #define _ATLHOST_IMPL
  27. #include <atlhost.h>
  28.  
  29. CComModule _Module;
  30.  
  31. BEGIN_OBJECT_MAP(ObjectMap)
  32.     OBJECT_ENTRY(CLSID_Registrar, CDLLRegObject)
  33.     OBJECT_ENTRY_NON_CREATEABLE(CAxHostWindow)
  34. END_OBJECT_MAP()
  35.  
  36. /////////////////////////////////////////////////////////////////////////////
  37. // DLL Entry Point
  38.  
  39. extern "C"
  40. BOOL WINAPI DllMain(HINSTANCE hInstance, DWORD dwReason, LPVOID /*lpReserved*/)
  41. {
  42.     if (dwReason == DLL_PROCESS_ATTACH)
  43.     {
  44.         OSVERSIONINFOA info;
  45.         info.dwOSVersionInfoSize = sizeof(info);
  46.         if (GetVersionExA(&info))
  47.         {
  48. #ifdef _UNICODE
  49.             if (info.dwPlatformId != VER_PLATFORM_WIN32_NT)
  50.             {
  51.                 MessageBoxA(NULL, "Can not run Unicode version of ATL.DLL on Windows 95.\nPlease install the correct version.", "ATL", MB_ICONSTOP|MB_OK);
  52.                 return FALSE;
  53.             }
  54. #else
  55.             if (info.dwPlatformId == VER_PLATFORM_WIN32_NT)
  56.             {
  57.                 OutputDebugString(_T("Running Ansi version of ATL.DLL on Windows NT : Slight Performace loss.\nPlease install the UNICODE version on NT.\n"));
  58.             }
  59. #endif
  60.         }
  61. #ifdef _DEBUG
  62.         _CrtSetDbgFlag(_CRTDBG_ALLOC_MEM_DF);
  63.         int n = 0;
  64.         _CrtSetBreakAlloc(n);
  65. #endif
  66.         _Module.Init(ObjectMap, hInstance, &LIBID_ATLLib);
  67. #ifdef _ATL_DEBUG_INTERFACES
  68.         int ni = 0;
  69.         _Module.m_nIndexBreakAt = ni;
  70. #endif // _ATL_DEBUG_INTERFACES
  71.         DisableThreadLibraryCalls(hInstance);
  72.     }
  73.     else if (dwReason == DLL_PROCESS_DETACH)
  74.     {
  75. #ifdef _DEBUG
  76.         ::OutputDebugString(_T("ATL.DLL exiting.\n"));
  77. #endif
  78.         _Module.Term();
  79.         AtlAxWinTerm();
  80. #ifdef _DEBUG
  81.         if (_CrtDumpMemoryLeaks())
  82.             ::MessageBeep(MB_ICONEXCLAMATION);
  83. #endif
  84.     }
  85.     return TRUE;    // ok
  86. }
  87.  
  88. /////////////////////////////////////////////////////////////////////////////
  89. // Used to determine whether the DLL can be unloaded by OLE
  90.  
  91. STDAPI DllCanUnloadNow(void)
  92. {
  93.     return (_Module.GetLockCount()==0) ? S_OK : S_FALSE;
  94. }
  95.  
  96. /////////////////////////////////////////////////////////////////////////////
  97. // Returns a class factory to create an object of the requested type
  98.  
  99. STDAPI DllGetClassObject(REFCLSID rclsid, REFIID riid, LPVOID* ppv)
  100. {
  101.     return _Module.GetClassObject(rclsid, riid, ppv);
  102. }
  103.  
  104. /////////////////////////////////////////////////////////////////////////////
  105. // DllRegisterServer - Adds entries to the system registry
  106.  
  107. STDAPI DllRegisterServer(void)
  108. {
  109.     // registers object, typelib and all interfaces in typelib
  110.     return _Module.RegisterServer(TRUE);
  111. }
  112.  
  113. /////////////////////////////////////////////////////////////////////////////
  114. // DllUnregisterServer - Removes entries from the system registry
  115.  
  116. STDAPI DllUnregisterServer(void)
  117. {
  118.     //No need to unregister typelib since ATL is a system component.
  119.     return S_OK;
  120. }
  121.