Source code of Windows XP (NT5)
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

195 lines
4.3 KiB

  1. //+---------------------------------------------------------------------------
  2. //
  3. // Microsoft Windows
  4. // Copyright (C) Microsoft Corporation, 1997.
  5. //
  6. // File: D L L M A I N . C P P
  7. //
  8. // Contents: DLL entry points for upnpcont.dll
  9. //
  10. // Notes:
  11. //
  12. // Author: mbend 8 Aug 2000
  13. //
  14. //----------------------------------------------------------------------------
  15. #include "pch.h"
  16. #pragma hdrstop
  17. #include "ucres.h"
  18. #include "ucbase.h"
  19. #include "hostp.h"
  20. #include "hostp_i.c"
  21. // Headers of COM objects
  22. #include "Container.h"
  23. //#define INITGUID
  24. //#include "uhclsid.h"
  25. //+---------------------------------------------------------------------------
  26. // Note: Proxy/Stub Information
  27. // To merge the proxy/stub code into the object DLL, add the file
  28. // dlldatax.c to the project. Make sure precompiled headers
  29. // are turned off for this file, and add _MERGE_PROXYSTUB to the
  30. // defines for the project.
  31. //
  32. // If you are not running WinNT4.0 or Win95 with DCOM, then you
  33. // need to remove the following define from dlldatax.c
  34. // #define _WIN32_WINNT 0x0400
  35. //
  36. // Further, if you are running MIDL without /Oicf switch, you also
  37. // need to remove the following define from dlldatax.c.
  38. // #define USE_STUBLESS_PROXY
  39. //
  40. // Modify the custom build rule for foo.idl by adding the following
  41. // files to the Outputs.
  42. // foo_p.c
  43. // dlldata.c
  44. // To build a separate proxy/stub DLL,
  45. // run nmake -f foops.mk in the project directory.
  46. // Proxy/Stub registration entry points
  47. //
  48. #include "dlldatax.h"
  49. #ifdef _MERGE_PROXYSTUB
  50. extern "C" HINSTANCE hProxyDll;
  51. #endif
  52. CComModule _Module;
  53. BEGIN_OBJECT_MAP(ObjectMap)
  54. OBJECT_ENTRY(CLSID_UPnPContainer, CContainer)
  55. END_OBJECT_MAP()
  56. //+---------------------------------------------------------------------------
  57. // DLL Entry Point
  58. //
  59. EXTERN_C
  60. BOOL
  61. WINAPI
  62. DllMain (
  63. HINSTANCE hInstance,
  64. DWORD dwReason,
  65. LPVOID lpReserved)
  66. {
  67. #ifdef _MERGE_PROXYSTUB
  68. if (!PrxDllMain(hInstance, dwReason, lpReserved))
  69. {
  70. return FALSE;
  71. }
  72. #endif
  73. if (dwReason == DLL_PROCESS_ATTACH)
  74. {
  75. DisableThreadLibraryCalls(hInstance);
  76. InitializeDebugging();
  77. _Module.Init(ObjectMap, hInstance);
  78. }
  79. else if (dwReason == DLL_PROCESS_DETACH)
  80. {
  81. DbgCheckPrematureDllUnload ("netshell.dll", _Module.GetLockCount());
  82. _Module.Term();
  83. UnInitializeDebugging();
  84. }
  85. return TRUE;
  86. }
  87. //+---------------------------------------------------------------------------
  88. // Used to determine whether the DLL can be unloaded by OLE
  89. //
  90. STDAPI
  91. DllCanUnloadNow ()
  92. {
  93. #ifdef _MERGE_PROXYSTUB
  94. if (PrxDllCanUnloadNow() != S_OK)
  95. {
  96. return S_FALSE;
  97. }
  98. #endif
  99. return (_Module.GetLockCount() == 0) ? S_OK : S_FALSE;
  100. }
  101. //+---------------------------------------------------------------------------
  102. // Returns a class factory to create an object of the requested type
  103. //
  104. STDAPI
  105. DllGetClassObject (
  106. REFCLSID rclsid,
  107. REFIID riid,
  108. LPVOID* ppv)
  109. {
  110. #ifdef _MERGE_PROXYSTUB
  111. if (PrxDllGetClassObject(rclsid, riid, ppv) == S_OK)
  112. {
  113. return S_OK;
  114. }
  115. #endif
  116. return _Module.GetClassObject(rclsid, riid, ppv);
  117. }
  118. //+---------------------------------------------------------------------------
  119. // DllRegisterServer - Adds entries to the system registry
  120. //
  121. STDAPI
  122. DllRegisterServer ()
  123. {
  124. BOOL fCoUninitialize = TRUE;
  125. HRESULT hr = CoInitializeEx (NULL,
  126. COINIT_DISABLE_OLE1DDE | COINIT_APARTMENTTHREADED);
  127. if (FAILED(hr))
  128. {
  129. fCoUninitialize = FALSE;
  130. if (RPC_E_CHANGED_MODE == hr)
  131. {
  132. hr = S_OK;
  133. }
  134. }
  135. if (SUCCEEDED(hr))
  136. {
  137. #ifdef _MERGE_PROXYSTUB
  138. hr = PrxDllRegisterServer ();
  139. if (FAILED(hr))
  140. {
  141. goto Exit;
  142. }
  143. #endif
  144. hr = _Module.RegisterServer();
  145. Exit:
  146. if (fCoUninitialize)
  147. {
  148. CoUninitialize ();
  149. }
  150. }
  151. TraceHr (ttidError, FAL, hr, FALSE, "netshell!DllRegisterServer");
  152. return hr;
  153. }
  154. //+---------------------------------------------------------------------------
  155. // DllUnregisterServer - Removes entries from the system registry
  156. //
  157. STDAPI
  158. DllUnregisterServer ()
  159. {
  160. #ifdef _MERGE_PROXYSTUB
  161. PrxDllUnregisterServer ();
  162. #endif
  163. _Module.UnregisterServer ();
  164. return S_OK;
  165. }