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

  1. // Connect.cpp : Implementation of DLL Exports.
  2. //
  3. // This is a part of the Active Template Library.
  4. // Copyright (C) 1996-1998 Microsoft Corporation
  5. // All rights reserved.
  6. //
  7. // This source code is only intended as a supplement to the
  8. // Active Template Library Reference and related
  9. // electronic documentation provided with the library.
  10. // See these sources for detailed information regarding the
  11. // Active Template Library product.
  12.  
  13. // You will need the NT SUR Beta 2 SDK or VC 4.2 in order to build this
  14. // project.  This is because you will need MIDL 3.00.15 or higher and new
  15. // headers and libs.  If you have VC 4.2 installed, then everything should
  16. // already be configured correctly.
  17.  
  18. #include "preconn.h"
  19. #include "connres.h"
  20. #include "initguid.h"
  21. #include "Connect.h"
  22. #include "Random.h"
  23.  
  24. #define IID_DEFINED
  25. #include "Connect_i.c"
  26.  
  27.  
  28. CComModule _Module;
  29.  
  30. BEGIN_OBJECT_MAP(ObjectMap)
  31.     OBJECT_ENTRY(CLSID_CoRandom, CRandom)
  32. END_OBJECT_MAP()
  33.  
  34. /////////////////////////////////////////////////////////////////////////////
  35. // DLL Entry Point
  36.  
  37. extern "C"
  38. BOOL WINAPI DllMain(HINSTANCE hInstance, DWORD dwReason, LPVOID /*lpReserved*/)
  39. {
  40.     if (dwReason == DLL_PROCESS_ATTACH)
  41.     {
  42.         _Module.Init(ObjectMap, hInstance);
  43.         DisableThreadLibraryCalls(hInstance);
  44.     }
  45.     else if (dwReason == DLL_PROCESS_DETACH)
  46.         _Module.Term();
  47.     return TRUE;    // ok
  48. }
  49.  
  50. /////////////////////////////////////////////////////////////////////////////
  51. // Used to determine whether the DLL can be unloaded by OLE
  52.  
  53. STDAPI DllCanUnloadNow(void)
  54. {
  55.     return (_Module.GetLockCount()==0) ? S_OK : S_FALSE;
  56. }
  57.  
  58. /////////////////////////////////////////////////////////////////////////////
  59. // Returns a class factory to create an object of the requested type
  60.  
  61. STDAPI DllGetClassObject(REFCLSID rclsid, REFIID riid, LPVOID* ppv)
  62. {
  63.     return _Module.GetClassObject(rclsid, riid, ppv);
  64. }
  65.  
  66. /////////////////////////////////////////////////////////////////////////////
  67. // DllRegisterServer - Adds entries to the system registry
  68.  
  69. STDAPI DllRegisterServer(void)
  70. {
  71.     // registers object, typelib and all interfaces in typelib
  72.     return _Module.RegisterServer(TRUE);
  73. }
  74.  
  75. /////////////////////////////////////////////////////////////////////////////
  76. // DllUnregisterServer - Removes entries from the system registry
  77.  
  78. STDAPI DllUnregisterServer(void)
  79. {
  80.     _Module.UnregisterServer();
  81.     return S_OK;
  82. }
  83.