C++写的DLL类库,C#调用回调函数时发生错误,程序崩掉:vshost32已停止工作
/// <summary> ///用户登录回调 /// </summary> /// <param name="nError"> nError: 登陆服务器错误值.0为登陆成功,其他为错误值</param> [UnmanagedFunctionPointer(CallingConvention.Cdecl)] public delegate void OnUserLoginCallBack(bool bl, uint nError); /// <summary> /// 注册用户登录回调 /// </summary> /// <param name="onuserLogin"></param> [DllImport("VideoCommunicationDll.dll", EntryPoint = "OnLoginCallBack", CallingConvention = CallingConvention.Cdecl)] public static extern void OnLoginCallBack(OnUserLoginCallBack onuserLogin);
C#的调用如下:
//回调函数 public static void onUserLoginCallBack(bool bl, uint nError){ //Console.WriteLine("onUserLoginCallBack-----" + bl.ToString()); //bll = bl; Console.WriteLine(bl); } //登录按钮 private void button1_Click(object sender, EventArgs e) { bool a = UnSafeJhq.InitDll(); OnUserLoginCallBack lc = new OnUserLoginCallBack(onUserLoginCallBack); UnSafeJhq.OnLoginCallBack(lc);//执行到这里报错 UnSafeJhq.UserLoginEx(textBox1.Text, textBox2.Text, textBox3.Text, 1); this.Visible = false; //this.Close(); Form form1 = new Form1(); Form1.userid = textBox2.Text; form1.ShowDialog(); }
执行到注册登录回调函数的那里报错:
各位有遇到过吗?
我这里写的和它差不多啊,只不过DLL是别人提供的,声明的cs也是别人提供的,我看不到C++ 的代码
@anyhow: 我这么说吧,你用这篇例子里的 C++ dll,然后在你的代码中调用,看能否成功。
把你的代码给我我给你看看
没解决了为什么崩,重新让他写的dll,OK了