在64位Windows 7上运行的C ++非托管DLL [英] C++ unmanaged dll runing at 64bit windows7

查看:70
本文介绍了在64位Windows 7上运行的C ++非托管DLL的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有C#Windows应用程序,该应用程序调用C ++非托管dll函数.该应用程序在Windows XP x86环境下运行良好.现在,我将此应用程序移至WIN7 64位环境.我在x64上编译了c ++ dll,并在x64上也编译了我的C#应用​​程序.当我运行我的应用程序时,我收到一条错误消息,显示"System.AccessViolationException:尝试读取或写入受保护的内存.这通常表明其他内存已损坏."当我的应用程序调用c ++ dll函数时.

我的C#中的代码如下所示:

I have C# windows application which calling C++ unmanaged dll function. this application is working fine at windows XP x86 environment. now i move this application to WIN7 64 bit environment. I complied c++ dll at x64, and build my C# application at x64 as well. when i run my application, I got error message showed "System.AccessViolationException: Attempted to read or write protected memory. This is often an indication that other memory is corrupt." when my application calling c++ dll function.

the code in my C# as show below:

[DllImport("SpotForwardSimDLL.dll")]
private static extern long CalSpotForwardSimulation(int A, int B, int C,
int vDate, int sDate, int eDate, double[] hisCurve, double[] monthVol,
double[] dailyVol, double[] forwardCurves, string[] curveNames,
double[] dailyVal, double[] monthVal,double[] corrVal)

CalSpotForwardSimulation(numFactors, numLoc, numSims,lCobDate, lStartDate, lendDate, hisCurves, monthVol, dailyVol,forwardCurves, curveNames, dailyVal, monthVal, corrVal);




C ++中的代码如下所示:




the code in C++ as show below:

__declspec(dllexport) long __stdcall
CalSpotForwardSimulation(int ltempOfFactors, int ltempOfLoc,
int ltempOfSims ,int vDate,int sDate,int eDate,
double * tempCurveHistorical,double * tempMonthlyVol,
double * tempDailyVol,double * tempForwardCurve,
char ** curveName,double dailyRet[],
double monthRet[],double corrRet[])



我已经在这个问题上工作了好几个星期了,对解决这个问题有什么建议吗?



I have been working on this issue for weeks, any suggestion to solve this problem?

推荐答案

机会是,您正在尝试使用某些Win32可执行文件,例如DLL.您不能这样做,并且该问题仅在运行时出现.例如,您怎么知道"SpotForwardSimDLL.dll"不是32位的?

以64位和32位构建的组件在不同平台上的64位系统上工作.您的64位代码在本机平台上运行,但是32位进程在名为WoW64的平台上运行,请参见 http://en .wikipedia.org/wiki/WOW64 [^ ] .

此外,有两个单独的64位平台:x86-64( http://en.wikipedia.org/wiki/X86 -64 [ ^ ])和IA- 64"Itanium"( http://en.wikipedia.org/wiki/Itanium [
Chances are, you''re trying to work with some Win32 executable, like a DLL. You cannot do it, and the problem is only manifested during run-time. For example, how do you know "SpotForwardSimDLL.dll" is not 32-bit?

The components built as 64-bit and 32-bit work on a 64-bit systems in a different platforms. Your 64-bit code runs on the native platform, but a 32-bit process works on the platform called WoW64, see http://en.wikipedia.org/wiki/WOW64[^].

Moreover, there are two separate 64-bit platforms: x86-64 (http://en.wikipedia.org/wiki/X86-64[^]) and IA-64 "Itanium" (http://en.wikipedia.org/wiki/Itanium[^]). They are incompatible. You version of OS supports one of them, depending on your CPU architectures, so all 64-bit software components you obtain should match one of these two architectures, but any 32-bit component will work. If you accidentally try to mix them up, you will get run-time crash of the same kind.

The only option to use a 32-bit component in 64-bit application is running both as different processes and use any kind in inter-process communications between them.

Another simple resolution would be keeping all of your 32-bit codes; chances are, they will successfully run on top of WoW64.

—SA


这篇关于在64位Windows 7上运行的C ++非托管DLL的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