C# 调用C++ dll

cjlovezj 2013-06-06 01:44:07
运行后就提示:debug assertion failed
File:afxwin1.inl
Line:19

找到afxwin1.inl的19行内容是:
_AFXWIN_INLINE HINSTANCE AFXAPI AfxGetInstanceHandle()
{
ASSERT(afxCurrentInstanceHandle != NULL);
return afxCurrentInstanceHandle;
}

请问这是什么问题,如何初始化实例,还是c#调用Csocket的问题,望高手帮忙,急!

C++:

extern "C" _declspec(dllexport) int InitVideoSDK(HWND pWnd)
{
int i;
SetTimer(pWnd, 1,1000,(TIMERPROC)TimerProc);//用回调函数处理
for(i=0; i<MAX_CAMERA_NUM; i++)
theApp.dvideo[i].CreateSocket(PORT_VIDEO,TYPE_VIDEO);
return 0;
}

C#:

[DllImport("lib_camera.dll")]
public static extern int InitVideoSDK(IntPtr pWnd);

private void button1_Click(object sender, EventArgs e)
{
try
{
InitVideoSDK(hwnd);
}
catch (System .Exception ex)
{
MessageBox.Show(ex.Message);
}

}

...全文
73 3 打赏 收藏 转发到动态 举报
写回复
用AI写文章
3 条回复
切换为时间正序
请发表友善的回复…
发表回复
gomoku 2013-06-10
  • 打赏
  • 举报
回复

extern "C" _declspec(dllexport) int InitVideoSDK(HWND pWnd)
{
  AFX_MANAGE_STATE(AfxGetStaticModuleState()); // <-- 加这行试试看
  int i;
owennol 2013-06-09
  • 打赏
  • 举报
回复
运行后就提示:debug assertion failed File:afxwin1.inl Line:19 这个应该不是MessageBox.Show(ex.Message)显示出来的,应该是C++内部的错误;
HopeInHeart 2013-06-09
  • 打赏
  • 举报
回复
把要调用的C++dll拷贝到编译目录下 添加引用: using System.Runtime.InteropServices; 声明: [DllImport("lib_camera.dll" EntryPoint="InitVideoSDK")] public static extern int InitVideoSDK(IntPtr pWnd); private void button1_Click(object sender, EventArgs e) { try { InitVideoSDK(this.Handle); } catch (System .Exception ex) { MessageBox.Show(ex.Message); } } 应该可以了,还不行联系我 qq:971096915

110,535

社区成员

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

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

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