Using 32-bit COM Call in 64-Bit Windows Application …

Added on by Ray Insalaco.

This was a new problem for me since I rarely ever need to write software that calls a COM object that is running on a second machine.  I am working on a data collection system that will integrate with our ERP system and is accessing it through the API that they provide.  The ERP system that I am connecting to is a 32-bit application and it will NOT run on a 64-bit system.  There is still some legacy code that they need to get migrated, and they are working on a full 64-bit update.  In my Visual Studio 2008 project I have a reference to a dll file that exposes the API needed to access the business rules and import or export data.  If I compile the project and run it on a 64-bit system, to program runs fine until I make a call against the API.  I then get this error:

“System.DllNotFoundException: Unable to load DLL 'SERVICES': The specified module could not be found. (Exception from HRESULT: 0x8007007E)”

After digging around, I found this is because I am calling a COM object that in turn is calling a 32-bit object which is not supported.  It is the act of the COM object running in the WOW64 subsystem making a call to a 32-bit object that is causing the problem.  At lest for the application that I am working on now, I was able to tell Visual Studio that the target CPU was a x86 and then everything ran fine.  This setting can be found at Project > Properties > Compile > Advanced Compile Options


Hope this helps …