Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Access x86 COM from x64 .NET

I have an x64 server which, since my libraries are compiled to AnyCPU, run under x64. We are needing to access a COM component which is registered under x86. I don't know enough about COM and my google searches are leading me nowhere.

Question: Can I use a symbolic registry link from x64 back to x86 for the COM component? Do I need to register the COM component under x64 as well? Can I (any statement here...) ?

Thanks.

like image 920
Craig Wilson Avatar asked Dec 11 '08 13:12

Craig Wilson


People also ask

Can you run x86 on x64?

WOW64 is the x86 emulator that allows 32-bit Windows-based applications to run seamlessly on 64-bit Windows. This allows for 32-bit (x86) Windows applications to run seamlessly in 64-bit (x64) Windows, as well as for 32-bit (x86) and 32-bit (ARM) Windows applications to run seamlessly in 64-bit (ARM64) Windows.

What is the difference between .NET x64 and x86?

It usually refers to x86 for 32 bit OS and x64 for system with 64 bit. Technically x86 simply refers to a family of processors and the instruction set they all use.

How do I choose between x86 and x64?

In the right pane, look at the System Type entry. For a 32-bit version operating system, it will say X86-based PC. For a 64-bit version, you'll see X64-based PC.

Is x86 64 the same as x64?

x86-64 (also known as x64, x86_64, AMD64, and Intel 64) is a 64-bit version of the x86 instruction set, first released in 1999. It introduced two new modes of operation, 64-bit mode and compatibility mode, along with a new 4-level paging mode.


3 Answers

If a component is running x64-native, it can't load a 32-bit COM server in-process, because it's the wrong sort of process. There are a couple of solutions possible:

  1. If you can, build a 64-bit version of the COM code (which would of course register itself in the 64-bit registry). This is the cleanest solution, but may not be possible if you don't have the code for the COM server.

  2. Run your .NET component as 32-bit x86, instead of x64. I assume you've already considered and rejected this one for some reason.

  3. Host the COM component out-of-process using the COM surrogate DLLhost.exe. This will make calls to the COM server much, much slower (they will now be interprocess Windows messages instead of native function calls), but is otherwise transparent (you don't have to do anything special).

    This probably won't be an option if the server requires a custom proxy-stub instead of using the normal oleaut32 one (very rare, though), since there won't be a 64-bit version of the proxy available. As long as it can use the ordinary OLE marshalling, you can just register it for surrogate activation.

like image 119
puetzk Avatar answered Oct 11 '22 22:10

puetzk


I have found this solution, Dealing with Legacy 32-bit Components in 64-bit Windows see in article :
• Converting a project type from in-process to out-of-process
• Using COM+ as a host (this work for me)
• Using dllhost as a surrogate host

like image 33
lsalamon Avatar answered Oct 11 '22 22:10

lsalamon


It's your COM component is housed in a COM server (ie a seperate process) then you won't need to do anything special as the COM subsystem will remote your calls from your x64 app to the X86 app and back again.

If your component is an in-process COM component then you'll have to rethink things as a 64 bit process can't use 32 bit in process COM components. You could force your server to run under x86 so that you can access the components (they'll both be 32 bit processes). If you don't want to do this then you'll have to see if there a x64 bit version of the COM components you're using.

like image 2
Sean Avatar answered Oct 11 '22 23:10

Sean