要注册COM服务器,我们运行类似高架方式:
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;
我注意到这些会发生:
- “Regsvr32.exe的com.dll” 援引中的DllRegisterServer。
- “Regsvr32.exe的/ U com.dll” 调用DllUnregisterServer的。
- “REGSVR32.EXE / N / I:用户com.dll” 调用DllInstall。
- “Regsvr32.exe的/ U / N / I:用户com.dll” 援引DllInstall。
我带参数/ N混淆和/ I以及DllUnregisterServer的和DllInstall。 有没有什么不同?
另外,为什么 “/ U / N / I:用户” 援引Dllinstall? 我注意到辗转在“HKEY_CURRENT_USER \ Software \ Classes下”对应的注册表项。
对于DllInstall()文档解释了区别:
DllInstall仅用于应用程序的安装和设置。 它不应该被应用程序调用。 这是目的中的DllRegisterServer或DllUnregisterServer的相似。 不同于这些功能,需要DllInstall可用于指定各种不同的动作的输入字符串。 这允许被安装在一个以上的方式一个DLL,基于作为适当的任何标准。
要使用REGSVR32使用DllInstall,添加“/我”标志后跟一个冒号(:)和一个字符串。 该字符串将传递给DllInstall作为pszCmdLine参数。 如果省略冒号和字符串,pszCmdLine将被设置为NULL。 下面的例子将被用于安装一个DLL。
REGSVR32 /我: “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
我的建议是只跳过使用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
,但它是微不足道的参数它打电话DllInstall
, DllUninstall
等,如你所愿。 这消除了什么被调用时等任何问题