Hello everybody,

I want to write a test program for reading/writing from a USB flash drive.

I am having the usb device path which i got from the api
PSP_DEVICE_INTERFACE_DETAIL_DATA DetailedInterfaceDataStructure ;// structure which get populated through this api.
"SetupDiGetDeviceInterfaceDetail( )"

DetailedInterfaceDataStructure->DevicePath ;

And the value of DevicePath is:
"\\?\usb#vid_058f&pid_6387#00000000#{a5dcbf10-6530-11d2-901f-00c04fb951ed}"

So i have written a sample code and hard coded the device path for opening a file on a usb thumb drive.But when i am using device path concatenated with file name,
"\\\\?\\usb#vid_058f&pid_6387#00000000#{a5dcbf10-6530-11d2-901f-00c04fb951ed}\\test.txt"
the WriteFile() function gives error i.e. "Incorrect parameter"

whereas when i am using path "F:\\test.txt" the same code is working.

This code works with "F:\\test.txt"
doesn't work with "\\\\?\\usb#vid_058f&pid_6387#00000000#{a5dcbf 10-6530-11d2-901f-00c04fb951ed}\\test.txt"

Please check and tell me what is the problem with this device path ?


Code is:

void __cdecl _tmain(int argc, TCHAR *argv[])
{
HANDLE hFile;
char DataBuffer[] = "This is a test string for write operation";
DWORD dwBytesToWrite = (DWORD)strlen(DataBuffer);
DWORD dwBytesWritten = 0;
//const WCHAR FileFullPath[] = {L"\\\\?\\usb#vid_058f&pid_6387#00000000#{a5dcbf 10-6530-11d2-901f-00c04fb951ed}\\test.c"}; Doesn't work

const WCHAR FileFullPath[] = {L"F:\\test.txt"} ; // Works

hFile = CreateFile((LPCTSTR)FileFullPath, // name of the write
GENERIC_WRITE, // open for writing
0, // do not share
NULL, // default security
CREATE_NEW, // overwrite existing
FILE_ATTRIBUTE_NORMAL, // normal file
NULL); // no attr. template

if (hFile == INVALID_HANDLE_VALUE)
{
printf("Could not open file (error %d)\n", GetLastError());
GetError() ;
return;
}
GetError() ;
wprintf(L"Writing %d bytes into %s\n", dwBytesToWrite, FileFullPath) ;


if( FALSE == WriteFile(hFile, // open file handle
DataBuffer, // start of data to write
dwBytesToWrite, // number of bytes to write
&dwBytesWritten, // number of bytes that were written
NULL) // no overlapped structure
)
{
printf("Could not write to file (error %d)\n", GetLastError());
GetError() ;
CloseHandle(hFile);
return;
}
wprintf(L"Wrote %d bytes to %s successfully.\n", dwBytesWritten, FileFullPath);
CloseHandle(hFile);
}