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.

222 lines
5.2 KiB

  1. #include "pch.h"
  2. #pragma hdrstop
  3. // This avoids duplicate definitions with Shell PIDL functions
  4. // and MUST BE DEFINED!
  5. #define AVOID_NET_CONFIG_DUPLICATES
  6. #include <atlbase.h>
  7. extern CComModule _Module;
  8. #include <atlcom.h>
  9. #include "ncatl.h"
  10. #include "nsbase.h"
  11. #include "upnpshell.h"
  12. #include "upnpfold.h"
  13. // Connection Folder Objects
  14. //
  15. // Undocument shell32 stuff. Sigh.
  16. #define DONT_WANT_SHELLDEBUG 1
  17. #define NO_SHIDLIST 1
  18. #define USE_SHLWAPI_IDLIST
  19. #include <commctrl.h>
  20. #include <shlobjp.h>
  21. #define INITGUID
  22. #include "upclsid.h"
  23. //+---------------------------------------------------------------------------
  24. // Note: Proxy/Stub Information
  25. // To merge the proxy/stub code into the object DLL, add the file
  26. // dlldatax.c to the project. Make sure precompiled headers
  27. // are turned off for this file, and add _MERGE_PROXYSTUB to the
  28. // defines for the project.
  29. //
  30. // If you are not running WinNT4.0 or Win95 with DCOM, then you
  31. // need to remove the following define from dlldatax.c
  32. // #define _WIN32_WINNT 0x0400
  33. //
  34. // Further, if you are running MIDL without /Oicf switch, you also
  35. // need to remove the following define from dlldatax.c.
  36. // #define USE_STUBLESS_PROXY
  37. //
  38. // Modify the custom build rule for foo.idl by adding the following
  39. // files to the Outputs.
  40. // foo_p.c
  41. // dlldata.c
  42. // To build a separate proxy/stub DLL,
  43. // run nmake -f foops.mk in the project directory.
  44. // Proxy/Stub registration entry points
  45. //
  46. #include "dlldatax.h"
  47. #include "upnptray.h"
  48. #ifdef _MERGE_PROXYSTUB
  49. extern "C" HINSTANCE hProxyDll;
  50. #endif
  51. CComModule _Module;
  52. BEGIN_OBJECT_MAP(ObjectMap)
  53. // Connection Folder and enumerator
  54. //
  55. OBJECT_ENTRY(CLSID_UPnPDeviceFolder, CUPnPDeviceFolder)
  56. OBJECT_ENTRY(CLSID_UPnPMonitor, CUPnPTray)
  57. END_OBJECT_MAP()
  58. //+---------------------------------------------------------------------------
  59. // DLL Entry Point
  60. //
  61. EXTERN_C
  62. BOOL
  63. WINAPI
  64. DllMain (
  65. HINSTANCE hInstance,
  66. DWORD dwReason,
  67. LPVOID lpReserved)
  68. {
  69. //#ifdef _MERGE_PROXYSTUB
  70. // if (!PrxDllMain(hInstance, dwReason, lpReserved))
  71. // {
  72. // return FALSE;
  73. // }
  74. //#endif
  75. if (dwReason == DLL_PROCESS_ATTACH)
  76. {
  77. DisableThreadLibraryCalls(hInstance);
  78. InitializeDebugging();
  79. if (FIsDebugFlagSet (dfidNetShellBreakOnInit))
  80. {
  81. DebugBreak();
  82. }
  83. _Module.Init(ObjectMap, hInstance);
  84. InitializeCriticalSection(&g_csFolderDeviceList);
  85. }
  86. else if (dwReason == DLL_PROCESS_DETACH)
  87. {
  88. DbgCheckPrematureDllUnload ("netshell.dll", _Module.GetLockCount());
  89. DeleteCriticalSection(&g_csFolderDeviceList);
  90. _Module.Term();
  91. UnInitializeDebugging();
  92. }
  93. return TRUE;
  94. }
  95. //+---------------------------------------------------------------------------
  96. // Used to determine whether the DLL can be unloaded by OLE
  97. //
  98. STDAPI
  99. DllCanUnloadNow ()
  100. {
  101. //#ifdef _MERGE_PROXYSTUB
  102. // if (PrxDllCanUnloadNow() != S_OK)
  103. // {
  104. // return S_FALSE;
  105. // }
  106. //#endif
  107. return (_Module.GetLockCount() == 0) ? S_OK : S_FALSE;
  108. }
  109. //+---------------------------------------------------------------------------
  110. // Returns a class factory to create an object of the requested type
  111. //
  112. STDAPI
  113. DllGetClassObject (
  114. REFCLSID rclsid,
  115. REFIID riid,
  116. LPVOID* ppv)
  117. {
  118. //#ifdef _MERGE_PROXYSTUB
  119. // if (PrxDllGetClassObject(rclsid, riid, ppv) == S_OK)
  120. // {
  121. // return S_OK;
  122. // }
  123. //#endif
  124. return _Module.GetClassObject(rclsid, riid, ppv);
  125. }
  126. //+---------------------------------------------------------------------------
  127. // DllRegisterServer - Adds entries to the system registry
  128. //
  129. STDAPI
  130. DllRegisterServer ()
  131. {
  132. BOOL fCoUninitialize = TRUE;
  133. HRESULT hr = CoInitializeEx (NULL,
  134. COINIT_DISABLE_OLE1DDE | COINIT_APARTMENTTHREADED);
  135. if (FAILED(hr))
  136. {
  137. fCoUninitialize = FALSE;
  138. if (RPC_E_CHANGED_MODE == hr)
  139. {
  140. hr = S_OK;
  141. }
  142. }
  143. if (SUCCEEDED(hr))
  144. {
  145. //#ifdef _MERGE_PROXYSTUB
  146. // hr = PrxDllRegisterServer ();
  147. // if (FAILED(hr))
  148. // {
  149. // goto Exit;
  150. // }
  151. //#endif
  152. hr = NcAtlModuleRegisterServer (&_Module);
  153. if (SUCCEEDED(hr))
  154. {
  155. hr = HrRegisterFolderClass();
  156. if (SUCCEEDED(hr))
  157. {
  158. // Notify the shell to reload the new shell extension
  159. SHEnableServiceObject(CLSID_UPnPMonitor, TRUE);
  160. }
  161. }
  162. if (fCoUninitialize)
  163. {
  164. CoUninitialize ();
  165. }
  166. }
  167. TraceHr (ttidError, FAL, hr, FALSE, "upnpfold!DllRegisterServer");
  168. return hr;
  169. }
  170. //+---------------------------------------------------------------------------
  171. // DllUnregisterServer - Removes entries from the system registry
  172. //
  173. STDAPI
  174. DllUnregisterServer ()
  175. {
  176. //#ifdef _MERGE_PROXYSTUB
  177. // PrxDllUnregisterServer ();
  178. //#endif
  179. CONST WCHAR c_szNetworkNeighborhoodFolderPathCLSID[] = L"::{208D2C60-3AEA-1069-A2D7-08002B30309D}";
  180. _Module.UnregisterServer ();
  181. HrUnRegisterDelegateFolderKey();
  182. HrUnRegisterUPnPUIKey();
  183. SHChangeNotify(SHCNE_UPDATEDIR, SHCNF_PATHW, c_szNetworkNeighborhoodFolderPathCLSID, NULL);
  184. return S_OK;
  185. }