Search code examples
unmanagedresources

unmanaged dll code


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?


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.