Problems with WriteFile

Trips

Well-known member
Joined
Aug 7, 2010
Messages
2,788
 
Hi
Im writing an application in Visual C++ and MFC which will comunicate with an embedded device via USB. I can open the file successfully with CreateFile, but WriteFile and CloseHandle both return the code ERROR_INVALID_HANDLE. Im not using overlapped code.
My code is:
HANDLE hTmp;
 DWORD NumBytesWritten;
 DWORD num_bytes_to_write;
 LPCVOID out_buffer;
 UpdateData(TRUE);
 num_bytes_to_write = str_Message.GetLength();
 out_buffer = str_Message;
 hTmp = CreateFile("<a>\\?\usb#vid_8765&pid_1234#13245678#{54654e76-dcf7-4a7f-878a-4e8fca0acc9a }",
      GENERIC_READ|GENERIC_WRITE, FILE_SHARE_READ | FILE_SHARE_WRITE, NULL, OPEN_EXISTING, 0, NULL);
 DWORD Error_0 = GetLastError();
 WriteFile(hTmp, out_buffer, num_bytes_to_write, &NumBytesWritten, NULL);
 DWORD Error_1 = GetLastError();
 CloseHandle(hTmp);
 DWORD Error_2 = GetLastError();
Can someone please advise me to what could be going wrong.
Thanks in advance
Andrew Ellis

View the full article
 
Back
Top