How to use a 32 bit COM object on Windows Server 2

2019-01-23 20:46发布

问题:

I am using the default DllSurrogate to enable automation of a 32bit COM object in 64bit. This works perfectly in Windows7 64 bit and Windows Server 2008 R2. However; regular flavor Windows Server 2008 (pre R2) completely ignores the DllSurrogate entry in the registry. I've researched this for days and found documentation that classic Windows Server 2008 had registry reflection which ignores the DllSurrogate value if its blank. (I leave the value of the registry string blank to use the default Surrogate.) To work around this not-reflected (not copied between 32bit and 64bit registries), I run the regedit.exe*32 and set the keys. Then I open normal regedit and set the keys. Still no luck. I have also tried setting the DllSurrogate registry value to c:\windows\syswow64\dllhost.exe so that the value isn't blank but that doesn't work at all (on any OS). The error I receive is "cannot create activex object."

I have reproduced the problem on 2 different Windows Server 2008 (Pre R2) machines. I also verified that the COM object can be used on those machines when launched from a 32 bit app. I used LINQPad 32 bit and 64bit to test. LINQPad running as 32 bit can create the COM object. 64bit LINQPad cannot.

[link text][1] <-- Solution I am using (works on R2) http://msdn.microsoft.com/en-us/library/aa384253(VS.85).aspx <-- Documentation that DllSurrogate registry entry is not reflected on Windows Server 2008, but I don't know how to circumvent this limitation. I tried using regedit.exe*32 to edit the 32bit registry directly.

Any ideas what I am missing here? Is there some special trick to use the default DllSurrogate (dllhost.exe) on pre-R2? Rewriting our COM to .NET is not an option at the moment. I hope that I am just missing something as this does work on the latest Windows Server 2008 R2.

Thanks for taking a look! Danny

回答1:

Problem solved! Thanks Hans for setting me on the right track! I accidentally configured the system to use a 64-bit DLLHost.exe file, which didn't work since it couldn't launch a 32-bit COM object.

Start-to-finish, here is how I was able to use my 32-bit COM object from a 64-bit application.

  1. Register COM object with regedit*32 (c:\windows\syswow64\regedit)

  2. Make the following registry changes. Be sure to put this all under Wow6432Node so the 32-bit DLLHost will be used.

  3. Determine your COM object's GUID by searching for registry for classname. ie. Classname would be the value you pass to createobject, like CreateObject("classname").

  4. Locate existing key HKey_Classes_Root\Wow6432Node\CLSID\[GUID]. Add a new REG_SZ (string) Value called AppID with a the COM object GUID as the value.

  5. Add a new key HKey_Classes_Root\Wow6432Node\AppID\[GUID]. Under this new key, add a new REG_SZ (string) Value called DllSurrogate. Leave the value empty.

  6. If not already there, create new Key under HKey_Local_Machine\Software\Wow6432Node\Classes\AppID\[GUID]. If not already there, add a new REG_SZ (string) Value called DllSurrogate under this key. Leave the value empty.

Now when you create your COM object you should see DLLHost.exe*32 show up in task manager. Turn on the command-line column in task manager and you should see C:\windows\syswow64\dllhost.exe /processid:{YourCOMGUIDHere}