C#调用dll “尝试读取或写入受保护的内存。这通常指示其他内存已损坏。”
编译OK,调试时候显示的错误
尝试读取或写入受保护的内存。这通常指示其他内存已损坏。
************** 异常文本 **************
System.AccessViolationException: 尝试读取或写入受保护的内存。这通常指示其他内存已损坏。
在 HZbox.HZjudge.DoRecognize(Byte[] byteSerializedCh, Int32 iByteNum, Int16 chDestCh, Int16& chWrittenCh, Double[] pEvalout, Int32 iENum, Int32[] state, Byte[] ch)
在 HZbox.HZjudge.Judge() 位置 I:\GoogleCode\hzapp\HZcomponent.HZbox\HZjudge.cs:行号 114
dll是C++的,是写.def的方式导出的方法
原来的声明是这样的
BOOL DoRecognize( const unsigned char* pWriteData, const int iDataLen, const unsigned short iDestWChar, unsigned short* iWrittenChar, double* pEvalOut, const int iENumber, int *state, char *cs);
[DllImport(@"C:\Windows\System32\RIT.dll", EntryPoint="DoRecognize")]static extern int DoRecognize( byte[] byteSerializedCh, int iByteNum, short chDestCh, ref short chWrittenCh, double[] pEvalout, int iENum, int[] state, byte[] ch);
// 注意你的编译方式改为Unicodeextern "C" __declspec(dllexport)BOOL __stdcall DoRecognize( const unsigned char* pWriteData, const int iDataLen, const unsigned short iDestWChar, unsigned short* iWrittenChar, double* pEvalOut, const int iENumber, int *state, char *cs);
[解决办法]
类型问题
参考
[解决办法]
也用指针,使用fix试试看
[解决办法]