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.

137 lines
2.9 KiB

  1. #include <nt.h>
  2. #include <ntrtl.h>
  3. #include <nturtl.h>
  4. #include <windows.h>
  5. #include <objbase.h>
  6. #include <stdio.h>
  7. #include <msiquery.h>
  8. typedef HRESULT (*CallFunc)( void );
  9. UINT RegisterDLL( MSIHANDLE hInstall, const char *DllName )
  10. {
  11. #if 0
  12. CHAR DbgMessage[ MAX_PATH ];
  13. sprintf( DbgMessage, "ProcessId %u, ThreadId %u", GetCurrentProcessId(), GetCurrentThreadId() );
  14. MessageBoxA( NULL, DbgMessage, NULL, MB_OK );
  15. #endif
  16. ASSERT( MsiGetMode( hInstall, MSIRUNMODE_SCHEDULED ) ||
  17. MsiGetMode( hInstall, MSIRUNMODE_ROLLBACK ) );
  18. HRESULT CoInitHr;
  19. CoInitHr = CoInitialize( NULL );
  20. if ( FAILED( CoInitHr ) && ( RPC_E_CHANGED_MODE != CoInitHr ) )
  21. return (UINT)CoInitHr;
  22. HMODULE hModule = NULL;
  23. HRESULT Hr = S_OK;
  24. hModule = LoadLibrary( DllName );
  25. if ( !hModule )
  26. {
  27. Hr = HRESULT_FROM_WIN32( GetLastError() );
  28. goto exit;
  29. }
  30. CallFunc RegisterFunc = (CallFunc)GetProcAddress( hModule, "DllRegisterServer" );
  31. Hr = (*RegisterFunc)();
  32. FreeLibrary( hModule );
  33. hModule = NULL;
  34. exit:
  35. if ( RPC_E_CHANGED_MODE != CoInitHr )
  36. CoUninitialize();
  37. SetLastError( Hr );
  38. return SUCCEEDED(Hr) ? ERROR_SUCCESS : ERROR_INSTALL_FAILURE;
  39. }
  40. UINT UnregisterDLL( MSIHANDLE hInstall, char *DllName )
  41. {
  42. ASSERT( MsiGetMode( hInstall, MSIRUNMODE_SCHEDULED ) ||
  43. MsiGetMode( hInstall, MSIRUNMODE_ROLLBACK ) );
  44. HRESULT CoInitHr;
  45. CoInitHr = CoInitialize( NULL );
  46. if ( FAILED( CoInitHr ) && ( RPC_E_CHANGED_MODE != CoInitHr ) )
  47. return (UINT)CoInitHr;
  48. HMODULE hModule = NULL;
  49. HRESULT Hr = S_OK;
  50. hModule = LoadLibrary( DllName );
  51. if ( !hModule )
  52. {
  53. DbgPrint( "Unable to load %s, error 0x%8.8X", DllName, GetLastError() );
  54. }
  55. else
  56. {
  57. CallFunc RegisterFunc = (CallFunc)GetProcAddress( hModule, "DllUnregisterServer" );
  58. if ( !RegisterFunc )
  59. {
  60. DbgPrint( "Unable to load %s!DllRegisterServer, error 0x%8.8X", DllName, GetLastError() );
  61. }
  62. else
  63. {
  64. Hr = (*RegisterFunc)();
  65. FreeLibrary( hModule );
  66. hModule = NULL;
  67. if ( FAILED( Hr ) )
  68. goto exit;
  69. }
  70. }
  71. FreeLibrary( hModule );
  72. hModule = NULL;
  73. exit:
  74. if ( RPC_E_CHANGED_MODE == CoInitHr )
  75. return Hr;
  76. CoUninitialize();
  77. return SUCCEEDED(Hr) ? ERROR_SUCCESS : ERROR_INSTALL_FAILURE;
  78. }
  79. UINT DllInstallBITSMgr( MSIHANDLE hInstall )
  80. {
  81. return RegisterDLL( hInstall, "bitsmgr.dll" );
  82. }
  83. UINT DllUninstallBITSMgr( MSIHANDLE hInstall )
  84. {
  85. return UnregisterDLL( hInstall, "bitsmgr.dll" );
  86. }
  87. UINT DllInstallBITSIsapi( MSIHANDLE hInstall )
  88. {
  89. return RegisterDLL( hInstall, "bitssrv.dll" );
  90. }
  91. UINT DllUninstallBITSIsapi( MSIHANDLE hInstall )
  92. {
  93. return UnregisterDLL( hInstall, "bitssrv.dll" );
  94. }