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.

326 lines
8.0 KiB

  1. /////////////////////////////////////////////////////////////////////////////
  2. //
  3. // Copyright (c) 1996-1999 Microsoft Corporation
  4. //
  5. // Module Name:
  6. // RegCOMObj.cpp
  7. //
  8. // Abstract:
  9. // The functions in this file are used to register and unregister the COM
  10. // objects used by Cluster Server.
  11. //
  12. // Author:
  13. // C. Brent Thomas (a-brentt) April 1 1998
  14. //
  15. // Revision History:
  16. //
  17. // Notes:
  18. //
  19. /////////////////////////////////////////////////////////////////////////////
  20. #include <stdio.h>
  21. #include <stdlib.h>
  22. #include <windows.h>
  23. #include <winerror.h>
  24. #include <tchar.h>
  25. #include "SetupCommonLibRes.h"
  26. typedef HRESULT (*PFDLLREGISTERSERVER)(void);
  27. /////////////////////////////////////////////////////////////////////////////
  28. //++
  29. //
  30. // RegisterCOMObject
  31. //
  32. // Routine Description:
  33. // This function attempts to register a COM object.
  34. //
  35. // Arguments:
  36. // ptszCOMObjectFileName - points to the name of the COM object file.
  37. // ptszPathToCOMObject - points to the location of the COM object.
  38. //
  39. //
  40. // Return Value:
  41. // ERROR_SUCCESS - indicated success
  42. // Any other value is an NT error code retrunde by GetLastError()
  43. //
  44. //--
  45. /////////////////////////////////////////////////////////////////////////////
  46. DWORD RegisterCOMObject( LPCTSTR ptszCOMObjectFileName,
  47. LPCTSTR ptszPathToCOMObject )
  48. {
  49. DWORD dwStatus;
  50. HINSTANCE hLib = NULL;
  51. TCHAR tszComObjFileName[_MAX_PATH];
  52. LPSTR pszEntryPoint;
  53. PFDLLREGISTERSERVER pfnRegisterServer;
  54. // ASSERT(ptszCOMObjectFileName != NULL); BUGBUG
  55. // ASSERT(ptszPathToCOMObject != NULL);
  56. //
  57. // Construct the file name.
  58. //
  59. wsprintf( tszComObjFileName, TEXT("%s\\%s"), ptszPathToCOMObject, ptszCOMObjectFileName );
  60. //
  61. // Load the DLL.
  62. //
  63. hLib = LoadLibrary( tszComObjFileName );
  64. if ( hLib != NULL )
  65. {
  66. //
  67. // Get the DllRegisterServer entry point.
  68. //
  69. pfnRegisterServer = (PFDLLREGISTERSERVER) GetProcAddress( hLib,
  70. "DllRegisterServer" );
  71. if ( pfnRegisterServer != NULL )
  72. {
  73. //
  74. // Call the entry point.
  75. //
  76. dwStatus = (*pfnRegisterServer)();
  77. }
  78. else
  79. {
  80. dwStatus = GetLastError();
  81. }
  82. FreeLibrary( hLib );
  83. }
  84. else
  85. {
  86. dwStatus = GetLastError();
  87. }
  88. return ( dwStatus );
  89. } // RegisterCOMObject
  90. /////////////////////////////////////////////////////////////////////////////
  91. //++
  92. //
  93. // UnRegisterCOMObject
  94. //
  95. // Routine Description:
  96. // This function attempts to unregister a COM object.
  97. //
  98. // Arguments:
  99. // ptszCOMObjectFileName - points to the name of the COM object file.
  100. // ptszPathToCOMObject - points to the location of the COM object.
  101. //
  102. //
  103. // Return Value:
  104. // ERROR_SUCCESS - indicated success
  105. // Any other value is an NT error code retrunde by GetLastError()
  106. //
  107. //--
  108. /////////////////////////////////////////////////////////////////////////////
  109. DWORD UnRegisterCOMObject( LPCTSTR ptszCOMObjectFileName,
  110. LPCTSTR ptszPathToCOMObject )
  111. {
  112. DWORD dwStatus;
  113. HINSTANCE hLib = NULL;
  114. TCHAR tszComObjFileName[_MAX_PATH];
  115. LPSTR pszEntryPoint;
  116. PFDLLREGISTERSERVER pfnRegisterServer;
  117. // ASSERT(ptszCOMObjectFileName != NULL); BUGBUG
  118. // ASSERT(ptszPathToCOMObject != NULL);
  119. //
  120. // Construct the file name.
  121. //
  122. wsprintf( tszComObjFileName, TEXT("%s\\%s"), ptszPathToCOMObject, ptszCOMObjectFileName );
  123. //
  124. // Load the DLL.
  125. //
  126. hLib = LoadLibrary( tszComObjFileName );
  127. if ( hLib != NULL )
  128. {
  129. //
  130. // Get the DllRegisterServer entry point.
  131. //
  132. pfnRegisterServer = (PFDLLREGISTERSERVER) GetProcAddress( hLib,
  133. "DllUnregisterServer" );
  134. if ( pfnRegisterServer != NULL )
  135. {
  136. //
  137. // Call the entry point.
  138. //
  139. dwStatus = (*pfnRegisterServer)();
  140. }
  141. else
  142. {
  143. dwStatus = GetLastError();
  144. }
  145. FreeLibrary( hLib );
  146. }
  147. else
  148. {
  149. dwStatus = GetLastError();
  150. }
  151. return ( dwStatus );
  152. } // UnRegisterCOMObject
  153. /////////////////////////////////////////////////////////////////////////////
  154. //++
  155. //
  156. // UnRegisterClusterCOMObjects
  157. //
  158. // Routine Description:
  159. // This function unregisters the COM objects that are components of Cluster
  160. // Server.
  161. //
  162. // Arguments:
  163. // hWnd - the handle to the parent window.
  164. // ptszPathToCOMObject - points to the location of the COM objects to be
  165. // unregistered..
  166. //
  167. // Return Value:
  168. // (BOOL) TRUE - indicates success
  169. // (BOOL) FALSE - indicates that an error was encountered
  170. //
  171. //--
  172. /////////////////////////////////////////////////////////////////////////////
  173. BOOL UnRegisterClusterCOMObjects( HINSTANCE hInstance,
  174. LPCTSTR ptszPathToCOMObject )
  175. {
  176. BOOL fReturnValue = (BOOL) TRUE;
  177. DWORD dwURCORv;
  178. TCHAR tszMessage[256]; // arbitrary size
  179. TCHAR tszFormatString[256];
  180. //
  181. // Unregister CluAdMMC.
  182. //
  183. dwURCORv = UnRegisterCOMObject( TEXT("CluAdMMC.dll"), ptszPathToCOMObject );
  184. if ( (dwURCORv != (DWORD) ERROR_SUCCESS) && (dwURCORv != (DWORD) ERROR_MOD_NOT_FOUND) )
  185. {
  186. if ( LoadString( hInstance, IDS_ERROR_UNREGISTERING_COM_OBJECT,
  187. tszFormatString, 256 ) > 0 )
  188. {
  189. wsprintf( tszMessage, tszFormatString, dwURCORv, TEXT("CluAdMMC.dll") );
  190. MessageBox( NULL, tszMessage, NULL, MB_OK | MB_ICONEXCLAMATION );
  191. } // Did LoadString succeed?
  192. fReturnValue = (BOOL) FALSE;
  193. }
  194. //
  195. // Unregister ClAdmWiz.
  196. //
  197. dwURCORv = UnRegisterCOMObject( TEXT("ClAdmWiz.dll"), ptszPathToCOMObject );
  198. if ( (dwURCORv != (DWORD) ERROR_SUCCESS) && (dwURCORv != (DWORD) ERROR_MOD_NOT_FOUND) )
  199. {
  200. if ( LoadString( hInstance, IDS_ERROR_UNREGISTERING_COM_OBJECT,
  201. tszFormatString, 256 ) > 0 )
  202. {
  203. wsprintf( tszMessage, tszFormatString, dwURCORv, TEXT("ClAdmWiz.dll") );
  204. MessageBox( NULL, tszMessage, NULL, MB_OK | MB_ICONEXCLAMATION );
  205. } // Did LoadString succeed?
  206. fReturnValue = (BOOL) FALSE;
  207. }
  208. //
  209. // Unregister IISClEx3.
  210. //
  211. dwURCORv = UnRegisterCOMObject( TEXT("IISClEx3.dll"), ptszPathToCOMObject );
  212. if ( (dwURCORv != (DWORD) ERROR_SUCCESS) && (dwURCORv != (DWORD) ERROR_MOD_NOT_FOUND) )
  213. {
  214. if ( LoadString( hInstance, IDS_ERROR_UNREGISTERING_COM_OBJECT,
  215. tszFormatString, 256 ) > 0 )
  216. {
  217. wsprintf( tszMessage, tszFormatString, dwURCORv, TEXT("IISClEx3.dll") );
  218. MessageBox( NULL, tszMessage, NULL, MB_OK | MB_ICONEXCLAMATION );
  219. } // Did LoadString succeed?
  220. fReturnValue = (BOOL) FALSE;
  221. }
  222. //
  223. // Unregister ClNetREx.
  224. //
  225. dwURCORv = UnRegisterCOMObject( TEXT("ClNetREx.dll"), ptszPathToCOMObject );
  226. if ( (dwURCORv != (DWORD) ERROR_SUCCESS) && (dwURCORv != (DWORD) ERROR_MOD_NOT_FOUND) )
  227. {
  228. if ( LoadString( hInstance, IDS_ERROR_UNREGISTERING_COM_OBJECT,
  229. tszFormatString, 256 ) > 0 )
  230. {
  231. wsprintf( tszMessage, tszFormatString, dwURCORv, TEXT("ClNetREx.dll") );
  232. MessageBox( NULL, tszMessage, NULL, MB_OK | MB_ICONEXCLAMATION );
  233. } // Did LoadString succeed?
  234. fReturnValue = (BOOL) FALSE;
  235. }
  236. //
  237. // Unregister CluAdmEx.
  238. //
  239. dwURCORv = UnRegisterCOMObject( TEXT("CluAdmEx.dll"), ptszPathToCOMObject );
  240. if ( (dwURCORv != (DWORD) ERROR_SUCCESS) && (dwURCORv != (DWORD) ERROR_MOD_NOT_FOUND) )
  241. {
  242. if ( LoadString( hInstance, IDS_ERROR_UNREGISTERING_COM_OBJECT,
  243. tszFormatString, 256 ) > 0 )
  244. {
  245. wsprintf( tszMessage, tszFormatString, dwURCORv, TEXT("CluAdmEx.dll") );
  246. MessageBox( NULL, tszMessage, NULL, MB_OK | MB_ICONEXCLAMATION );
  247. } // Did LoadString succeed?
  248. fReturnValue = (BOOL) FALSE;
  249. }
  250. return ( fReturnValue );
  251. }