Take the 2-minute tour ×

I have a project that must be compiled and run in 64 bit mode. Unfortunately, I am required to call upon a DLL that is only available in 32 bit mode, so there's no way I can house everything in a 1 Visual Studio project. I am working to find the best way to wrap the 32 bit DLL in its own exe/service and issue remote (although on the same machine) calls to that exe/service from my 64 bit app. My OS is Win7 Pro 64 bit.

The required calls to this 32 bit process are several dozen per second, but low data volume. This is a realtime image analysis application so response time is critical despite low volume. Lots of sending/receiving single primitives.

Ideally, I would host a WCF service to house this DLL, but in a 64 bit OS one cannot force the service to run as x86! Source. That is really unfortunate since I timed function calls to the WCF service to be only 4ms on my machine.

I have experimented with named pipes is .net. I found them to be 40-50 times slower than WCF (unusable for me).

Any other options or suggestions for the best way to approach my puzzle?

share|improve this question
See this answer for a more comprehensive list of techniques for accessing 32-bit DLLs from 64-bit applications. –  cdiggins Oct 17 '12 at 15:51
add comment

2 Answers

up vote 6 down vote accepted

As you correctly note, there is no way to mix bitness in the same process. You need a separate process for your 32-bit part.

I think hosting a WCF Service is the right way to go. Your link only talks about wcfsvchost. I am pretty sure you can create your own Windows Service, and host the WCF service in that on 32 bit.

See this link: How to host a WCF service in a managed application. You can host your service in any managed application, including a Windows Service, and run it under the bitness you like.

This is the amount of code required to self-host a WCF service in your application, assuming you have just created a new service called MyService, and the appropiate configuration has been added to app.config:

class Program
    static void Main(string[] args)
        using(ServiceHost host = new ServiceHost(typeof(MyService), new Uri[0]))

The above program will run just as well, also if you compile it explicitly as 32 or 64 bit.

share|improve this answer
Could you please elaborate a little bit? I see I can create a 32 bit Windows Service, how would I go about creating a WCF service to do the I/O for my 32 bit Windows Service? –  bufferz May 10 '10 at 17:33
Thanks driis! I was not aware you could host WCF services manually from an application. This is a much better solution than one I thought I would end up using. raises fist in the air –  bufferz May 10 '10 at 17:51
Oh, and just in case you run into security problems, here's a link: blogs.msdn.com/amitlale/archive/2007/01/29/… –  driis May 10 '10 at 17:53
add comment

None. Point. 32 bit dll in 64 bit process = no go.

What I do is run a 32 bit wrapper process and communicate with it using WCF - much like you do. I can force the OS to run 32 bit.

I have a core library (Tradex.Connectivity.Core), with the platform independant .NET code. I have two wrappers (Wrapper32.exe, Wapper64.exe) that start and load the independent code and then load the class (managed C++). Works like a charm.

THat pretty much is the only way for me - you can not crss load 32 and 64 bit elements.

share|improve this answer
"WHat I do is run a 32 bit wrapper process and communicate with it using WCF - much like you do. I can force the OS to run 32 bit." How did you manage to get your WCF service to run in 32 bit mode on a 64 bit OS? Setting the platform target to x86 throws BadImageFormatException and I haven't been able to research a way around this. –  bufferz May 10 '10 at 17:31
Why do I care? I mean, WCF is network based anyway. Once the stuff is serialized, there is no 32 or 64 bit mode anymore. Oh, and I self-host - no wcfsvdhost, I start my own hosting in my exe. Only a couple of lines of code. –  TomTom May 10 '10 at 17:36
Thanks TomTom, I did not know you could self host WCF elements outside of WCF template projects. Since you asked "why do I care?" I must point out that I literally could not compile a 32 bit WCF template project that wrapped a 32 bit DLL. Just the template though, self hosting works. thanks again. –  bufferz May 10 '10 at 17:54
add comment

Your Answer


