调用非托管DLL不成功,请帮帮忙

tyronehong 2005-12-13 04:33:26
public class TestDll
{
[DllImport("keyint.dll")]
public static extern void init(ref string ErrCode);

public static string testinit()
{
string errcode = "0";
init(ref errcode); //这句出错,提示:未将对象的引用设置到对象的实例??
return errcode;
}
}
...全文
173 11 打赏 收藏 转发到动态 举报
写回复
用AI写文章
11 条回复
切换为时间正序
请发表友善的回复…
发表回复
tyronehong 2005-12-16
  • 打赏
  • 举报
回复
解决了,用StringBuilder,谢谢
lookcode 2005-12-13
  • 打赏
  • 举报
回复
public static extern void init(ref string ErrCode);

有这个函数吗? 引用来做什么用,如果要学习引用,最好找個可以用的
pyuan 2005-12-13
  • 打赏
  • 举报
回复
不要用ref string,而且最好用stringbuiler
速马 2005-12-13
  • 打赏
  • 举报
回复
没有任何情况需要使用ref string
速马 2005-12-13
  • 打赏
  • 举报
回复
贴出函数原型
还有方法的参数是传入参数还是传出参数
tyronehong 2005-12-13
  • 打赏
  • 举报
回复
VS 2003提示:未将对象的引用设置到对象的实例??
VS 2005提示:尝试读取或写入受保护的内存。这通常指示其他内存已损坏。!!!??
tyronehong 2005-12-13
  • 打赏
  • 举报
回复
这是VB6的声明,能成功调用
Private Declare Sub init Lib "hisint.dll" (ByVal Errcode As String)

PB的,也能成功
PRIVATE SUBROUTINE init(ref string Errcode) Library 'keyint.dll'

在.net里应该如何调用,谢谢了
diandian82 2005-12-13
  • 打赏
  • 举报
回复
mark
tiaoci 2005-12-13
  • 打赏
  • 举报
回复
public static extern void init(string ErrCode);

不需要ref吧,不知道你dll中怎么用的 ERRCODE
rex0y 2005-12-13
  • 打赏
  • 举报
回复
EntryPoint没写,还有参数类型对不对
rex0y 2005-12-13
  • 打赏
  • 举报
回复
[DllImport("User32.dll",EntryPoint="keybd_event")]
private static extern void keybd_event(byte vk,byte
scan,long dwFlags,long dwExtraInfo);

110,499

社区成员

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

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

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