WriteFile oddity

Tech Tip: Click here to run a free scan for Windows Errors and optimize PC performance



For physically writing on a USB stick I use the functions "CreateFile"
and then "WriteFile" on the basis
of the handle returned by CreateFile. I call "Write File" with
standard parameters, i.e. Generic_Write /
File_Share_Read or File_Share_Write / Open_Existing.

While these functions work properly when physically writing on the
volume or on the partition via
"CreateFile('\\{drive letter}:',.....)" and write data exactly
according to instructions, the writing
process fails when opening the physical drive via
"CreateFile('PhysicalDrive{drive number}',.....)".
As in some cases I want to write the MBR but am unable to address it
via the volume, I also need this
call.

What is particularly odd is that, officially, no error occurs.
CreateFile returns a valid handle and
WriteFile returns both "true" and a number of (allegedly) written
bytes, which exactly corresponds
to the requested number in the WriteFile command.

However, *nothing at all* is written on the USB stick. Is this problem
already known or has anybody
noticed a similar conduct? By the way, dismounting or locking the
target drive does not change the
described conduct in any way. The problem occurs on different
computers, with different USB sticks and
both under XP and under Vista all alike.

I would be very grateful for receiving field reports or solutions to
the problem.

.



Relevant Pages

  • Re: developing Application software for a host to communicate with a USB device
    ... I have seen use of Createfile, ... Writefile, & Readfile functions to communicate with the USB peripheral. ... If we need to send the token packets by the software then how is it done? ...
    (comp.arch.embedded)
  • Re: USB Testing
    ... I have no idea if the port is displayed in a GUI or is in the ... Trying to do a CreateFile in XP...As I said above, ... As for using CreateFilefrom XP, I used the device ID for the USB ... WCEUSBSH driver to load. ...
    (microsoft.public.windowsce.platbuilder)
  • Re: SECURITY_ATTRIBUTES declaration for CreateFile
    ... but I got to a point where WriteFile would decide to ... the file it is still opened by "TAPI3". ... com1File = CreateFile(_ ...
    (microsoft.public.vb.winapi)
  • Re: Bidirectional communication to USB printer
    ... Maybe you have more then one instance of this printer in your registry and ... CreateFile(), ... > WriteFileand CloseHandle() run successfully and all the bytes are ... > written (at least WriteFile() reports this). ...
    (microsoft.public.development.device.drivers)
  • Writefile: the parameter is incorrect
    ... private static extern bool WriteFile( ... handle = CreateFile( ...
    (microsoft.public.dotnet.framework.interop)