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.

444 lines
9.2 KiB

  1. /*++
  2. Copyright (c) 2002 Microsoft Corporation
  3. Module Name :
  4. complus.hxx
  5. Abstract:
  6. Classes that are used to activate the COM+ and
  7. DTC components
  8. Author:
  9. Christopher Achille (cachille)
  10. Project:
  11. Internet Services Setup
  12. Revision History:
  13. April 2002: Created
  14. --*/
  15. #include "stdafx.h"
  16. #include "complus.hxx"
  17. // Constructor
  18. //
  19. CCOMPlusInstallComponent::CCOMPlusInstallComponent():
  20. m_hComSetupDll( NULL )
  21. {
  22. }
  23. // Destructor
  24. //
  25. CCOMPlusInstallComponent::~CCOMPlusInstallComponent()
  26. {
  27. if ( m_hComSetupDll == NULL )
  28. {
  29. // Free the library
  30. DBG_REQUIRE( m_hComSetupDll );
  31. }
  32. }
  33. // InitializeComSetupDll
  34. //
  35. // Initialize the Com Setup Dll
  36. // This loads the dll, so that we can call the exported functions
  37. // by it.
  38. //
  39. BOOL
  40. CCOMPlusInstallComponent::InitializeComSetupDll()
  41. {
  42. TSTR_PATH strPath;
  43. if ( m_hComSetupDll != NULL )
  44. {
  45. // Since this is already opened, lets return true
  46. return TRUE;
  47. }
  48. if ( !strPath.RetrieveSystemDir() ||
  49. !strPath.PathAppend( STRING_SETUPFILES_LOCATION ) ||
  50. !strPath.PathAppend( STRING_COMPLUS_SETUPDLL ) )
  51. {
  52. // Log the error
  53. iisDebugOut( ( LOG_TYPE_ERROR,
  54. _T("COMPlus setup, failed to construct path\n") ) );
  55. return FALSE;
  56. }
  57. m_hComSetupDll = LoadLibrary( strPath.QueryStr() );
  58. if ( m_hComSetupDll == NULL )
  59. {
  60. // Log the error
  61. iisDebugOut( ( LOG_TYPE_ERROR,
  62. _T("COMPlus setup, failed to LoadLibrary on '%s'\n"),
  63. STRING_COMPLUS_SETUPDLL ) );
  64. }
  65. return ( m_hComSetupDll != NULL );
  66. }
  67. // InstallComponent
  68. //
  69. // Install or Uninstall the Component
  70. //
  71. // Parameters:
  72. // bInstall - TRUE == Install
  73. // FALSE == Uninstall
  74. //
  75. BOOL
  76. CCOMPlusInstallComponent::InstallComponent( BOOL bInstall )
  77. {
  78. pComDtc_Set pfnInstall = NULL;
  79. HRESULT hr;
  80. if ( !InitializeComSetupDll() )
  81. {
  82. // Failed to initialize, bail
  83. return FALSE;
  84. }
  85. pfnInstall = (pComDtc_Set) GetProcAddress(m_hComSetupDll,
  86. STRING_COM_INSTALLFUNCTION );
  87. if ( pfnInstall == NULL )
  88. {
  89. // Log the error
  90. iisDebugOut( ( LOG_TYPE_ERROR,
  91. _T("COMPlus Install/Uninstall call failed, could not find exported function. GLE=0x%8x\n"),
  92. GetLastError() ) );
  93. return FALSE;
  94. }
  95. hr = pfnInstall( bInstall ? TRUE : FALSE );
  96. if ( FAILED( hr ) )
  97. {
  98. // Log the error
  99. iisDebugOut( ( LOG_TYPE_ERROR,
  100. _T("COMPlus Install/Uninstall call failed, hr=0x%8x\n"),
  101. hr ) );
  102. }
  103. return ( SUCCEEDED( hr ) );
  104. }
  105. // Install
  106. //
  107. // Install the COM+ Component
  108. //
  109. BOOL
  110. CCOMPlusInstallComponent::Install()
  111. {
  112. return InstallComponent( TRUE );
  113. }
  114. // PostUnInstall
  115. //
  116. // UnInstall the COM+ Component
  117. // This must be done in OC_COMPLETE, so we are doing it in PostUninstall
  118. //
  119. BOOL
  120. CCOMPlusInstallComponent::PostUnInstall()
  121. {
  122. return InstallComponent( FALSE );
  123. }
  124. // IsInstalled
  125. //
  126. // Return if COM+ is installed
  127. //
  128. BOOL
  129. CCOMPlusInstallComponent::IsInstalled( LPBOOL pbIsInstalled )
  130. {
  131. pComDtc_Get pfnIsInstalled = NULL;
  132. HRESULT hr;
  133. ASSERT( pbIsInstalled );
  134. if ( !InitializeComSetupDll() )
  135. {
  136. // Failed to initialize, bail
  137. return FALSE;
  138. }
  139. pfnIsInstalled = (pComDtc_Get) GetProcAddress(m_hComSetupDll,
  140. STRING_COM_ISINSTALLEDFUNCTION );
  141. if ( pfnIsInstalled == NULL )
  142. {
  143. // Log the error
  144. iisDebugOut( ( LOG_TYPE_ERROR,
  145. _T("COMPlus IsInstalled call failed, could not find exported function. GLE=0x%8x\n"),
  146. GetLastError() ) );
  147. return FALSE;
  148. }
  149. hr = pfnIsInstalled( &g_OCMInfo, pbIsInstalled );
  150. if ( FAILED( hr ) )
  151. {
  152. // Log the error
  153. iisDebugOut( ( LOG_TYPE_ERROR,
  154. _T("COMPlus Install/Uninstall call failed, hr=0x%8x\n"),
  155. hr ) );
  156. }
  157. return ( SUCCEEDED( hr ) );
  158. }
  159. // GetFriendlyName
  160. //
  161. // Retrieve the FriendlyName of the COM+ Component
  162. //
  163. BOOL
  164. CCOMPlusInstallComponent::GetFriendlyName( TSTR *pstrFriendlyName )
  165. {
  166. return pstrFriendlyName->LoadString( IDS_COMPLUS_COMPONETNAME );
  167. }
  168. // GetName
  169. //
  170. // Get the name of the component in the inf
  171. //
  172. LPTSTR
  173. CCOMPlusInstallComponent::GetName()
  174. {
  175. return g_ComponentList[ COMPONENT_COMPLUS ].szComponentName;
  176. }
  177. // GetSmallIcon
  178. //
  179. // Retrieve the small icon for this OCM component
  180. //
  181. BOOL
  182. CCOMPlusInstallComponent::GetSmallIcon( HBITMAP *phIcon )
  183. {
  184. *phIcon = LoadBitmap( (HINSTANCE) g_MyModuleHandle,
  185. MAKEINTRESOURCE( IDB_ICON_COMPLUS ));
  186. return ( *phIcon != NULL );
  187. }
  188. // Constructor
  189. //
  190. CDTCInstallComponent::CDTCInstallComponent():
  191. m_hDtcSetupDll( NULL )
  192. {
  193. }
  194. // Destructor
  195. //
  196. CDTCInstallComponent::~CDTCInstallComponent()
  197. {
  198. if ( m_hDtcSetupDll == NULL )
  199. {
  200. // Free the library
  201. DBG_REQUIRE( m_hDtcSetupDll != NULL );
  202. }
  203. }
  204. // InitializeComSetupDll
  205. //
  206. // Initialize the Com Setup Dll
  207. // This loads the dll, so that we can call the exported functions
  208. // by it.
  209. //
  210. BOOL
  211. CDTCInstallComponent::InitializeDtcSetupDll()
  212. {
  213. TSTR_PATH strPath;
  214. if ( m_hDtcSetupDll != NULL )
  215. {
  216. // Since this is already opened, lets return true
  217. return TRUE;
  218. }
  219. if ( !strPath.RetrieveSystemDir() ||
  220. !strPath.PathAppend( STRING_SETUPFILES_LOCATION ) ||
  221. !strPath.PathAppend( STRING_DTC_SETUPDLL ) )
  222. {
  223. // Log the error
  224. iisDebugOut( ( LOG_TYPE_ERROR,
  225. _T("DTC setup, failed to construct path\n") ) );
  226. return FALSE;
  227. }
  228. m_hDtcSetupDll = LoadLibrary( strPath.QueryStr() );
  229. if ( m_hDtcSetupDll == NULL )
  230. {
  231. // Log the error
  232. iisDebugOut((LOG_TYPE_ERROR,
  233. _T("DTC setup, failed to LoadLibrary on '%s'\n"),
  234. STRING_COMPLUS_SETUPDLL ) );
  235. }
  236. return ( m_hDtcSetupDll != NULL );
  237. }
  238. // InstallComponent
  239. //
  240. // Install or Uninstall the Component
  241. //
  242. // Parameters:
  243. // bInstall - TRUE == Install
  244. // FALSE == Uninstall
  245. //
  246. BOOL
  247. CDTCInstallComponent::InstallComponent( BOOL bInstall )
  248. {
  249. pComDtc_Set pfnInstall = NULL;
  250. HRESULT hr;
  251. iisDebugOut((LOG_TYPE_PROGRAM_FLOW, _T("Calling InstallComponent\n")));
  252. if ( !InitializeDtcSetupDll() )
  253. {
  254. // Failed to initialize, bail
  255. return FALSE;
  256. }
  257. pfnInstall = (pComDtc_Set) GetProcAddress(m_hDtcSetupDll,
  258. STRING_DTC_INSTALLFUNCTION );
  259. if ( pfnInstall == NULL )
  260. {
  261. // Log the error
  262. iisDebugOut( ( LOG_TYPE_ERROR,
  263. _T("DTC Install/Uninstall call failed, could not find exported function. GLE=0x%8x\n"),
  264. GetLastError() ) );
  265. return FALSE;
  266. }
  267. hr = pfnInstall( bInstall ? TRUE : FALSE );
  268. if ( FAILED( hr ) )
  269. {
  270. // Log the error
  271. iisDebugOut( ( LOG_TYPE_ERROR,
  272. _T("DTC Install/Uninstall call failed, hr=0x%8x\n"),
  273. hr ) );
  274. }
  275. return ( SUCCEEDED( hr ) );
  276. }
  277. // Install
  278. //
  279. // Install the COM+ Component
  280. //
  281. BOOL
  282. CDTCInstallComponent::Install()
  283. {
  284. return InstallComponent( TRUE );
  285. }
  286. // PostUnInstall
  287. //
  288. // UnInstall the COM+ Component
  289. // Because this needs to be done in OC_COMPLETE, we do it in
  290. // PostUnInstall
  291. //
  292. BOOL
  293. CDTCInstallComponent::PostUnInstall()
  294. {
  295. return InstallComponent( FALSE );
  296. }
  297. // IsInstalled
  298. //
  299. // Return if DTC is installed
  300. //
  301. BOOL
  302. CDTCInstallComponent::IsInstalled( LPBOOL pbIsInstalled )
  303. {
  304. pComDtc_Get pfnIsInstalled = NULL;
  305. HRESULT hr;
  306. ASSERT( pbIsInstalled );
  307. if ( !InitializeDtcSetupDll() )
  308. {
  309. // Failed to initialize, bail
  310. return FALSE;
  311. }
  312. pfnIsInstalled = (pComDtc_Get) GetProcAddress(m_hDtcSetupDll,
  313. STRING_DTC_ISINSTALLEDFUNCTION );
  314. if ( pfnIsInstalled == NULL )
  315. {
  316. // Log the error
  317. iisDebugOut( ( LOG_TYPE_ERROR,
  318. _T("DTC IsInstalled call failed, could not find exported function. GLE=0x%8x\n"),
  319. GetLastError() ) );
  320. return FALSE;
  321. }
  322. hr = pfnIsInstalled( &g_OCMInfo, pbIsInstalled );
  323. if ( FAILED( hr ) )
  324. {
  325. // Log the error
  326. iisDebugOut( ( LOG_TYPE_ERROR,
  327. _T("DTC Install/Uninstall call failed, hr=0x%8x\n"),
  328. hr ) );
  329. }
  330. return ( SUCCEEDED( hr ) );
  331. }
  332. // GetFriendlyName
  333. //
  334. // Retrieve the FriendlyName of the DTC Component
  335. //
  336. BOOL
  337. CDTCInstallComponent::GetFriendlyName( TSTR *pstrFriendlyName )
  338. {
  339. return pstrFriendlyName->LoadString( IDS_DTC_COMPONETNAME );
  340. }
  341. // GetName
  342. //
  343. // Get the name of the component in the inf
  344. //
  345. LPTSTR
  346. CDTCInstallComponent::GetName()
  347. {
  348. return g_ComponentList[ COMPONENT_DTC ].szComponentName;
  349. }
  350. // GetSmallIcon
  351. //
  352. // Retrieve the small icon for this OCM component
  353. //
  354. BOOL
  355. CDTCInstallComponent::GetSmallIcon( HBITMAP *phIcon )
  356. {
  357. *phIcon = LoadBitmap( (HINSTANCE) g_MyModuleHandle,
  358. MAKEINTRESOURCE( IDB_ICON_DTC ));
  359. return ( *phIcon != NULL );
  360. }