2012-06-12 90 views
2

要註冊COM服務器,我們運行像在升高的模式:RegSvr32.exe的/ n和/ i參數有什麼不同?

regsvr32.exe com.dll 

要執行每個用戶註冊,執行在用戶帳戶:

regsvr32.exe /n /i:user com.dll 

regsvr32.exe的支持這些參數:

/u - Unregister server 
/i - Call DllInstall passing it an optional [cmdline]; when used with /u calls dll uninstall 
/n - do not call DllRegisterServer; this option must be used with /i 
/s – Silent; display no message boxes (added with Windows XP and Windows Vista) 

在Delphi中創建COM服務器時,這些方法被導出:

exports 
    DllGetClassObject, 
    DllCanUnloadNow, 
    DllRegisterServer, 
    DllUnregisterServer, 
    DllInstall; 

我注意到這些會發生:

  1. 「Regsvr32.exe的com.dll」 援引中的DllRegisterServer。
  2. 「regsvr32.exe/u com.dll」調用DllUnregisterServer。
  3. 「regsvr32.exe/n/i:user com.dll」調用DllInstall。
  4. 「regsvr32.exe/u/n/i:user com.dll」調用DllInstall。

我很迷惑參數/ n和/我以及DllUnregisterServer和DllInstall。有什麼不同嗎?

另外,爲什麼「/ u/n/i:user」調用Dllinstall?我注意到「HKEY_CURRENT_USER \ Software \ Classes」中的相應註冊表項被刪除。

+0

/n可*僅*與使用/ I,所以它不是 「之間」。 – 2012-06-12 03:42:36

+0

使用「/ n/i」而沒有參數(DllRegisterServer)有什麼不同?何時使用「/ n/i」以及何時不使用任何參數? –

+0

那麼,「什麼時候使用DllRegisterServer而不是(只)DllInstall」? – 2012-06-12 03:59:03

回答

5

The documentation for DllInstall()解釋的區別:

DllInstall僅用於應用程序的安裝和設置。它不應該由應用程序調用它 。它與 DllRegisterServer或DllUnregisterServer類似。與這些函數不同, DllInstall接受一個輸入字符串,該字符串可用於指定各種不同的操作。這允許基於任何適當的標準以多種方式將DLL安裝在 中。

要在regsvr32中使用DllInstall,請添加「/ i」標誌,後跟冒號 (:)和一個字符串。該字符串將作爲 pszCmdLine參數傳遞給DllInstall。如果省略冒號和字符串,pszCmdLine 將被設置爲NULL。以下示例將用於安裝 DLL。

REGSVR32/I: 「Install_1」 dllname.dll

DllInstall被調用, bInstall設置爲TRUE,pszCmdLine設置爲 「Install_1」。卸載 DLL,使用以下:

REGSVR32/U/I: 「Install_1」 dllname.dll

隨着 兩者的上述例子中,中的DllRegisterServer或DllUnregisterServer的 也將被調用。要僅調用DllInstall,請添加一個「/ n」標誌。

REGSVR32/N/I: 「Install_1」 dllname.dll

2

我的建議是隻跳過使用regsvr32.exe的根本 - 這是一樣容易,只是自己做的工作:

int register(char const *DllName) { 
     HMODULE library = LoadLibrary(DllName); 
     if (NULL == library) { 
       // unable to load DLL 
       // use GetLastError() to find out why. 
       return -1;  // or a value based on GetLastError() 
     } 
     STDAPI (*DllRegisterServer)(void); 
     DllRegisterServer = GetProcAddress(library, "DllRegisterServer"); 
     if (NULL == DllRegisterServer) { 
       // DLL probably isn't a control -- it doesn't contain a 
       // DllRegisterServer function. At this point, you might 
       // want to look for a DllInstall function instead. This is 
       // what RegSvr32 calls when invoked with '/i' 
       return -2; 
     } 
     int error; 
     if (NOERROR == (error=DllRegisterServer())) { 
       // It thinks it registered successfully. 
       return 0; 
     } 
     else 
       return error; 
} 

這個特殊的代碼調用DllRegisterServer,但它的瑣碎,它以參數化如您所願,請致電DllInstallDllUninstall等。這消除了什麼被調用時有任何問題,等等

+2

-1不回答提出的問題,可以回答的問題。 –

+0

@DavidHeffernan:你毫無疑問是對的 - 回答他問的問題比試圖真正幫助他更好。我應該永遠被踢出去做這樣一件可怕的事情。 –

+1

@JerryCoffin:你的回答對我也有幫助,雖然沒有直接回答這個問題。我也從你的答案中學習,通過使用編程技術而不是使用命令行來註冊dll。 –

相關問題