在单独的DLL中调用C ++函数时,我从Visual Studio C#应用程序获取StackOverFlowException。请参阅附图。
引起异常的原因可能是整个数组dblExptData被放在了堆栈上.a
注意我不是C#程序员,这是属于我的C#同事的代码;我负责他正在调用的C ++ DLL。我也从调用此DLL的C ++测试工具中获得异常,但我只是在C ++调用程序中增加了堆栈大小,并且它工作正常。
但是,我不知道如何从C#中做到这一点,他也不知道。有什么指针吗?
以下是代码:
namespace Sample_BO_50_crash
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
}
private void button1_Click(object sender, EventArgs e)
{
int[] aPVTcorrelations = new int[4] { 4, 0, 2, 2 };
int iFm = 56;
int iDs = 112;
int iDp = 2128;
double[] afluidData = new double[448] { 365.653948309249, 0, 0.8, 0.85, 0, 0, 0, 0.068947448, 365.653948309249, // I have truncated this for the post
double[] dblWeightFactData = new double[2576] { 1, 1, 10, 0, 0, 0, 0, 1, // I have truncated this for the post
int[] iExptInfo = new int[448] { 1, 0, 6, 19, 1, // I have truncated this for the post
double[] dblExptData = new double[48944]
{ -10000, 404.2611, 33784310.2078, 0 }; // I have truncated this for the post
double[] BoundsData = new double[6] { 50, 50, 50, 50, 50, 50 };
double[] aPVTtuningMults = new double[12] { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 };
int errorcode = (int)BO_Tune.TUNEBOPVTCORRS(aPVTcorrelations, iFm, iDs, iDp, afluidData, iExptInfo, dblExptData, dblWeightFactData, BoundsData, aPVTtuningMults);
}
}
public class BO_Tune
{
public const string strMapTune1 = "BOPVTTune.dll";
// Interface of method to get Tuned results
[DllImport(strMapTune1, CharSet = CharSet.Ansi, CallingConvention = CallingConvention.Cdecl)]
public static extern IntPtr TUNEBOPVTCORRS(int[] aPVTcorrelations, int Ifm, int Ids, int Idp, double[] afluidData,
int[] ExptInfo, double[] ExptData, double[] WeightFactData, double[] BoundsData, double[] aPVTtuningMults);
}
}
错误消息是:类型' System.StackOverflowException'未处理的异常。发生在Sample_BO_50_crash.exe
中如果可能,尽量避免使用EDITBIN.EXE,希望从编译器/链接器中执行此操作。
C ++方面的声明:
_declspec(dllexport) int TUNEBOPVTCORRS(
int* aPVTcorrelations,
int Ifm,
int Ids,
int Idp,
double* afluidData,
int* ExptInfo,
double* ExptData, //output
double* WeightFactData,
double* BoundsData,
double* aPVTtuningMults) // output
导致问题的是ExptData数组。