home *** CD-ROM | disk | FTP | other *** search
/ Tricks of the Windows Gam…ming Gurus (2nd Edition) / Disc2.iso / msdn_vcb / samples / vc98 / atl / polygon / polygon.cpp < prev    next >
C/C++ Source or Header  |  1998-03-26  |  2KB  |  82 lines

  1. // Polygon.cpp : Implementation of DLL Exports.
  2.  
  3.  
  4. // Note: Proxy/Stub Information
  5. //      To build a separate proxy/stub DLL,
  6. //      run nmake -f Polygonps.mk in the project directory.
  7.  
  8. #include "stdafx.h"
  9. #include "resource.h"
  10. #include <initguid.h>
  11. #include "Polygon.h"
  12.  
  13. #include "Polygon_i.c"
  14. #include "PolyCtl.h"
  15. #include "PolyProp.h"
  16.  
  17.  
  18. CComModule _Module;
  19.  
  20. BEGIN_OBJECT_MAP(ObjectMap)
  21. OBJECT_ENTRY(CLSID_PolyCtl, CPolyCtl)
  22. OBJECT_ENTRY(CLSID_PolyProp, CPolyProp)
  23. END_OBJECT_MAP()
  24.  
  25. /////////////////////////////////////////////////////////////////////////////
  26. // DLL Entry Point
  27.  
  28. extern "C"
  29. BOOL WINAPI DllMain(HINSTANCE hInstance, DWORD dwReason, LPVOID /*lpReserved*/)
  30. {
  31.     if (dwReason == DLL_PROCESS_ATTACH)
  32.     {
  33.         _Module.Init(ObjectMap, hInstance, &LIBID_POLYGONLib);
  34.         DisableThreadLibraryCalls(hInstance);
  35.     }
  36.     else if (dwReason == DLL_PROCESS_DETACH)
  37.         _Module.Term();
  38.     return TRUE;    // ok
  39. }
  40.  
  41. /////////////////////////////////////////////////////////////////////////////
  42. // Used to determine whether the DLL can be unloaded by OLE
  43.  
  44. STDAPI DllCanUnloadNow(void)
  45. {
  46.     return (_Module.GetLockCount()==0) ? S_OK : S_FALSE;
  47. }
  48.  
  49. /////////////////////////////////////////////////////////////////////////////
  50. // Returns a class factory to create an object of the requested type
  51.  
  52. STDAPI DllGetClassObject(REFCLSID rclsid, REFIID riid, LPVOID* ppv)
  53. {
  54.     return _Module.GetClassObject(rclsid, riid, ppv);
  55. }
  56.  
  57. /////////////////////////////////////////////////////////////////////////////
  58. // DllRegisterServer - Adds entries to the system registry
  59.  
  60. STDAPI DllRegisterServer(void)
  61. {
  62.     // registers object, typelib and all interfaces in typelib
  63.     return _Module.RegisterServer(TRUE);
  64. }
  65.  
  66. /////////////////////////////////////////////////////////////////////////////
  67. // DllUnregisterServer - Removes entries from the system registry
  68.  
  69. STDAPI DllUnregisterServer(void)
  70. {
  71.     HRESULT hr = _Module.UnregisterServer();
  72.  
  73. #if _WIN32_WINNT >= 0x0400
  74.     if (FAILED(hr))
  75.         return hr;
  76.     // Following assumes that the type library version is 1.0
  77.     hr = UnRegisterTypeLib(LIBID_POLYGONLib, 1, 0, LOCALE_NEUTRAL, SYS_WIN32);
  78. #endif
  79.  
  80.     return hr;
  81. }
  82.