简体   繁体   English

从x64托管代码调用x64 C ++ DLL

[英]x64 C++ DLL called from x64 Managed Code

I have a x64-bit managed project that calls into an x64 bit C++ DLL. 我有一个x64位托管项目,该项目调用x64位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 这在Visual Studio 2010中很好用。但是,如果我将C ++项目升级到Visual Studio 2012,则无法再调用x64位DLL,并且收到错误消息。

An attempt was made to load a program with an incorrect format. 试图加载格式错误的程序。 (Exception from HRESULT: 0x8007000B) (来自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. 该项目在Visual Studio 2010中运行良好。如果我不允许Visual Studio将项目升级到Visual Studio 2012,并且在Visual Studio 2010中编译并与C ++ DLL链接,则效果并不理想。

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: C Sharp中的签名是:

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

signature in C++ is: C ++中的签名是:

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"). 在C#项目中,实际上需要查看三个相关位置(解决方案配置,解决方案配置到项目配置的映射以及在“平台目标”下“构建”部分的项目属性页上定义的项目配置的实际含义) 。 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. 您可能需要运行corflags.exe来查看.Net二进制文件是否真的是x64 / AnyCPU构建。 On the C++ DLL, dependency walker can tell you what architecture the DLL is for. 在C ++ DLL上,依赖关系跟踪程序可以告诉您DLL的体系结构。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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