110,571
社区成员
发帖
与我相关
我的任务
分享
DWORD __stdcall VCI_OpenDevice(DWORD DeviceType,DWORD DeviceInd,DWORD Reserved);
namespace testPCI5110DLL
{
public partial class Form1 : Form
{
[DllImport("ControlCAN.dll")]
static private extern int VCI_OpenDevice(int DeviceType, int DeviceInd, int Reserved);
public Form1()
{
InitializeComponent();
}
private void button1_Click(object sender, EventArgs e)
{
int open_device = VCI_OpenDevice(7, 0, 0);
if (open_device != 1)
{
MessageBox.Show("Open device fail!");
}
}
}
}
int error = 0;
//test pci5110
//ÉùÃ÷DLLº¯Êý
typedef DWORD (CALLBACK *OPENDEVICE)(DWORD DeviceType,DWORD DeviceInd,DWORD Reserved);
//ÉùÃ÷º¯Êý¾ä±ú
HMODULE hTestDLL = NULL;
OPENDEVICE VCI_OpenDevice = NULL;
// ¼ÓÔض¯Ì¬Á´½Ó¿â
hTestDLL = LoadLibrary(TEXT("ControlCAN.dll"));
if(hTestDLL == NULL)
{
error = GetLastError();
printf("cannot load ControlCAN.dll\n");
exit(0);
}
//ϵͳÃû³Æ
VCI_OpenDevice = (OPENDEVICE)GetProcAddress(hTestDLL,"VCI_OpenDevice");
if(VCI_OpenDevice==NULL)
{
error = GetLastError();
printf("cannot load process GetHostName\n");
FreeLibrary(hTestDLL);
exit(1);
}
DWORD DeviceType = 7;
DWORD DeviceInd = 0;
DWORD Reserved = 0;
DWORD open_device_status = (*VCI_OpenDevice)(DeviceType, DeviceInd, Reserved);
error = GetLastError(); //error返回6 FreeLibrary(hTestDLL);
{
//test pci5110
//声明DLL函数
typedef DWORD (_cdecl *OPENDEVICE)(DWORD DeviceType,DWORD DeviceInd,DWORD Reserved);
//声明函数句柄
HMODULE hTestDLL = NULL;
OPENDEVICE VCI_OpenDevice = NULL;
// 加载动态链接库
hTestDLL = LoadLibrary(LPCWSTR("ControlCAN.dll"));
if(hTestDLL == NULL)
{
int i = GetLastError();
printf("cannot load ControlCAN.dll\n");
exit(0);
}
//系统名称
VCI_OpenDevice = (OPENDEVICE)GetProcAddress(hTestDLL,"VCI_OpenDevice");
if(VCI_OpenDevice==NULL)
{
printf("cannot load process GetHostName\n");
FreeLibrary(hTestDLL);
exit(1);
}
DWORD open_device_status = (*VCI_OpenDevice)(7, 0, 0);
}