home *** CD-ROM | disk | FTP | other *** search
/ Tricks of the Windows Gam…ming Gurus (2nd Edition) / Disc2.iso / msdn_vcb / samples / vc98 / addins / cmdwnd / cmdstub / cmdstub.cpp < prev    next >
C/C++ Source or Header  |  1998-04-02  |  3KB  |  115 lines

  1. // cmdstub.cpp : Implementation of DLL Exports.
  2.  
  3.  
  4. // Note: Proxy/Stub Information
  5. //      To merge the proxy/stub code into the object DLL, add the file 
  6. //      dlldatax.c to the project.  Make sure precompiled headers 
  7. //      are turned off for this file, and add _MERGE_PROXYSTUB to the 
  8. //      defines for the project.  
  9. //
  10. //      If you are not running WinNT4.0 or Win95 with DCOM, then you
  11. //      need to remove the following define from dlldatax.c
  12. //      #define _WIN32_WINNT 0x0400
  13. //
  14. //      Further, if you are running MIDL without /Oicf switch, you also 
  15. //      need to remove the following define from dlldatax.c.
  16. //      #define USE_STUBLESS_PROXY
  17. //
  18. //      Modify the custom build rule for cmdstub.idl by adding the following 
  19. //      files to the Outputs.
  20. //          cmdstub_p.c
  21. //          dlldata.c
  22. //      To build a separate proxy/stub DLL, 
  23. //      run nmake -f cmdstubps.mk in the project directory.
  24.  
  25. #include "stdafx.h"
  26. #include "resource.h"
  27. #include <initguid.h>
  28. #include "cmdstub.h"
  29. #include "dlldatax.h"
  30.  
  31. #include "cmdstub_i.c"
  32. #include "CmdWnd.h"
  33.  
  34. #ifdef _MERGE_PROXYSTUB
  35. extern "C" HINSTANCE hProxyDll;
  36. #endif
  37.  
  38. CComModule _Module;
  39.  
  40. BEGIN_OBJECT_MAP(ObjectMap)
  41. OBJECT_ENTRY(CLSID_CmdWnd, CCmdWnd)
  42. END_OBJECT_MAP()
  43.  
  44. /////////////////////////////////////////////////////////////////////////////
  45. // DLL Entry Point
  46.  
  47. extern "C"
  48. BOOL WINAPI DllMain(HINSTANCE hInstance, DWORD dwReason, LPVOID lpReserved)
  49. {
  50.     lpReserved;
  51. #ifdef _MERGE_PROXYSTUB
  52.     if (!PrxDllMain(hInstance, dwReason, lpReserved))
  53.         return FALSE;
  54. #endif
  55.     if (dwReason == DLL_PROCESS_ATTACH)
  56.     {
  57.         _Module.Init(ObjectMap, hInstance, &LIBID_CMDSTUBLib);
  58.         DisableThreadLibraryCalls(hInstance);
  59.     }
  60.     else if (dwReason == DLL_PROCESS_DETACH)
  61.         _Module.Term();
  62.     return TRUE;    // ok
  63. }
  64.  
  65. /////////////////////////////////////////////////////////////////////////////
  66. // Used to determine whether the DLL can be unloaded by OLE
  67.  
  68. STDAPI DllCanUnloadNow(void)
  69. {
  70. #ifdef _MERGE_PROXYSTUB
  71.     if (PrxDllCanUnloadNow() != S_OK)
  72.         return S_FALSE;
  73. #endif
  74.     return (_Module.GetLockCount()==0) ? S_OK : S_FALSE;
  75. }
  76.  
  77. /////////////////////////////////////////////////////////////////////////////
  78. // Returns a class factory to create an object of the requested type
  79.  
  80. STDAPI DllGetClassObject(REFCLSID rclsid, REFIID riid, LPVOID* ppv)
  81. {
  82. #ifdef _MERGE_PROXYSTUB
  83.     if (PrxDllGetClassObject(rclsid, riid, ppv) == S_OK)
  84.         return S_OK;
  85. #endif
  86.     return _Module.GetClassObject(rclsid, riid, ppv);
  87. }
  88.  
  89. /////////////////////////////////////////////////////////////////////////////
  90. // DllRegisterServer - Adds entries to the system registry
  91.  
  92. STDAPI DllRegisterServer(void)
  93. {
  94. #ifdef _MERGE_PROXYSTUB
  95.     HRESULT hRes = PrxDllRegisterServer();
  96.     if (FAILED(hRes))
  97.         return hRes;
  98. #endif
  99.     // registers object, typelib and all interfaces in typelib
  100.     return _Module.RegisterServer(TRUE);
  101. }
  102.  
  103. /////////////////////////////////////////////////////////////////////////////
  104. // DllUnregisterServer - Removes entries from the system registry
  105.  
  106. STDAPI DllUnregisterServer(void)
  107. {
  108. #ifdef _MERGE_PROXYSTUB
  109.     PrxDllUnregisterServer();
  110. #endif
  111.     return _Module.UnregisterServer(TRUE);
  112. }
  113.  
  114.  
  115.