L'USB encore et toujours

anthonycosson Messages postés 106 Date d'inscription mercredi 30 mars 2005 Statut Membre Dernière intervention 20 novembre 2009 - 1 févr. 2006 à 17:23
Lutinore Messages postés 3246 Date d'inscription lundi 25 avril 2005 Statut Membre Dernière intervention 27 octobre 2012 - 9 févr. 2006 à 13:24
bonjours a tous je dois creer un programme qui puisse menumerer les ports usb et ensuite pouvoir lire dessus, aucun forums aucun sites n'a pu me procurer un vrai code qui fonctionne, moi meme je n'ai pas reussi ;) donc si quelqu'un sait vraiment comment faire, pourait-il me procurer au moins le code pour recuperer un identifiant du port usb, ca me sauverai la vie merci beaucoup davance tchao :)

4 réponses

Lutinore Messages postés 3246 Date d'inscription lundi 25 avril 2005 Statut Membre Dernière intervention 27 octobre 2012 41
2 févr. 2006 à 06:37
0
anthonycosson Messages postés 106 Date d'inscription mercredi 30 mars 2005 Statut Membre Dernière intervention 20 novembre 2009
9 févr. 2006 à 11:29
bon j'ai trouver quelques sources et en suivant les conseils et sources a la lettre mon code donne ceci mais ca ne marche pas le createfile me retourne toujours un INVALID_HANDLE_VALUE quelqu'un aurait-il une petite idée ???


#include "stdafx.h"


#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 _tmain(
int argc, _TCHAR* argv[])


{


//DEFINIR ICI SON GUID


GUID USBIO_GUID = {0xa5dcbf10, 0x6530, 0x11d2, {0x90, 0x1f, 0x00, 0xc0, 0x4f, 0xb9, 0x51, 0xed}};


#define GUID_STRING "a5dcbf10-6530-11d2-901f-00c04fb951ed"


//


//loop and describe all the matches


//scan the GUID definied in global USBIO_GUID.


//return 0 or 1 (devicename : the first match)


char* DeviceName;



// Get handle to the devices


HDEVINFO hInfo = SetupDiGetClassDevs((LPGUID)&USBIO_GUID, NULL, NULL,


DIGCF_PRESENT | DIGCF_INTERFACEDEVICE);



if (hInfo == INVALID_HANDLE_VALUE)



return(0);


SP_INTERFACE_DEVICE_DATA Interface_Info;


Interface_Info.cbSize =
sizeof(Interface_Info);
// Enumerate device



if (!SetupDiEnumDeviceInterfaces(hInfo, NULL, (LPGUID) &USBIO_GUID,0,


&Interface_Info))


{


SetupDiDestroyDeviceInfoList(hInfo);



return(0);


}


DWORD needed;
// get the required length


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);



return(0);


}



// fill the device details


detail->cbSize =
sizeof(SP_INTERFACE_DEVICE_DETAIL_DATA);



if (!SetupDiGetInterfaceDeviceDetail(hInfo, &Interface_Info, detail,needed,NULL, NULL))


{


free((PVOID) detail);


SetupDiDestroyDeviceInfoList(hInfo);



return(0);


}



//strncpy(DeviceName, detail->DevicePath, MAX_PATH );


free((PVOID) detail);


SetupDiDestroyDeviceInfoList(hInfo);



// return true, USB device found


HANDLE truc;


truc=CreateFile(detail->DevicePath,GENERIC_READ,FILE_SHARE_READ | FILE_SHARE_WRITE,NULL,OPEN_EXISTING,0,NULL);



if(truc==INVALID_HANDLE_VALUE)


printf("erreur");



else


printf("ca marche");



return(1);
0
Lutinore Messages postés 3246 Date d'inscription lundi 25 avril 2005 Statut Membre Dernière intervention 27 octobre 2012 41
9 févr. 2006 à 13:22
Je t'ai indiqué une librairie en code managé si tu fais du C/C++ faut mieux poser ta question sur www.cppfrance.com.
0
Lutinore Messages postés 3246 Date d'inscription lundi 25 avril 2005 Statut Membre Dernière intervention 27 octobre 2012 41
9 févr. 2006 à 13:24
Ca recommence ça m'écrit encore mon texte en gras, je sais pas pourquoi..
0
Rejoignez-nous