导入c+时c#中的堆栈溢出异常+;动态链接库
我有一个C#类库项目,其中有以下方法:导入c+时c#中的堆栈溢出异常+;动态链接库,c#,dllimport,stack-overflow,C#,Dllimport,Stack Overflow,我有一个C#类库项目,其中有以下方法: public string GetPackagestring(string devID, string ConfigName) { //my code here string ProgramName="VOT"; //here I call a c++ Dll function packagestring = getparameters(devID, ConfigName, ProgramName); //other
public string GetPackagestring(string devID, string ConfigName)
{
//my code here
string ProgramName="VOT";
//here I call a c++ Dll function
packagestring = getparameters(devID, ConfigName, ProgramName);
//other part of code
}
调用外部dll函数时,在packagestring行中出现Stackoverflow异常
在我的项目中,我正在导入DLL,如下所示
public partial class Form1 : Form
{
//Import DLL
[DllImport(@"\DLL\testconfigdump.dll", CharSet = CharSet.Ansi, EntryPoint = "getparameters", CallingConvention = CallingConvention.Cdecl)]
[return: MarshalAs(UnmanagedType.BStr)]
public static extern string getparameters(string pumpid, string configname, string progname);
...
}
有人能帮我解释为什么我会遇到stackoverflow问题吗?消息说当前线程处于stackoverflow状态。您需要提供用于编译dll的代码,否则很难说发生了什么。GetPackageString是否在循环中调用?您必须在C中使用
StringBuilder
,而不是string
。在C中提供getparameters
的代码也很有帮助。