C#.net 问题。调用外部DLL 20分! 20
publicForm1(){InitializeComponent();con=newconnect();ChartInit();groupBox1.Hide();Dll...
public Form1()
{
InitializeComponent();
con = new connect();
ChartInit();
groupBox1.Hide();
DllInit();
}
当DLLInit注释掉之后,就显示正常:
当DLLInit 加上之后 就显示不正常。 一个大红叉
请看DLLInit的具体实现:
public void DllInit()
{
QM_DLL = LoadLibrary("QM_USB.dll");
if(QM_DLL != IntPtr.Zero)
{
IntPtr P_Init_can = GetProcAddress(QM_DLL, "Init_can");
IntPtr P_Quit_can = GetProcAddress(QM_DLL, "Quit_can");
IntPtr P_Can_send = GetProcAddress(QM_DLL, "Can_send");
IntPtr P_Can_receive = GetProcAddress(QM_DLL, "Can_receive");
Init_can = (TYPE_Init_can)Marshal.GetDelegateForFunctionPointer(P_Init_can, typeof(TYPE_Init_can));
Quit_can = (TYPE_Quit_can)Marshal.GetDelegateForFunctionPointer(P_Quit_can, typeof(TYPE_Quit_can));
Can_send = (TYPE_Can_send)Marshal.GetDelegateForFunctionPointer(P_Can_send, typeof(TYPE_Can_send));
Can_receive = (TYPE_Can_receive)Marshal.GetDelegateForFunctionPointer(P_Can_receive, typeof(TYPE_Can_receive));
MessageBox.Show("DLL加载成功!!!");
}
else
{
MessageBox.Show("DLL加载失败!!!");
//Process.GetCurrentProcess().Kill();
}
}
请看ChartInit()的具体实现
网上百度了下,说是什么线程的影响,子线程什么的,。关键是我就没有用多线程啊 展开
{
InitializeComponent();
con = new connect();
ChartInit();
groupBox1.Hide();
DllInit();
}
当DLLInit注释掉之后,就显示正常:
当DLLInit 加上之后 就显示不正常。 一个大红叉
请看DLLInit的具体实现:
public void DllInit()
{
QM_DLL = LoadLibrary("QM_USB.dll");
if(QM_DLL != IntPtr.Zero)
{
IntPtr P_Init_can = GetProcAddress(QM_DLL, "Init_can");
IntPtr P_Quit_can = GetProcAddress(QM_DLL, "Quit_can");
IntPtr P_Can_send = GetProcAddress(QM_DLL, "Can_send");
IntPtr P_Can_receive = GetProcAddress(QM_DLL, "Can_receive");
Init_can = (TYPE_Init_can)Marshal.GetDelegateForFunctionPointer(P_Init_can, typeof(TYPE_Init_can));
Quit_can = (TYPE_Quit_can)Marshal.GetDelegateForFunctionPointer(P_Quit_can, typeof(TYPE_Quit_can));
Can_send = (TYPE_Can_send)Marshal.GetDelegateForFunctionPointer(P_Can_send, typeof(TYPE_Can_send));
Can_receive = (TYPE_Can_receive)Marshal.GetDelegateForFunctionPointer(P_Can_receive, typeof(TYPE_Can_receive));
MessageBox.Show("DLL加载成功!!!");
}
else
{
MessageBox.Show("DLL加载失败!!!");
//Process.GetCurrentProcess().Kill();
}
}
请看ChartInit()的具体实现
网上百度了下,说是什么线程的影响,子线程什么的,。关键是我就没有用多线程啊 展开
2个回答
2015-06-26 · 知道合伙人软件行家
关注
展开全部
QM_DLL = LoadLibrary("QM_USB.dll"); 这个地方设个断点,进行调试,看哪个地方出错了。再把出错信息发出来。
更多追问追答
追问
这段DLL引用代码 是写DLL的人提供的。 那段代码没有异常出现,
追答
TRY
{
DllInit();
}
Catch(EXCEPTION EX)
{
MessageBox.Show(Ex.Message); 显示出来看是什么问题。
}
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询