我正在使用c ++形态库mcr.dll,当我在C#控制台应用程序中使用它时它工作正常,但当我试图在ASP.NET MVC4控制器中运行此代码时它失败了#34; getlemma()"方法,在线" LoadMcr(s)"使用System.StackOverflowException。请帮助我理解,为什么mvc控制器不想让它像在控制台应用程序中那样工作?
PS:当我尝试在控制台应用程序中运行它时出现了一些问题,例如关于" PInvoke" ConsoleApplication1!ConsoleApplication1.morph :: LoadMc unbalanced stack"的消息,但是当我添加"CallingConvention = CallingConvention.Cdecl".
public string getlemma(string word)
{
InitMcr();
string s = "zal.mcr";
LoadMcr(s);
Tids tt = new Tids();
FindWID(word, ref tt);
Tid t = tt.ids[0];
Tinlexdata inlex = new Tinlexdata();
GetWordById(t, false, false, ref inlex);
return (inlex.inlex[0].anword);
}
[System.Runtime.InteropServices.StructLayoutAttribute(System.Runtime.InteropServices.LayoutKind.Sequential)]
public struct Tid
{
/// unsigned int
public uint lnk;
/// unsigned char
public byte en;
}
[System.Runtime.InteropServices.StructLayoutAttribute(System.Runtime.InteropServices.LayoutKind.Sequential)]
public struct Tids
{
/// Tid[200]
[System.Runtime.InteropServices.MarshalAsAttribute(System.Runtime.InteropServices.UnmanagedType.ByValArray, SizeConst = 200, ArraySubType = System.Runtime.InteropServices.UnmanagedType.Struct)]
public Tid[] ids;
/// int
public int count;
}
// // InitMcr() - initialize dictionary
[DllImport("mcr.dll", CharSet = CharSet.None, CallingConvention = CallingConvention.Cdecl)]
public static extern int InitMcr();
// // LoadMcr - load dictionary
[DllImport("mcr.dll", CharSet = CharSet.None, CallingConvention = CallingConvention.Cdecl)]
public static extern int LoadMcr([System.Runtime.InteropServices.InAttribute()] [System.Runtime.InteropServices.MarshalAsAttribute(System.Runtime.InteropServices.UnmanagedType.LPStr)] string s);
// // FindID - (find word in lemma dictionary)
[DllImport("mcr.dll", CharSet = CharSet.None, CallingConvention = CallingConvention.Cdecl)]
public static extern int FindWID([System.Runtime.InteropServices.InAttribute()] [System.Runtime.InteropServices.MarshalAsAttribute(System.Runtime.InteropServices.UnmanagedType.LPStr)] string s, ref Tids ids);
// GetByID - (get lemma for a word)
[DllImport("mcr.dll", CharSet = CharSet.None, EntryPoint = "GetWordById", CallingConvention = CallingConvention.Cdecl)]
public static extern int GetWordById(Tid id, [System.Runtime.InteropServices.MarshalAsAttribute(System.Runtime.InteropServices.UnmanagedType.I1)] bool gh_only, [System.Runtime.InteropServices.MarshalAsAttribute(System.Runtime.InteropServices.UnmanagedType.I1)] bool all, ref Tinlexdata outdata);