| 12
 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
 73
 74
 75
 76
 77
 78
 79
 80
 81
 82
 83
 84
 85
 86
 87
 88
 89
 90
 91
 92
 93
 94
 95
 96
 97
 98
 99
 100
 101
 102
 103
 104
 105
 106
 
 | GUID hidGUID = {0x53f56307, 0xb6bf, 0x11d0, {0x94, 0xf2, 0x00, 0xa0, 0xc9, 0x1e, 0xfb, 0x8b}};
//GUID hidGUID = {0xa5dcbf10, 0x6530, 0x11d2, {0x90, 0x1f, 0x00, 0xc0, 0x4f, 0xb9, 0x51, 0xed}};
	HDEVINFO hardwareDeviceInfoSet;
    SP_DEVICE_INTERFACE_DATA deviceInterfaceData;
    PSP_INTERFACE_DEVICE_DETAIL_DATA deviceDetail;
    ULONG requiredSize;
    HANDLE deviceHandle = INVALID_HANDLE_VALUE;
    DWORD result;
    //Get the HID GUID value - used as mask to get list of devices
//    HidD_GetHidGuid (&hidGUID);
    //Get a list of devices matching the criteria (hid interface, present)
    hardwareDeviceInfoSet = SetupDiGetClassDevs (&hidGUID,
                                                 NULL, // Define no enumerator (global)
                                                 NULL, // Define no
                                                 (DIGCF_PRESENT | // Only Devices present
                                                 DIGCF_DEVICEINTERFACE)); // Function class devices.
    deviceInterfaceData.cbSize = sizeof(SP_DEVICE_INTERFACE_DATA);
    //Go through the list and get the interface data
    result = SetupDiEnumDeviceInterfaces (hardwareDeviceInfoSet,
                                          NULL, //infoData,
                                          &hidGUID, //interfaceClassGuid,
                                          0, //changement
                                          &deviceInterfaceData);
    /* Failed to get a device - possibly the index is larger than the number of devices */
    if (result == FALSE)
    {
        SetupDiDestroyDeviceInfoList (hardwareDeviceInfoSet);
//        return INVALID_HANDLE_VALUE;
    }
    //Get the details with null values to get the required size of the buffer
    SetupDiGetDeviceInterfaceDetail (hardwareDeviceInfoSet,
                                     &deviceInterfaceData,
                                     NULL, //interfaceDetail,
                                     0, //interfaceDetailSize,
                                     &requiredSize,
                                     0); //infoData))
    //Allocate the buffer
    deviceDetail = (PSP_INTERFACE_DEVICE_DETAIL_DATA)malloc(requiredSize);
    deviceDetail->cbSize = sizeof(SP_INTERFACE_DEVICE_DETAIL_DATA);
    //Fill the buffer with the device details
    if (!SetupDiGetDeviceInterfaceDetail (hardwareDeviceInfoSet,
                                          &deviceInterfaceData,
                                          deviceDetail,
                                          requiredSize,
                                          &requiredSize,
                                          NULL)) 
    {
        SetupDiDestroyDeviceInfoList (hardwareDeviceInfoSet);
        free (deviceDetail);
//        return INVALID_HANDLE_VALUE;
    }
    //Open file on the device
    deviceHandle = CreateFile (deviceDetail->DevicePath,
                               GENERIC_READ,
                               FILE_SHARE_READ | FILE_SHARE_WRITE,
                               NULL,        // no SECURITY_ATTRIBUTES structure
                               OPEN_EXISTING, // No special create flags
                               0, 
                               NULL);       // No template file
	if(deviceHandle==INVALID_HANDLE_VALUE)
			printf("erreur\n");
		else
			printf("ca marche\n");
printf("device : %s\n",deviceDetail->DevicePath);
/*
char* buffer;
DWORD nb_caractere;
printf("lecture\n");
COMMTIMEOUTS Timeout;
Timeout.ReadTotalTimeoutConstant=10000;
Timeout.WriteTotalTimeoutConstant=0;
Timeout.WriteTotalTimeoutMultiplier=0;
SetCommTimeouts(deviceHandle,&Timeout);
int testread;
testread=ReadFile(deviceHandle,buffer,2048,&nb_caractere,NULL);
if(testread==0)
printf("erreur read %d\n",testread);
else
printf("contenu : %s\n",buffer);
if(GetLastError()==ERROR_HANDLE_EOF)
printf("ERROR_HANDLE_EOF");
if(GetLastError()==ERROR_IO_PENDING)
printf("ERROR_IO_PENDING");
*/
DWORD z;
if(WriteFile(deviceHandle,"coucou",6,&z,NULL)==0)
printf("erreur");
SetupDiDestroyDeviceInfoList (hardwareDeviceInfoSet);
free (deviceDetail); | 
Partager