c# - An attempt was made to load a program with an incorrect format -
i using c# loading c++ dll, , got error:
"an unhandled exception of type 'system.badimageformatexception' occurred in myapp.exe" "additional information: attempt made load program incorrect format. (exception hresult: 0x8057000b)
i not figure out why. c++ dll generated using vs2012 wizard, win32 application, dll pre-head. built x64 option. here code:
// mynativedll.cpp : defines exported functions dll application. // #include "stdafx.h" //char* pmemorybuffer = null; using namespace std; __declspec(dllexport) long test() { long a; = 1; a++; return a; }
the c# code calling is:
[dllimport("c:\\mynativedll\\x64\\debug\\mynativedll.dll", entrypoint = "test")] private extern static int test(); void dojob() { long = test(); // exception thrown here }
c# code built cpu option, , loading x64 native dll. wondering did wrong? have been trying long, stuck here. thanks!
update when compile native dll using win 32 option, , set correct dll path, loads successfully. when compile native dll x64 options, load correct path, loading fails.
as mentioned: the c++ dll generated using vs2012 wizard, win32 application, dll pre-head. built x64 option
the dll , exe have both 32 bit, or both 64 bit.
Comments
Post a Comment