我仿照Cypress的控制面板写一个程序把所有Ezusb都列举出来我的代码如下:
bool TForm1::bOpenDriver(HANDLE * phDeviceHandle, char * devname)
{
//TODO: Add your source code here
char completeDeviceName[64] = " ";
char pcMsg[64] = " ";
strcat(completeDeviceName,devname);
*phDeviceHandle = CreateFile( completeDeviceName,
GENERIC_WRITE,
FILE_SHARE_WRITE,
NULL,
OPEN_EXISTING,
0,
NULL);
if(*phDeviceHandle == INVALID_HANDLE_VALUE)
{
return false;
}
else
{
return true;
}
}
列举函数在下面:
void TForm1::OnFileUpdataAllDevs(void)
{
//TODO: Add your source code here
int i=0;
HANDLE hDevice = NULL;
char pcDriverName[MAX_DRIVER_NAME] = " ";
m_strUSBDevs = " ";
for(i = 0;i < MAX_USB_DEV_NUMBER;i++)
{
sprintf(pcDriverName, "Ezusb-%d ",i);
if(bOpenDriver(&hDevice,pcDriverName) == true)
{
m_strUSBDevs += pcDriverName;
m_strUSBDevs += "\n ";
Edit1-> Text = m_strUSBDevs;
CloseHandle(hDevice);
}
}
} |