22 October, 2012

How RegSvr32 works on x64?

File system redirection works in x64 OS. It means that when you are 32-bits application and try to run %WinDir%\System32\RegSvr32.exe, you run %WinDir%\SysWOW64\RegSvr32.exe in fact. It's very good for compatibility. However, there is the problem when you want to register 64-bits COM DLL from 32-bits process: 32-bits process can't work with 64-bits DLL.

RegSvr32 do the special work to solve this problem. It detects that it works in WOW64 mode and DLL is 64-bit then ... it disable file system redirection for current thread by the Wow64EnableWow64FsRedirection() call and run itself (the command line contains original path: %WinDir%\System32\RegSvr32.exe) with the same arguments. Ta-da... It's beautiful decision!

Update: However, run itself in 64-bits mode will be skipped when 32-bits application loads 64-bits DLL by LoadLibraryEx() call and get the non-right error code - only the ERROR_BAD_EXE_FORMAT (0xC1) error code is expected.

No comments: