DllImport Attempted to read or write protected memory

lixinwin2003 2013-05-10 09:28:02
int ReadCard(char *room, char *gate,char *stime, char *guestname, char *guestid, char *track1, char *track2, long *cardno, int *st);
这是dll里的原函数
其中:room、gate、stime、guestname、guestid、track1、track2、cardno、st为输出参数
gate、Guestname 、Guestid 、track1 、track2 可以为null
翻译成C#的代码:
int ReadCard(ref string room, string gate, ref string stime,
ref string guestname, ref string guestid, string track1, string track2,
ref int cardno, ref int st);


这样写报错哟,你帮我看看!!
Attempted to read or write protected memory. This is often an indication that other memory is corrupt.
试图读取或写入受保护的内存。这往往是一个迹象表明其他内存已损坏。
...全文
151 2 打赏 收藏 转发到动态 举报
写回复
用AI写文章
2 条回复
切换为时间正序
请发表友善的回复…
发表回复
lixinwin2003 2013-05-13
  • 打赏
  • 举报
回复
问题已经自己解决,这里数据类型错误,用StringBuilder,去ref,就可以!!都没有人回我!
lixinwin2003 2013-05-10
  • 打赏
  • 举报
回复
调用代码: string room = ""; //String gate = null; string stime = ""; //string guestname = null; string guestid = ""; //String track1 = null; //String track2 = null; int cardno = 0; int st = 1; int restul = adelMain.ReadCard(ref room, null, ref stime, null, ref guestid, null, null, ref cardno, ref st); if (restul == 0) { MessageBox.Show("成功!"); } else { MessageBox.Show("失败!" + restul); } 原型: [DllImport("MainDll.dll")] public static extern int ReadCard(ref string room, string gate, ref string stime, string guestname, ref string guestid, string track1, string track2, ref int cardno, ref int st);

62,047

社区成员

发帖
与我相关
我的任务
社区描述
.NET技术交流专区
javascript云原生 企业社区
社区管理员
  • ASP.NET
  • .Net开发者社区
  • R小R
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告

.NET 社区是一个围绕开源 .NET 的开放、热情、创新、包容的技术社区。社区致力于为广大 .NET 爱好者提供一个良好的知识共享、协同互助的 .NET 技术交流环境。我们尊重不同意见,支持健康理性的辩论和互动,反对歧视和攻击。

希望和大家一起共同营造一个活跃、友好的社区氛围。

试试用AI创作助手写篇文章吧