CE.A
CE.A

Reputation: 11

WriteFile() Error 3758100489 with Usb Device

I have a project to communicate with a usb device using usb bus. The device has its own driver and a communication protokol Guid . In its guid there is this senetence :"After USB driver is installed any program can communicate with the device by using ‘CreateFile’, ‘ReadFile’ and ‘WriteFile’, common Windows system functions." So I followed the instructions and the Creatfile() function works very well. My problem is with Writefile()and ReadFile functions. It shows always this Error 3758100489 : In the guid book there is this note:All messages use Intel style byte ordering where fields larger than one byte are stored in memory so that the least significant part is in lowest address. So i tried to use functions to convert to littel Endien too I tried to use overlapped parameter in Creatfile() and Writefile() but still have the same problem. i tried to use many forms of message packet with help from the guid too

Can anyone help me ? thank you very much

P.s USB path is right 100%

Upvotes: 1

Views: 244

Answers (2)

Wander3r
Wander3r

Reputation: 1881

Your error code in hex is 0xE0001009. The USB device should be locked before you can perform the operation. I am not completely sure and can't test it, but I think you would need this function DeviceIoControl to lock the volume first.

In WriteFile documentation, it's mentioned

A write on a disk handle will succeed if one of the following conditions is true:

  • The sectors to be written to do not fall within a volume's extents.
  • The sectors to be written to fall within a mounted volume, but you have explicitly locked or dismounted the volume by using FSCTL_LOCK_VOLUME or FSCTL_DISMOUNT_VOLUME.

This article could help in making the call for locking.

Upvotes: 1

Alessandro Jacopson
Alessandro Jacopson

Reputation: 18593

Try to get more info about 3758100489.

See Retrieving the Last-Error Code or try to build and run the following program which should show you a human readable description of error 3758100489:

#include <windows.h>
#include <strsafe.h>

void main()
{
    LPVOID lpMsgBuf;
    LPVOID lpDisplayBuf;
    //DWORD dw = GetLastError();
    DWORD dw = 3758100489; 

    FormatMessage(
        FORMAT_MESSAGE_ALLOCATE_BUFFER | 
        FORMAT_MESSAGE_FROM_SYSTEM |
        FORMAT_MESSAGE_IGNORE_INSERTS,
        NULL,
        dw,
        MAKELANGID(LANG_NEUTRAL, SUBLANG_DEFAULT),
        (LPTSTR) &lpMsgBuf,
        0, NULL );

    // Display the error message and exit the process

    lpDisplayBuf = (LPVOID)LocalAlloc(LMEM_ZEROINIT, 
        lstrlen((LPCTSTR)lpMsgBuf) ); 
    StringCchPrintf((LPTSTR)lpDisplayBuf, 
        LocalSize(lpDisplayBuf) / sizeof(TCHAR),
        TEXT("failed with error %d: %s"), 
         dw, lpMsgBuf); 
    MessageBox(NULL, (LPCTSTR)lpDisplayBuf, TEXT("Error"), MB_OK); 

    LocalFree(lpMsgBuf);
    LocalFree(lpDisplayBuf);
}

Upvotes: 0

Related Questions