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.

359 lines
8.6 KiB

  1. /******************************************************************************
  2. Copyright (c) 2000 Microsoft Corporation
  3. Module Name:
  4. FrmMars.cpp
  5. Abstract:
  6. This file contains the implementation of the CSRFrameMars class, which
  7. implements SR UI using MARS / IE.
  8. Revision History:
  9. Seong Kook Khang (SKKhang) 04/04/2000
  10. created
  11. ******************************************************************************/
  12. #include "stdwin.h"
  13. #include "stdatl.h"
  14. #include <MarsHost.h>
  15. #include "resource.h"
  16. #include "rstrpriv.h"
  17. #include <initguid.h>
  18. #include "srui_htm.h"
  19. #include "rstrmgr.h"
  20. #include "rstrprog.h"
  21. #include "rstrshl.h"
  22. #include "FrmBase.h"
  23. #include "srui_htm_i.c"
  24. /////////////////////////////////////////////////////////////////////////////
  25. //
  26. // ATL Module for UI Frame
  27. //
  28. /////////////////////////////////////////////////////////////////////////////
  29. CComModule _Module;
  30. BEGIN_OBJECT_MAP(ObjectMap)
  31. OBJECT_ENTRY(CLSID_RstrProgress, CRstrProgress)
  32. //OBJECT_ENTRY(CLSID_RstrEdit, CRstrEdit)
  33. OBJECT_ENTRY(CLSID_RestoreShellExternal, CRestoreShell)
  34. END_OBJECT_MAP()
  35. /////////////////////////////////////////////////////////////////////////////
  36. //
  37. // CSRFrameMars
  38. //
  39. /////////////////////////////////////////////////////////////////////////////
  40. class CSRFrameMars : public ISRFrameBase
  41. {
  42. public:
  43. CSRFrameMars();
  44. ~CSRFrameMars();
  45. // ISRUI_Base methods
  46. public:
  47. DWORD RegisterServer();
  48. DWORD UnregisterServer();
  49. BOOL InitInstance( HINSTANCE hInst );
  50. BOOL ExitInstance();
  51. void Release();
  52. int RunUI( LPCWSTR szTitle, int nStart );
  53. // Operations
  54. protected:
  55. BOOL CleanUp();
  56. DWORD InvokeMARS( LPCWSTR szTitle );
  57. // Attributes
  58. protected:
  59. HWND m_hWnd;
  60. };
  61. /////////////////////////////////////////////////////////////////////////////
  62. // CSRFrameMars create instance
  63. BOOL CreateSRFrameInstance( ISRFrameBase **pUI )
  64. {
  65. TraceFunctEnter("CreateSRFrameInstance");
  66. BOOL fRet = TRUE;
  67. LPCWSTR cszErr;
  68. *pUI = new CSRFrameMars;
  69. if ( *pUI == NULL )
  70. {
  71. cszErr = ::GetSysErrStr();
  72. ErrorTrace(TRACE_ID, "Creating SRUI Instance failed - %s", cszErr);
  73. fRet = FALSE;
  74. goto Exit;
  75. }
  76. Exit:
  77. TraceFunctLeave();
  78. return( fRet );
  79. }
  80. /////////////////////////////////////////////////////////////////////////////
  81. // CSRFrameMars construction/destruction
  82. CSRFrameMars::CSRFrameMars()
  83. {
  84. m_hWnd = NULL;
  85. }
  86. CSRFrameMars::~CSRFrameMars()
  87. {
  88. }
  89. /////////////////////////////////////////////////////////////////////////////
  90. // CSRFrameMars - ISRFrameBase methods
  91. DWORD CSRFrameMars::RegisterServer()
  92. {
  93. TraceFunctEnter("CSRFrameMars::RegisterServer");
  94. DWORD dwRet = 0;
  95. HRESULT hr;
  96. hr = _Module.UpdateRegistryFromResource(IDR_RSTRUI, TRUE);
  97. if ( FAILED(hr) )
  98. {
  99. ErrorTrace(TRACE_ID, "CComModule::UpdateRegistryFromResource failed, err=%l", hr);
  100. dwRet = hr;
  101. goto Exit;
  102. }
  103. hr = _Module.RegisterServer(TRUE);
  104. if ( FAILED(hr) )
  105. {
  106. ErrorTrace(TRACE_ID, "CComModule::RegisterServer failed, err=%l", hr);
  107. dwRet = hr;
  108. goto Exit;
  109. }
  110. Exit:
  111. TraceFunctLeave();
  112. return( dwRet );
  113. }
  114. DWORD CSRFrameMars::UnregisterServer()
  115. {
  116. TraceFunctEnter("CSRFrameMars::UnregisterServer");
  117. DWORD dwRet = 0;
  118. HRESULT hr;
  119. hr = _Module.UpdateRegistryFromResource(IDR_RSTRUI, FALSE);
  120. if ( FAILED(hr) )
  121. {
  122. ErrorTrace(TRACE_ID, "CComModule::UpdateRegistryFromResource failed, err=%l", hr);
  123. dwRet = hr;
  124. goto Exit;
  125. }
  126. hr = _Module.UnregisterServer(TRUE);
  127. if ( FAILED(hr) )
  128. {
  129. ErrorTrace(TRACE_ID, "CComModule::UnregisterServer failed, err=%l", hr);
  130. dwRet = hr;
  131. goto Exit;
  132. }
  133. Exit:
  134. TraceFunctLeave();
  135. return( dwRet );
  136. }
  137. BOOL CSRFrameMars::InitInstance( HINSTANCE hInst )
  138. {
  139. TraceFunctEnter("CSRFrameMars::InitInstance");
  140. BOOL fRet = TRUE;
  141. HRESULT hr;
  142. //BUGBUG - Is this necessary???
  143. g_hInst = hInst;
  144. #if _WIN32_WINNT >= 0x0400 & defined(_ATL_FREE_THREADED)
  145. hr = ::CoInitializeEx(NULL, COINIT_MULTITHREADED);
  146. #else
  147. // we're using apartment threading model
  148. hr = ::CoInitialize(NULL);
  149. #endif
  150. if (FAILED(hr))
  151. {
  152. FatalTrace(TRACE_ID, "Cannot initialize COM, hr=%l", hr);
  153. fRet = FALSE;
  154. goto Exit;
  155. }
  156. _Module.Init(ObjectMap, hInst, &LIBID_RestoreUILib);
  157. Exit:
  158. TraceFunctLeave();
  159. return( fRet );
  160. }
  161. BOOL CSRFrameMars::ExitInstance()
  162. {
  163. TraceFunctEnter("CSRFrameMars::ExitInstance");
  164. _Module.Term();
  165. ::CoUninitialize();
  166. TraceFunctLeave();
  167. return( TRUE );
  168. }
  169. void CSRFrameMars::Release()
  170. {
  171. TraceFunctEnter("CSRFrameMars::Release");
  172. // clean up...
  173. delete this;
  174. TraceFunctLeave();
  175. }
  176. int CSRFrameMars::RunUI( LPCWSTR szTitle, int nStart )
  177. {
  178. TraceFunctEnter("CSRFrameMars::RunUI");
  179. int nRet = 0;
  180. HRESULT hr;
  181. RECT rc = { 0, 0, 0, 0 };
  182. #if _WIN32_WINNT >= 0x0400 & defined(_ATL_FREE_THREADED)
  183. hr = _Module.RegisterClassObjects(CLSCTX_LOCAL_SERVER,
  184. REGCLS_MULTIPLEUSE | REGCLS_SUSPENDED);
  185. _ASSERTE(SUCCEEDED(hRes));
  186. hr = CoResumeClassObjects();
  187. #else
  188. // we're using apartment threading model
  189. hr = _Module.RegisterClassObjects(CLSCTX_LOCAL_SERVER,
  190. REGCLS_MULTIPLEUSE);
  191. #endif
  192. _ASSERTE(SUCCEEDED(hr));
  193. if ( !g_pRstrMgr->SetStartMode( nStart ) )
  194. {
  195. nRet = E_FAIL;
  196. goto Exit;
  197. }
  198. //if ( g_cRestoreShell.Create( NULL, rc ) == NULL )
  199. //{
  200. // nRet = E_FAIL;
  201. // goto Exit;
  202. //}
  203. nRet = InvokeMARS( szTitle );
  204. if ( nRet != 0 )
  205. goto Exit;
  206. _Module.RevokeClassObjects();
  207. Exit:
  208. TraceFunctLeave();
  209. return( nRet );
  210. }
  211. /////////////////////////////////////////////////////////////////////////////
  212. // CSRFrameMars operations - internal
  213. BOOL CSRFrameMars::CleanUp()
  214. {
  215. return( TRUE );
  216. }
  217. DWORD CSRFrameMars::InvokeMARS( LPCWSTR szTitle )
  218. {
  219. TraceFunctEnter("CSRFrameMars::InvokeMARS");
  220. DWORD dwRet = 0;
  221. LPCWSTR cszErr;
  222. WCHAR szMarsPath[MAX_PATH+1];
  223. WCHAR szSRPath[MAX_PATH+1];
  224. HMODULE hMars;
  225. PFNMARSTHREADPROC pfnMarsThreadProc;
  226. MARSTHREADPARAM sMTP;
  227. WCHAR szMainWndTitle[MAX_PATH+1];
  228. CComBSTR bstrTitle, bstrSRPath;
  229. CSRMarsHost_Object *pMH = NULL;
  230. HRESULT hr;
  231. ::GetWindowsDirectory( szMarsPath, MAX_PATH );
  232. ::lstrcat( szMarsPath, L"\\pchealth\\helpctr\\binaries\\pchshell.dll" );
  233. hMars = ::LoadLibrary( szMarsPath );
  234. if ( hMars == NULL )
  235. {
  236. #ifdef DEBUG
  237. MessageBox( NULL, szMarsPath, L"LoadLibrary failed", MB_OK );
  238. #endif
  239. dwRet = ::GetLastError();
  240. cszErr = ::GetSysErrStr( dwRet );
  241. ErrorTrace(TRACE_ID, "::LoadLibrary('marscore.dll') failed - %s", cszErr);
  242. goto Exit;
  243. }
  244. pfnMarsThreadProc = (PFNMARSTHREADPROC)::GetProcAddress( hMars, (LPCSTR)MAKEINTRESOURCE(ORD_MARSTHREADPROC) );
  245. if ( pfnMarsThreadProc == NULL )
  246. {
  247. #ifdef DEBUG
  248. MessageBox( NULL, L"Unknown", L"GetProcAddress failed", MB_OK );
  249. #endif
  250. dwRet = ::GetLastError();
  251. cszErr = ::GetSysErrStr( dwRet );
  252. ErrorTrace(TRACE_ID, "::GetProcAddress failed - %s", cszErr);
  253. goto Exit;
  254. }
  255. bstrTitle = szTitle;
  256. ::GetModuleFileName( NULL, szSRPath, MAX_PATH );
  257. ::PathRemoveFileSpec( szSRPath );
  258. ::PathAppend( szSRPath, L"srframe.mmf" );
  259. bstrSRPath = szSRPath;
  260. ::ZeroMemory( &sMTP, sizeof(sMTP) );
  261. sMTP.cbSize = sizeof(sMTP);
  262. sMTP.hIcon = NULL;
  263. sMTP.nCmdShow = SW_HIDE;
  264. sMTP.dwFlags = MTF_MANAGE_WINDOW_SIZE;
  265. sMTP.pwszTitle = bstrTitle;
  266. sMTP.pwszPanelURL = bstrSRPath;
  267. // Create an UI Instance.
  268. hr = CSRMarsHost_Object::CreateInstance( &pMH );
  269. if ( FAILED(hr) )
  270. {
  271. #ifdef DEBUG
  272. MessageBox( NULL, szMarsPath, L"CreateInstance of MarsHost failed", MB_OK );
  273. #endif
  274. dwRet = hr;
  275. ErrorTrace(TRACE_ID, "CHCPMarsHost_Object::CreateInstance failed, hr=%u", hr);
  276. goto Exit;
  277. }
  278. //
  279. // Add a reference count
  280. //
  281. pMH->AddRef();
  282. dwRet = pfnMarsThreadProc( pMH, &sMTP );
  283. if ( pMH )
  284. pMH->Release();
  285. if ( hMars )
  286. ::FreeLibrary( hMars );
  287. Exit:
  288. TraceFunctLeave();
  289. return( dwRet );
  290. }
  291. // end of file