Click here to Skip to main content
15,889,034 members
Home / Discussions / C / C++ / MFC
   

C / C++ / MFC

 
AnswerRe: How to read USB type Disk Drive device? Pin
Albert Holguin1-Mar-12 11:26
professionalAlbert Holguin1-Mar-12 11:26 
GeneralRe: How to read USB type Disk Drive device? Pin
Le@rner1-Mar-12 18:04
Le@rner1-Mar-12 18:04 
GeneralRe: How to read USB type Disk Drive device? Pin
Albert Holguin1-Mar-12 18:52
professionalAlbert Holguin1-Mar-12 18:52 
GeneralRe: How to read USB type Disk Drive device? Pin
Le@rner1-Mar-12 20:53
Le@rner1-Mar-12 20:53 
QuestionRe: How to read USB type Disk Drive device? Pin
David Crow2-Mar-12 2:41
David Crow2-Mar-12 2:41 
AnswerRe: How to read USB type Disk Drive device? Pin
Le@rner4-Mar-12 17:55
Le@rner4-Mar-12 17:55 
SuggestionRe: How to read USB type Disk Drive device? Pin
David Crow5-Mar-12 2:29
David Crow5-Mar-12 2:29 
GeneralRe: How to read USB type Disk Drive device? Pin
Le@rner5-Mar-12 18:56
Le@rner5-Mar-12 18:56 
C++
	HDEVINFO        hDevInfo, hIntDevInfo;
    BOOL            disk_status=FALSE;


    hDevInfo = SetupDiGetClassDevs(
                    (LPGUID) &GUID_DEVCLASS_DISKDRIVE,
                    NULL,
                    NULL, 
                    DIGCF_PRESENT  ); // All devices present on system
    if (hDevInfo == INVALID_HANDLE_VALUE)
    {
       
        return 0;
    }

   
    hIntDevInfo = SetupDiGetClassDevs (
                 (LPGUID)&GUID_DEVCLASS_DISKDRIVE,
                 NULL,                                   // Enumerator
                 NULL,                                   // Parent Window
                 (DIGCF_PRESENT | DIGCF_INTERFACEDEVICE  // Only Devices present & Interface class
                 ));

    if( hDevInfo == INVALID_HANDLE_VALUE ) 
	{
        
        return 0;
	}

	SP_DEVICE_INTERFACE_DATA            interfaceData;
    PSP_DEVICE_INTERFACE_DETAIL_DATA    interfaceDetailData = NULL;
   
    PUCHAR                              disk_p;
    UCHAR                               outBuf[512];
    ULONG                               length = 0,
                                        returned = 0,
                                        returnedLength=0;
    DWORD                               interfaceDetailDataSize,
                                        reqSize,
                                        errorCode, 
                                        disk_i=0;


	DWORD Index=0;

    interfaceData.cbSize = sizeof (SP_INTERFACE_DEVICE_DATA);

    disk_status = SetupDiEnumDeviceInterfaces ( 
                hIntDevInfo,             // Interface Device Info handle
                0,                      // Device Info data
                (LPGUID)&GUID_DEVCLASS_DISKDRIVE, // Interface registered by driver
                Index,                  // Member
                &interfaceData          // Device Interface Data
                );

    if ( disk_status == FALSE ) 
	{
        errorCode = GetLastError();
        if ( errorCode == ERROR_NO_MORE_ITEMS ) 
		{
            //No more interfaces
        }
        else 
		{
            //SetupDiEnumDeviceInterfaces failed 
        }
        return 0;
    }
        
    

    disk_status = SetupDiGetDeviceInterfaceDetail (
                hIntDevInfo,         // Interface Device info handle
                &interfaceData,     // Interface data for the event class
                NULL,               // Checking for buffer size
                0,                  // Checking for buffer size
                &reqSize,           // Buffer size required to get the detail data
                NULL                // Checking for buffer size
                );

   

    if ( disk_status == FALSE ) 
	{
        errorCode = GetLastError();
        if ( errorCode != ERROR_INSUFFICIENT_BUFFER ) {
            //SetupDiGetDeviceInterfaceDetail failed 
            return 0;
        }
    }

   

    interfaceDetailDataSize = reqSize;
    
	interfaceDetailData = (PSP_DEVICE_INTERFACE_DETAIL_DATA) malloc (interfaceDetailDataSize);
    
	if ( interfaceDetailData == NULL ) 
	{
        
        return 0;
    }
    interfaceDetailData->cbSize = sizeof (SP_INTERFACE_DEVICE_DETAIL_DATA);

    disk_status = SetupDiGetDeviceInterfaceDetail (
                  hIntDevInfo,               // Interface Device info handle
                  &interfaceData,           // Interface data for the event class
                  interfaceDetailData,      // Interface detail data
                  interfaceDetailDataSize,  // Interface detail data size
                  &reqSize,                 // Buffer size required to get the detail data
                  NULL);                    // Interface device info

    if ( disk_status == FALSE ) {
        
        return 0;
    }

   

    serial_handle = CreateFile(
                interfaceDetailData->DevicePath,    // device interface name
                GENERIC_READ | GENERIC_WRITE,       // dwDesiredAccess
                FILE_SHARE_READ | FILE_SHARE_WRITE, // dwShareMode
                NULL,                               // lpSecurityAttributes
                OPEN_EXISTING,                      // dwCreationDistribution
                0,                                  // dwFlagsAndAttributes
                NULL                                // hTemplateFile
                );

