1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72
|
void CCMDTVDlg::OnButton1()
{
// TODO: Add your control notification handler code here
int i;
bool t=false;
CString Devices[10]; // an array of cstrings
for (i=2; i<3 ; i++)
{
t=true;
SP_INTERFACE_DEVICE_DATA Interface_Info;
Interface_Info.cbSize = sizeof(Interface_Info);
// Enumerate device
if (!SetupDiEnumInterfaceDevice(hInfo, NULL, (LPGUID)
&USBIODS_GUID,i, &Interface_Info))
{
SetupDiDestroyDeviceInfoList(hInfo);
//SetDlgItemText(IDC_LABEL,"Pas De device enum");
t=false;
}
DWORD needed; // get the required lenght
SetupDiGetInterfaceDeviceDetail(hInfo, &Interface_Info,
NULL, 0, &needed, NULL);
PSP_INTERFACE_DEVICE_DETAIL_DATA detail =
(PSP_INTERFACE_DEVICE_DETAIL_DATA) malloc(needed);
if (!detail)
{
SetupDiDestroyDeviceInfoList(hInfo);
//SetDlgItemText(IDC_LABEL,"CCC");
t=false;
}
CString str;
// fill the device details
if(t)
{
detail->cbSize = sizeof(SP_INTERFACE_DEVICE_DETAIL_DATA);
if (!SetupDiGetInterfaceDeviceDetail(hInfo,&Interface_Info,detail, needed,NULL, NULL))
{
free((PVOID) detail);
SetupDiDestroyDeviceInfoList(hInfo);
SetDlgItemText(IDC_LABEL,"Pas interface");
}
char name[MAX_PATH];
strncpy(name, detail->DevicePath, sizeof(name));
free((PVOID) detail);
str.Format("%s",name);
hUsbDevice = CreateFile(name, GENERIC_READ, 0, NULL, OPEN_EXISTING, 0, NULL);
if(hUsbDevice == INVALID_HANDLE_VALUE)
{
SetDlgItemText(IDC_LABEL1,"Erreur lors de l'ouverure du port");
}else
{
SetDlgItemText(IDC_LABEL1,"Port ouvert");
}
Devices[i] = name; // keep a copy of each device name
}
SetDlgItemText(IDC_LABEL,str);
}
} |
Partager