简体   繁体   中英

x64 C++ DLL called from x64 Managed Code

I have a x64-bit managed project that calls into an x64 bit C++ DLL. This worked good in Visual Studio 2010. However if I upgrade the C++ project to Visual Studio 2012 I can no longer call the x64-bit DLL and I recieve the error

An attempt was made to load a program with an incorrect format. (Exception from HRESULT: 0x8007000B)

This project worked great in Visual Studio 2010. If I do not allow Visual Studio to upgrade the project to Visual Studio 2012 and compile and link with the C++ DLL in Visual Studio 2010 than all works great.

My question is what has changed to break this code. I'm assuming some general type has changed that will require changes in my part. The first function signature that breaks is:

The signature in C sharp is:

internal static extern int ReverseBottomToTop(IntPtr imgptr, int nrows, int ncols)

signature in C++ is:

int ReverseBottomToTop(unsigned char *imgptr, int nrows, int ncols)

You might want to double check the project settings. In C# projects there are actually three relevant locations to look at (solution configuration, mapping of solution configuration to project configuration and the actualy meaning of the project configuration as defined on the project's property page in the "Build" section under "Platform target"). Usually the error you get is correct in that it indicates a platform mismatch between the binaries involved.

You might want to run corflags.exe to see whether or not your .Net binary really is an x64/AnyCPU build. On the C++ DLL, dependency walker can tell you what architecture the DLL is for.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM