请大家帮忙的。C++编写的dll(libgc.dll)放在当前的目录的debug目录下。一下是我用C#写的动态调用C++dll测试方法:ing System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
//using System.Linq;
using System.Text;
using System.Windows.Forms;
using System.Runtime.InteropServices;namespace Dialogic01
{
public partial class test : Form
{
public test()
{
InitializeComponent();
}
[DllImport("libgc.dll", CharSet = CharSet.Ansi, CallingConvention = CallingConvention.Cdecl)]
public static extern int gc_Start(IntPtr startp);
[DllImport("libgc.dll", CharSet = CharSet.Ansi, CallingConvention = CallingConvention.Cdecl)]
public static extern int gc_Close(int chdev);
[DllImport("libgc.dll", CharSet = CharSet.Ansi, CallingConvention = CallingConvention.Cdecl)]
public static extern int gc_OpenEx(ref int linedevp, string devicename, int mode, [MarshalAs(UnmanagedType.AsAny)] Object usrattr);
[DllImport("libgc.dll", CharSet = CharSet.Ansi, CallingConvention = CallingConvention.Cdecl)]
public static extern int gc_GetResourceH(int linedevp, ref int resourcehp, int resourcetype);
private void button1_Click(object sender, EventArgs e)
{
try
{
gc_Close(1);
}catch( Exception ex)
{
MessageBox.Show(ex.Message);
return;
}
}
}
}
运行时:点击测试按钮出现异常:[System.DllNotFoundException] = {"无法加载 DLL“libgc.dll”: 找不到指定的模块。 (异常来自 HRESULT:0x8007007E)。"}我在网上查阅了很多资料都未解决,请教高手指点指点的。
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
//using System.Linq;
using System.Text;
using System.Windows.Forms;
using System.Runtime.InteropServices;namespace Dialogic01
{
public partial class test : Form
{
public test()
{
InitializeComponent();
}
[DllImport("libgc.dll", CharSet = CharSet.Ansi, CallingConvention = CallingConvention.Cdecl)]
public static extern int gc_Start(IntPtr startp);
[DllImport("libgc.dll", CharSet = CharSet.Ansi, CallingConvention = CallingConvention.Cdecl)]
public static extern int gc_Close(int chdev);
[DllImport("libgc.dll", CharSet = CharSet.Ansi, CallingConvention = CallingConvention.Cdecl)]
public static extern int gc_OpenEx(ref int linedevp, string devicename, int mode, [MarshalAs(UnmanagedType.AsAny)] Object usrattr);
[DllImport("libgc.dll", CharSet = CharSet.Ansi, CallingConvention = CallingConvention.Cdecl)]
public static extern int gc_GetResourceH(int linedevp, ref int resourcehp, int resourcetype);
private void button1_Click(object sender, EventArgs e)
{
try
{
gc_Close(1);
}catch( Exception ex)
{
MessageBox.Show(ex.Message);
return;
}
}
}
}
运行时:点击测试按钮出现异常:[System.DllNotFoundException] = {"无法加载 DLL“libgc.dll”: 找不到指定的模块。 (异常来自 HRESULT:0x8007007E)。"}我在网上查阅了很多资料都未解决,请教高手指点指点的。
或windows\system32目录下试试