Question

I am having a C# (.NET 3.5, VS2005 Professional) application that uses unmanaged 32bit library written in C/C++. API that I use is like this:

void * Initialize(int x);

voic GetData(void *);

And this works when I run it on Windows XP 32bit, but on Windows XP64bit it throws exception:

Unhandled Exception: System.Reflection.TargetInvocationException: Exception has been thrown by the target of an invocation. ---> System.BadImageFormatException: An attempt was made to load a program with an incorrect format. (Exception from HRESULT: 0x8007000B) at Aktuelizator.CommonLibrary.InitializeRingBuffer(Int32 dim) at Aktuelizator.AktuelizatorWService.AktuelizatorWS..ctor()

These unmanaged DLL's work under 64bit XP when called from 32bit unmanages application writetn in C/C++.

Does anyone have any idea?

Was it helpful?

Solution

Your build configuration Platform is set to 'Any CPU', that means on a 64 bit OS it runs as 64 bit and you can't load the dll. Set it instead to x86, this will force it to run as 32 bit regardless of OS and your dll will load fine.

OTHER TIPS

It sounds like your DLL is only compiled to 32 bit, but you try to call it from both a 32 bit and 64 bit process. The former will work, of course. The later, however, won't. 32 bit DLLs can only be used in 32 bit processes. Try compiling the DLL to a 64 bit target and let the C# app use that one.

Check all parameters that are defined as Int32, that should in fact be IntPtr.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top