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.

240 lines
6.2 KiB

  1. //+-------------------------------------------------------------------------
  2. //
  3. // Microsoft Windows
  4. //
  5. // Copyright (C) Microsoft Corporation, 1998 - 1999
  6. //
  7. // File: rrasprxy.cpp
  8. //
  9. //--------------------------------------------------------------------------
  10. #include <stdafx.h>
  11. #include <windows.h>
  12. #include "remras.h"
  13. #include "resource.h"
  14. #define _ATL_APARTMENT_THREADED
  15. #define _ATL_STATIC_REGISTRY
  16. #include <atlbase.h>
  17. //You may derive a class from CComModule and use it if you want to override
  18. //something, but do not change the name of _Module
  19. class CExeModule : public CComModule
  20. {
  21. public:
  22. LONG Unlock();
  23. DWORD dwThreadID;
  24. };
  25. CExeModule _Module;
  26. #include <atlcom.h>
  27. #undef _ATL_DLL
  28. #include <statreg.h>
  29. #include <statreg.cpp>
  30. #define _ATL_DLL
  31. #include <atlimpl.cpp>
  32. BEGIN_OBJECT_MAP(ObjectMap)
  33. // OBJECT_ENTRY(CLSID_RemoteRouterConfig, CRemCfg)
  34. END_OBJECT_MAP()
  35. extern "C" {
  36. extern BOOL WINAPI MidlGeneratedDllMain(HINSTANCE, DWORD, LPVOID);
  37. extern HRESULT STDAPICALLTYPE MidlGeneratedDllRegisterServer();
  38. extern HRESULT STDAPICALLTYPE MidlGeneratedDllUnregisterServer();
  39. extern HRESULT STDAPICALLTYPE MidlGeneratedDllGetClassObject(REFCLSID,REFIID,
  40. void **);
  41. extern HRESULT STDAPICALLTYPE MidlGeneratedDllCanUnloadNow();
  42. };
  43. LONG CExeModule::Unlock()
  44. {
  45. LONG l = CComModule::Unlock();
  46. if (l == 0)
  47. {
  48. #if _WIN32_WINNT >= 0x0400
  49. if (CoSuspendClassObjects() == S_OK)
  50. PostThreadMessage(dwThreadID, WM_QUIT, 0, 0);
  51. #else
  52. PostThreadMessage(dwThreadID, WM_QUIT, 0, 0);
  53. #endif
  54. }
  55. return l;
  56. }
  57. /*!--------------------------------------------------------------------------
  58. DllMain
  59. -
  60. Author: KennT
  61. ---------------------------------------------------------------------------*/
  62. BOOL WINAPI DllMain(HINSTANCE hInstance,
  63. DWORD dwReason,
  64. LPVOID pvReserved)
  65. {
  66. BOOL fReturn;
  67. _Module.Init(ObjectMap, hInstance);
  68. _Module.dwThreadID = GetCurrentThreadId();
  69. fReturn = MidlGeneratedDllMain(hInstance, dwReason, pvReserved);
  70. return fReturn;
  71. }
  72. /*!--------------------------------------------------------------------------
  73. DllRegisterServer
  74. -
  75. Author: KennT
  76. ---------------------------------------------------------------------------*/
  77. HRESULT STDAPICALLTYPE DllRegisterServer()
  78. {
  79. CRegObject ro;
  80. WCHAR swzPath[MAX_PATH*2 + 1];
  81. WCHAR swzModule[MAX_PATH*2 + 1];
  82. HRESULT hRes;
  83. int i, cLen;
  84. GetModuleFileNameW(_Module.GetModuleInstance(), swzPath, MAX_PATH*2);
  85. lstrcpyW(swzModule, swzPath);
  86. // Given this path, substitue remrras.exe for rrasprxy.dll
  87. // ----------------------------------------------------------------
  88. cLen = lstrlenW(swzPath);
  89. for (i=cLen; --i>=0; )
  90. {
  91. // Ok, this is a path marker, copy over it
  92. // ------------------------------------------------------------
  93. if (swzPath[i] == L'\\')
  94. {
  95. lstrcpyW(swzPath+i+1, L"remrras.exe");
  96. break;
  97. }
  98. }
  99. // Add in the substitute for the %REMRRAS%
  100. // ----------------------------------------------------------------
  101. ro.AddReplacement(L"REMRRAS", swzPath);
  102. // We need to fix up the registrar.
  103. // Go through and register the object CLSID for remrras.exe
  104. // ----------------------------------------------------------------
  105. ro.ResourceRegister(swzModule, ((UINT) LOWORD((DWORD)IDR_Remrras)), L"REGISTRY");
  106. // Register the APPIDs
  107. // ----------------------------------------------------------------
  108. ro.ResourceRegister(swzModule, ((UINT) LOWORD((DWORD) IDR_REMCFG)), L"REGISTRY");
  109. // Register the type library for REMRRAS
  110. // ----------------------------------------------------------------
  111. hRes = AtlModuleRegisterTypeLib(&_Module, NULL);
  112. // Call the MIDL-generated registration (to register the
  113. // proxy dll).
  114. // ----------------------------------------------------------------
  115. if (SUCCEEDED(hRes))
  116. hRes = MidlGeneratedDllRegisterServer();
  117. return hRes;
  118. }
  119. /*!--------------------------------------------------------------------------
  120. DllUnregisterServer
  121. -
  122. Author: KennT
  123. ---------------------------------------------------------------------------*/
  124. HRESULT STDAPICALLTYPE DllUnregisterServer()
  125. {
  126. CRegObject ro;
  127. WCHAR swzPath[MAX_PATH*2 + 1];
  128. WCHAR swzModule[MAX_PATH*2 + 1];
  129. HRESULT hRes;
  130. int i, cLen;
  131. GetModuleFileNameW(_Module.GetModuleInstance(), swzPath, MAX_PATH*2);
  132. lstrcpyW(swzModule, swzPath);
  133. // Given this path, substitue remrras.exe for rrasprxy.dll
  134. // ----------------------------------------------------------------
  135. cLen = lstrlenW(swzPath);
  136. for (i=cLen; --i>=0; )
  137. {
  138. // Ok, this is a path marker, copy over it
  139. // ------------------------------------------------------------
  140. if (swzPath[i] == L'\\')
  141. {
  142. lstrcpyW(swzPath+i+1, L"remrras.exe");
  143. break;
  144. }
  145. }
  146. // Add in the substitute for the %REMRRAS%
  147. // ----------------------------------------------------------------
  148. ro.AddReplacement(L"REMRRAS", swzPath);
  149. // We need to fix up the registrar.
  150. // Go through and register the object CLSID for remrras.exe
  151. // ----------------------------------------------------------------
  152. ro.ResourceUnregister(swzModule, ((UINT) LOWORD((DWORD)IDR_Remrras)), L"REGISTRY");
  153. // Unregister the APPID
  154. // ----------------------------------------------------------------
  155. ro.ResourceUnregister(swzModule, ((UINT) LOWORD((DWORD)IDR_REMCFG)), L"REGISTRY");
  156. // Unregister the type library
  157. // ----------------------------------------------------------------
  158. hRes = UnRegisterTypeLib(LIBID_REMRRASLib,
  159. 1, 0, // version 1.0
  160. LOCALE_SYSTEM_DEFAULT,
  161. SYS_WIN32);
  162. // Call the MIDL-generated registration (to unregister the
  163. // proxy dll).
  164. // ----------------------------------------------------------------
  165. hRes = MidlGeneratedDllUnregisterServer();
  166. return hRes;
  167. }
  168. /*!--------------------------------------------------------------------------
  169. DllGetClassObject
  170. -
  171. Author: KennT
  172. ---------------------------------------------------------------------------*/
  173. HRESULT STDAPICALLTYPE DllGetClassObject(REFCLSID rclsid,
  174. REFIID riid,
  175. void **ppv)
  176. {
  177. return MidlGeneratedDllGetClassObject(rclsid, riid, ppv);
  178. }
  179. /*!--------------------------------------------------------------------------
  180. DllCanUnloadNow
  181. -
  182. Author: KennT
  183. ---------------------------------------------------------------------------*/
  184. HRESULT STDAPICALLTYPE DllCanUnloadNow()
  185. {
  186. return MidlGeneratedDllCanUnloadNow();
  187. }