C++ 使用 64 位 regsvr32 注册 32 位 DLL
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/18935163/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
Registering a 32 bit DLL with 64 bit regsvr32
提问by Abhijit
Considering the following Understanding
考虑以下理解
- A 32 bit Process cannot load a 64 bit dll or vice versa.
- For registering/unregistering a DLL
regsvr32
calls the entry pointDllRegisterServer
/DllUnregisterServer
after loading the target DLL into its address space throughLoadLIbrary
. - On a 64 bit System, 32 bit version of regsvr32 is present in
C:\Windows\SysWOW64
- 32 位进程无法加载 64 位 dll,反之亦然。
- 对于注册/取消注册 DLL
regsvr32
调用入口点DllRegisterServer
/DllUnregisterServer
在将目标 DLL 通过LoadLIbrary
. - 在 64 位系统上,32 位版本的 regsvr32 存在于
C:\Windows\SysWOW64
But then on my 2008 R2 Box, I was able to register a 32 bit dll by the 64 bit regsvr32. How was that possible? Am I missing something?
但是后来在我的 2008 R2 Box 上,我能够通过 64 位 regsvr32 注册一个 32 位 dll。那怎么可能?我错过了什么吗?
The example I wanted to highlight in the screenshot was the last for which the Dialog pops up.
我想在屏幕截图中突出显示的示例是对话框弹出的最后一个示例。
采纳答案by Roman R.
This should explain how it happens exactly:
这应该解释它究竟是如何发生的:
(source: alax.info)
(来源:alax.info)
regsvr32
will start it's another bitness twin internally to match the bitness of the DLL. This is how registration succeeds. You don't need to care whether you start 32-bit or 64-bit version of regsvr32
because it will take care of mismatch.
regsvr32
将在内部启动它的另一个位双胞胎以匹配 DLL 的位。这样注册就成功了。您无需关心是启动 32 位还是 64 位版本,regsvr32
因为它会处理不匹配问题。
The scenario when you need to care is when you start regsvr32
from Visual Studio as debugging host. You want correct bitness there, because child process with actual registration will run outside of debugger and you won't be able to step your code through.
需要注意的情况是regsvr32
从 Visual Studio启动作为调试主机。您需要正确的位数,因为具有实际注册的子进程将在调试器之外运行,您将无法单步执行代码。
回答by Abhijit
It seems Mats and my assumption were correct. MS have re-engineered the 64 bit regsvr32 so that based on the target dll bitness it may spawn up a new 32 bit regsvr32 process from %SYSWOW64% to register the DLL. To prove this point, I fired up procexp, spied on the pop up Window for the 32 bit DLL and here was what showed up.
Mats 和我的假设似乎是正确的。MS 重新设计了 64 位 regsvr32,以便根据目标 dll 位数,它可能会从 %SYSWOW64% 生成一个新的 32 位 regsvr32 进程来注册 DLL。为了证明这一点,我启动了 procexp,监视 32 位 DLL 的弹出窗口,这是显示的内容。
Couple of things to note
需要注意的几件事
- The Command line for the 32 bit regsvr32 maps with the 32 bit DLL name I was trying to register
- The 32 bit Version of the regsvr32 is a child process of the 64 bit version of regsvr32
- The Image Type and the Path Column
- 32 位 regsvr32 的命令行映射了我试图注册的 32 位 DLL 名称
- regsvr32的32位版本是regsvr32的64位版本的子进程
- 图像类型和路径列