Open device successfullt, but read file return 0;

success = ReadFile(serial_handle,&rxBuffer,max_rx_size,&read_nbr,NULL);


please help me where i m wrong
GeneralRe: How to read USB type Disk Drive device? Pin
David Crow6-Mar-12 2:32
David Crow6-Mar-12 2:32 
GeneralRe: How to read USB type Disk Drive device? Pin
Le@rner6-Mar-12 17:15
Le@rner6-Mar-12 17:15 
QuestionRe: How to read USB type Disk Drive device? Pin
David Crow6-Mar-12 17:53
David Crow6-Mar-12 17:53 
AnswerRe: How to read USB type Disk Drive device? Pin
Le@rner12-Mar-12 20:41
Le@rner12-Mar-12 20:41 
QuestionRe: How to read USB type Disk Drive device? Pin
David Crow13-Mar-12 3:18
David Crow13-Mar-12 3:18 
Questioncreate statusBar in dialog problem Pin
appollosputnik29-Feb-12 15:31
appollosputnik29-Feb-12 15:31 
AnswerRe: create statusBar in dialog problem Pin
chenxi_129-Feb-12 18:00
chenxi_129-Feb-12 18:00 
AnswerRe: create statusBar in dialog problem Pin
Chandrakantt29-Feb-12 18:53
Chandrakantt29-Feb-12 18:53 
GeneralRe: create statusBar in dialog problem Pin
appollosputnik1-Mar-12 0:19
appollosputnik1-Mar-12 0:19 
QuestionMenu items disabled but appear enabled Pin
cpp_prgmer29-Feb-12 9:27
cpp_prgmer29-Feb-12 9:27 
QuestionRe: Menu items disabled but appear enabled Pin
David Crow29-Feb-12 9:56
David Crow29-Feb-12 9:56 
AnswerRe: Menu items disabled but appear enabled Pin
cpp_prgmer29-Feb-12 10:56
cpp_prgmer29-Feb-12 10:56 
GeneralRe: Menu items disabled but appear enabled Pin
Maximilien29-Feb-12 13:57
Maximilien29-Feb-12 13:57 
GeneralRe: Menu items disabled but appear enabled Pin
cpp_prgmer1-Mar-12 3:56
cpp_prgmer1-Mar-12 3:56 
QuestionRe: Menu items disabled but appear enabled Pin
Randor 29-Feb-12 17:47
professional Randor 29-Feb-12 17:47 
AnswerRe: Menu items disabled but appear enabled Pin
rana ray1-Mar-12 5:46
rana ray1-Mar-12 5:46 
GeneralRe: Menu items disabled but appear enabled Pin
cpp_prgmer1-Mar-12 14:37
cpp_prgmer1-Mar-12 14:37 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.