delphi编写的dll在C#中如何调用?

muqingyan 2012-10-22 09:37:23
delphi编写的dll函数如下:
function SendDatafun(comport:integer;bps:longint;address:integer;sendData:pchar;color:integer;showMode,showSpeed,showTime:integer):integer;
StdCall external '../dlltpzp.DLL';
在C#中如何调用,我是用下边的方法,总是提示“尝试读取或写入受保护的内存。这通常指示其他内存已损坏。”
[DllImport("dlltpzp.dll", CharSet = CharSet.Ansi)]
private static extern int SendDatafun(int comport, long bps, int address, StringBuilder sendData, int color, int showMode, int showspeed, int showtime);
在线等,各位大神帮帮忙啊
...全文
130 5 打赏 收藏 转发到动态 举报
写回复
用AI写文章
5 条回复
切换为时间正序
请发表友善的回复…
发表回复
muqingyan 2012-10-23
  • 打赏
  • 举报
回复
参数问题已经解决,不过还有其他问题,再慢慢解决吧
只在此山中 2012-10-23
  • 打赏
  • 举报
回复
先把long bps 改为 int bps 看,
如果还不行,把StringBuilder sendData改为IntPtr sendData,然后自己分配非托管内存,调用.
muqingyan 2012-10-23
  • 打赏
  • 举报
回复
各位大神,没有人能帮忙解决这个问题吗?
muqingyan 2012-10-22
  • 打赏
  • 举报
回复
[Quote=引用 1 楼 的回复:]
加上调用约定说明,delphi你应该是stdcall的吧
[DllImport("",CallingConvention=CallingConvention.StdCall)]
[/Quote]

加上了还是不行,是不是那个参数转换的有问题呢?
bdmh 2012-10-22
  • 打赏
  • 举报
回复
加上调用约定说明,delphi你应该是stdcall的吧
[DllImport("",CallingConvention=CallingConvention.StdCall)]

110,535

社区成员

发帖
与我相关
我的任务
社区描述
.NET技术 C#
社区管理员
  • C#
  • Web++
  • by_封爱
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告

让您成为最强悍的C#开发者

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