|
-
June 22nd, 2009, 01:38 AM
#1
Problem with USB device path
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);
}
Similar Threads
-
By timbo19572804 in forum USB/Firewire
Replies: 5
Last Post: March 13th, 2008, 03:31 PM
-
By Sadie_X in forum Sound Card Drivers
Replies: 23
Last Post: July 5th, 2006, 11:01 PM
-
By bwbeye in forum USB/Firewire
Replies: 1
Last Post: April 10th, 2006, 10:55 AM
-
By leduarte in forum USB/Firewire
Replies: 0
Last Post: March 30th, 2005, 09:47 AM
-
By Marinero in forum USB/Firewire
Replies: 14
Last Post: May 8th, 2004, 07:23 AM
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
|
Bookmarks