在HKEY_CURRENT_USER中注册代理/存根 [英] Register a proxy/stub in HKEY_CURRENT_USER
问题描述
MIDL编译器使用写入HKEY_LOCAL_MACHINE的注册例程为代理/存根生成代码.有什么办法(最好是不破解MIDL生成的代码,又不绕过所有生成的代码,而使用自定义代码)在HKEY_CURRENT_USER中注册MIDL生成的p/s?
The MIDL compiler generates code for a proxy/stub with registration routines that write to HKEY_LOCAL_MACHINE. Is there any way (preferably without hacking the MIDL-generated code and without bypassing all that generated code in favor of custom code) to register a MIDL-generated p/s in HKEY_CURRENT_USER?
另外:如果p/s和COM服务器都是按用户注册的,则这样可以工作吗?我刚刚发现(经过非常令人沮丧的48小时之后),如果按用户注册COM服务器,则在整个机器上注册的P/S将无法正常工作.具体来说,在这种情况下,p/s的异步调用逻辑(ICallFactory :: CreateCall)将失败.
Also: Will this work if both the p/s and the COM server are registered per-user like this? I just found (after a very frustrating 48 hours) that a p/s registered machine-wide will not work correctly if the COM server is registered per-user. Specifically, the asynchronous call logic (ICallFactory::CreateCall) of the p/s will fail under these circumstances.
推荐答案
使用RegOverridePredefKey是正确的答案.然后注册:
Using RegOverridePredefKey is the right answer. Then register with:
regsvr32 /n /i:user C:\src\myCode.dll
使用"/i:user",regsvr32将您的"DllInstall"称为"DllInstall".功能而不是DllRegisterServer.
With "/i:user", regsvr32 calls your the "DllInstall" function instead of DllRegisterServer.
DllInstall的示例实现:
Example implementation of DllInstall:
extern "C" STDAPI DllInstall(BOOL bInstall, _In_opt_ LPCWSTR pszCmdLine)
{
HRESULT hr = E_FAIL;
static const wchar_t szUserSwitch[] = L"user";
if (pszCmdLine != NULL)
{
if (_wcsnicmp(pszCmdLine, szUserSwitch, _countof(szUserSwitch)) == 0)
{
ATL::AtlSetPerUserRegistration(true); // is this really needed??
}
}
LSTATUS status = RegCreateKeyEx(HKEY_CURRENT_USER, L"SOFTWARE\\Classes", 0, 0, REG_OPTION_NON_VOLATILE, KEY_ALL_ACCESS, 0, &hkcu_classes, &disposition);
if (status == ERROR_SUCCESS)
{
status = RegOverridePredefKey(HKEY_CLASSES_ROOT, hkcu_classes);
}
hr = HRESULT_FROM_NT(status);
if (SUCCEEDED(hr))
{
if (bInstall)
{
hr = DllRegisterServer();
if (FAILED(hr))
{
DllUnregisterServer();
}
}
else
{
hr = DllUnregisterServer();
}
}
}
这篇关于在HKEY_CURRENT_USER中注册代理/存根的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!