编译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);用在C#里我写成了[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);总觉得是不是类型错了。另外还有一点不知道值不值得一说,
这个dll回读取txt文件的,一开始调用是文件读不到,所以我把dll读取的文件路径都改成了绝对路径,放在system32下。
然后就变成了这样的错误,请高手指教~
尝试读取或写入受保护的内存。这通常指示其他内存已损坏。************** 异常文本 **************
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);用在C#里我写成了[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);总觉得是不是类型错了。另外还有一点不知道值不值得一说,
这个dll回读取txt文件的,一开始调用是文件读不到,所以我把dll读取的文件路径都改成了绝对路径,放在system32下。
然后就变成了这样的错误,请高手指教~
解决方案 »
- C#字符串问题。。。。求助
- 【有图】用如Artistree软件模板生成网页在Dreamweaver 或VS2008中设计错位,但运行时正常,为什么
- 控制台程序,main()的返回值是 void,为何运行后,还是会返回操作系统一个0值呢? [code=C#] using System; namespace p
- C#企业开发控件、企业开发工具,有哪些?
- 拜求有关自动绘图操作的干扰问题解决方法
- asp.net如何实现验证码
- 探讨:动态添加枚举值
- 求助C# IOCP性能并发
- 哪位愿意帮忙把这6行java代码转为C#代码?
- .net中的栈和堆的问题!!
- tablelayoutpanel如何遍历所有单元格
- c#做登录器,对照数据库时的一个小问题
// 注意你的编译方式改为Unicode
extern "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);
// 放到你合适的目录下
[DllImport("RIT.dll", CallingConvention = CallingConvention.Winapi, CharSet = CharSet.Unicode)]
[return: MarshalAs(UnmanagedType.Bool)]
public static extern bool DoRecognize(
ref byte byteSerializedCh,
int iByteNum,
short chDestCh,
ref short chWrittenCh,
ref double pEvalout,
int iENum,
ref int state,
ref byte ch);
现在要我改RID.dll用stdcall的方式不太现实,
另外那些指针有些是数组,有些是出参,请教可以都用ref吗?