代码如下: C++ 接口如下:
DWORD dwKeyIndex; //输送系统分配的索引
DWORD bandRate=0; // 暂时没用
DWORD rv; // 返回值 成功 USBKEY_SUCCESS 失败 USBKEY_KEY_REMOVED
KEYHANDLE hKey; //输出句柄
Usb_Connect(dwKeyIndex,bandRate,&hKey)C# 调用 该接口:
using using System.Runtime.InteropServices;
.....[ DllImport(@"C:\ZfCryptApi.dll", EntryPoint = "Usb_Connect")]
public static extern UInt32 Usb_Connect(UInt32 dwKeyIndex,UInt32 bandRate, ref IntPtr hkey);
private void button1_Click(object sender, EventArgs e)
{
UInt32 dwindex = Convert.ToUInt32(textBox1.Text);
IntPtr hkey = IntPtr.Zero;
UInt32 rv=Usb_Connect(dwindex, 0,ref hkey);
label1.Text = rv.ToString();
}
运行结果:无法在 DLL“C:\ZfCryptApi.dll”中找到名为“Usb_Connect”的入口点。我的调用是否正确,望大侠指教。
DWORD dwKeyIndex; //输送系统分配的索引
DWORD bandRate=0; // 暂时没用
DWORD rv; // 返回值 成功 USBKEY_SUCCESS 失败 USBKEY_KEY_REMOVED
KEYHANDLE hKey; //输出句柄
Usb_Connect(dwKeyIndex,bandRate,&hKey)C# 调用 该接口:
using using System.Runtime.InteropServices;
.....[ DllImport(@"C:\ZfCryptApi.dll", EntryPoint = "Usb_Connect")]
public static extern UInt32 Usb_Connect(UInt32 dwKeyIndex,UInt32 bandRate, ref IntPtr hkey);
private void button1_Click(object sender, EventArgs e)
{
UInt32 dwindex = Convert.ToUInt32(textBox1.Text);
IntPtr hkey = IntPtr.Zero;
UInt32 rv=Usb_Connect(dwindex, 0,ref hkey);
label1.Text = rv.ToString();
}
运行结果:无法在 DLL“C:\ZfCryptApi.dll”中找到名为“Usb_Connect”的入口点。我的调用是否正确,望大侠指教。
试试类似:extern "C" DWORD cdecl Usb_Connect(...);这样的格式吧。很久没用C++的,都忘记了。呵呵,但希望能够给你点提示。