Leaked source code of windows server 2003
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.

253 lines
6.7 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 = TRUE;
  67. if(dwReason == DLL_PROCESS_ATTACH){
  68. _Module.Init(ObjectMap, hInstance);
  69. _Module.dwThreadID = GetCurrentThreadId();
  70. fReturn = MidlGeneratedDllMain(hInstance, dwReason, pvReserved);
  71. }
  72. else if(dwReason == DLL_PROCESS_DETACH){
  73. _Module.Term();
  74. }
  75. return fReturn;
  76. }
  77. /*!--------------------------------------------------------------------------
  78. DllRegisterServer
  79. -
  80. Author: KennT
  81. ---------------------------------------------------------------------------*/
  82. HRESULT STDAPICALLTYPE DllRegisterServer()
  83. {
  84. CRegObject ro;
  85. WCHAR swzPath[MAX_PATH*2 + 1] = {0};
  86. WCHAR swzModule[MAX_PATH*2 + 1] = {0};
  87. HRESULT hRes;
  88. int i, cLen;
  89. if ( !GetModuleFileNameW(_Module.GetModuleInstance(), swzPath, MAX_PATH*2) )
  90. {
  91. return GetLastError();
  92. }
  93. lstrcpyW(swzModule, swzPath);
  94. // Given this path, substitue remrras.exe for rrasprxy.dll
  95. // ----------------------------------------------------------------
  96. cLen = lstrlenW(swzPath);
  97. for (i=cLen; --i>=0; )
  98. {
  99. // Ok, this is a path marker, copy over it
  100. // ------------------------------------------------------------
  101. if (swzPath[i] == L'\\')
  102. {
  103. lstrcpyW(swzPath+i+1, L"remrras.exe");
  104. break;
  105. }
  106. }
  107. // Add in the substitute for the %REMRRAS%
  108. // ----------------------------------------------------------------
  109. ro.AddReplacement(L"REMRRAS", swzPath);
  110. // We need to fix up the registrar.
  111. // Go through and register the object CLSID for remrras.exe
  112. // ----------------------------------------------------------------
  113. ro.ResourceRegister(swzModule, ((UINT) LOWORD((DWORD)IDR_Remrras)), L"REGISTRY");
  114. // Register the APPIDs
  115. // ----------------------------------------------------------------
  116. ro.ResourceRegister(swzModule, ((UINT) LOWORD((DWORD) IDR_REMCFG)), L"REGISTRY");
  117. // Register the type library for REMRRAS
  118. // ----------------------------------------------------------------
  119. hRes = AtlModuleRegisterTypeLib(&_Module, NULL);
  120. // Call the MIDL-generated registration (to register the
  121. // proxy dll).
  122. // ----------------------------------------------------------------
  123. if (SUCCEEDED(hRes))
  124. hRes = MidlGeneratedDllRegisterServer();
  125. return hRes;
  126. }
  127. /*!--------------------------------------------------------------------------
  128. DllUnregisterServer
  129. -
  130. Author: KennT
  131. ---------------------------------------------------------------------------*/
  132. HRESULT STDAPICALLTYPE DllUnregisterServer()
  133. {
  134. CRegObject ro;
  135. WCHAR swzPath[MAX_PATH*2 + 1] = {0};
  136. WCHAR swzModule[MAX_PATH*2 + 1] = {0};
  137. HRESULT hRes;
  138. int i, cLen;
  139. if ( !GetModuleFileNameW(_Module.GetModuleInstance(), swzPath, MAX_PATH*2) )
  140. {
  141. return GetLastError();
  142. }
  143. lstrcpynW(swzModule, swzPath, MAX_PATH);
  144. // Given this path, substitue remrras.exe for rrasprxy.dll
  145. // ----------------------------------------------------------------
  146. cLen = lstrlenW(swzPath);
  147. for (i=cLen; --i>=0; )
  148. {
  149. // Ok, this is a path marker, copy over it
  150. // ------------------------------------------------------------
  151. if (swzPath[i] == L'\\')
  152. {
  153. lstrcpyW(swzPath+i+1, L"remrras.exe");
  154. break;
  155. }
  156. }
  157. // Add in the substitute for the %REMRRAS%
  158. // ----------------------------------------------------------------
  159. ro.AddReplacement(L"REMRRAS", swzPath);
  160. // We need to fix up the registrar.
  161. // Go through and register the object CLSID for remrras.exe
  162. // ----------------------------------------------------------------
  163. ro.ResourceUnregister(swzModule, ((UINT) LOWORD((DWORD)IDR_Remrras)), L"REGISTRY");
  164. // Unregister the APPID
  165. // ----------------------------------------------------------------
  166. ro.ResourceUnregister(swzModule, ((UINT) LOWORD((DWORD)IDR_REMCFG)), L"REGISTRY");
  167. // Unregister the type library
  168. // ----------------------------------------------------------------
  169. hRes = UnRegisterTypeLib(LIBID_REMRRASLib,
  170. 1, 0, // version 1.0
  171. LOCALE_SYSTEM_DEFAULT,
  172. SYS_WIN32);
  173. // Call the MIDL-generated registration (to unregister the
  174. // proxy dll).
  175. // ----------------------------------------------------------------
  176. hRes = MidlGeneratedDllUnregisterServer();
  177. return hRes;
  178. }
  179. /*!--------------------------------------------------------------------------
  180. DllGetClassObject
  181. -
  182. Author: KennT
  183. ---------------------------------------------------------------------------*/
  184. HRESULT STDAPICALLTYPE DllGetClassObject(REFCLSID rclsid,
  185. REFIID riid,
  186. void **ppv)
  187. {
  188. return MidlGeneratedDllGetClassObject(rclsid, riid, ppv);
  189. }
  190. /*!--------------------------------------------------------------------------
  191. DllCanUnloadNow
  192. -
  193. Author: KennT
  194. ---------------------------------------------------------------------------*/
  195. HRESULT STDAPICALLTYPE DllCanUnloadNow()
  196. {
  197. return MidlGeneratedDllCanUnloadNow();
  198. }