anthonycosson
Messages postés
106
Date d'inscription
mercredi 30 mars 2005
Statut
Membre
Dernière intervention
20 novembre 2009
21 mars 2006 à 09:11
le systeme est le meme mais il faut recuperer le GUID du port usb utilisé pour le mettre ensuite dans le createfile
voila le debut du code:
#include <stdio.h>
#include <stdlib.h>
#include <objbase.h>
//DWORRD, ...
#include <setupapi.h>
// you may have to manually include this library.
#include
//USBIO_GUID
//#include <conio.h> // ? unnecessary for the moment
//displayPeriph libs
#include <windows.h>
//#include <devguid.h>
#include <regstr.h>
#pragma
comment (
lib,"setupapi.lib")
#define INITGUID
int main()
{
//GUID hidGUID = {0xa5dcbf10, 0x6530, 0x11d2, {0x90, 0x1f, 0x00, 0xc0, 0x4f, 0xb9, 0x51, 0xed}};
//GUID hidGUID = {0x53f56307, 0xb6bf, 0x11d0, {0x94, 0xf2, 0x00, 0xa0, 0xc9, 0x1e, 0xfb, 0x8b}};
/*ROOT_HSB*/GUID hidGUID = {0xf18a0e88, 0xc30c, 0x11d0, {0x88, 0x15, 0x00, 0xa0, 0xc9, 0x06, 0xbe, 0xd8}};
//GUID hidGUID = {0x53f56307, 0xb6bf, 0x11d0, {0x94, 0xf2, 0x00, 0xa0, 0xc9, 0x1e, 0xfb, 0x8b}};
///*DOUCHETTE*/GUID hidGUID = {0x745a17a0L, 0x74d3, 0x11d0, {0xb6, 0xfe, 0x00, 0xa0, 0xc9, 0x0f, 0x57, 0xda}};
///*DOUCHETTE*/GUID hidGUID = {0xA5DCBF10L, 0x6530, 0x11D2, {0x90, 0x1F, 0x00, 0xC0, 0x4F, 0xB9, 0x51, 0xED}};
HDEVINFO hDevInfo;
SP_INTERFACE_DEVICE_DATA InterfaceDeviceInfoData;
hDevInfo = SetupDiGetClassDevs(&hidGUID, 0, 0, DIGCF_PRESENT | DIGCF_INTERFACEDEVICE);
if (hDevInfo == INVALID_HANDLE_VALUE)
{
printf("Erreur SetUpDiGetClassDevs\n");
return 0;
}
SP_DEVINFO_DATA DeviceInfoData;
DeviceInfoData.cbSize =
sizeof(SP_DEVINFO_DATA);
int nb = SetupDiEnumDeviceInfo(hDevInfo,0,&DeviceInfoData);
for (
int i=0;SetupDiEnumDeviceInfo(hDevInfo,i,&DeviceInfoData);i++)
{
InterfaceDeviceInfoData.cbSize =
sizeof(SP_INTERFACE_DEVICE_DATA);
DWORD needed;
if (!SetupDiEnumDeviceInterfaces(hDevInfo,NULL,&hidGUID,i,&InterfaceDeviceInfoData))
{
SetupDiDestroyDeviceInfoList(hDevInfo);
printf("erreur setupenumdevice\n");
return 0;
}
//une première fois afin de connaître la taille de la zone mémoire à réserver (needed)
SetupDiGetDeviceInterfaceDetail(hDevInfo,&InterfaceDeviceInfoData,NULL,0,&needed,NULL);
//on réserve la taille mémoire
PSP_DEVICE_INTERFACE_DETAIL_DATA detail = (PSP_INTERFACE_DEVICE_DETAIL_DATA)
new
char[needed];
if (!detail)
{
printf("Problème mémoire PSP_INTERFACE_DEVICE_DETAIL_DATA");
SetupDiDestroyDeviceInfoList(hDevInfo);
return 0;
}
//on cherche le "nom" du device
detail->cbSize =
sizeof(SP_DEVICE_INTERFACE_DETAIL_DATA);
if (!SetupDiGetDeviceInterfaceDetail(hDevInfo,&InterfaceDeviceInfoData,detail,needed,NULL,NULL))
{
delete detail;
printf("Aucune information de détail");
SetupDiDestroyDeviceInfoList(hDevInfo);
return 0;
}
printf("device path %s\n",detail->DevicePath);
HANDLE hCom;
hCom = CreateFile(detail->DevicePath, GENERIC_READ | GENERIC_WRITE, 0, NULL, OPEN_EXISTING, 0, NULL);
DWORD test = GetLastError();
if (hCom == INVALID_HANDLE_VALUE)
{
LPSTR Message;
FormatMessage(FORMAT_MESSAGE_ALLOCATE_BUFFER | FORMAT_MESSAGE_FROM_SYSTEM,NULL,test,
MAKELANGID(LANG_NEUTRAL, SUBLANG_DEFAULT),(LPSTR)&Message,0,NULL);
printf("invalid handle %s\n",Message);
}
else
{
printf("HANDLE Correct\n",hCom);
}
}
SetupDiDestroyDeviceInfoList(hDevInfo);
return 0;
}
par contre mes GUID doivent certainement differé des tiens....
voila mon adresse e-mail au cas tu voudrai deux trois renseignement miguelbouchof@hotmail.com