Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Registering a 32 bit DLL with 64 bit regsvr32

Tags:

c++

windows

rpc

com

Considering the following Understanding

  1. A 32 bit Process cannot load a 64 bit dll or vice versa.
  2. For registering/unregistering a DLL regsvr32 calls the entry point DllRegisterServer / DllUnregisterServer after loading the target DLL into its address space through LoadLIbrary.
  3. On a 64 bit System, 32 bit version of regsvr32 is present in 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?

enter image description here

The example I wanted to highlight in the screenshot was the last for which the Dialog pops up.

like image 991
Abhijit Avatar asked Sep 21 '13 16:09

Abhijit


People also ask

How do I register a DLL with regsvr32?

Click Start > All Programs > Accessories and right-click on "Command Prompt" and select "Run as Administrator" OR in the Search box, type CMD and when cmd.exe appears in your results, right-click on cmd.exe and select "Run as administrator" At the command prompt, enter: REGSVR32 "PATH TO THE DLL FILE"


2 Answers

This should explain how it happens exactly:


(source: 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.

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.

like image 175
Roman R. Avatar answered Oct 20 '22 10:10

Roman R.


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.

Couple of things to note

  1. The Command line for the 32 bit regsvr32 maps with the 32 bit DLL name I was trying to register
  2. The 32 bit Version of the regsvr32 is a child process of the 64 bit version of regsvr32
  3. The Image Type and the Path Column

enter image description here

like image 22
Abhijit Avatar answered Oct 20 '22 08:10

Abhijit