I'm writing a program to make an exact duplicate of a floppy disk. I call the CreateFile API function with "\\.A:" and it attempts to read from the disk but it returns INVALID_FILE_HANDLE. I would greatly appreciate any help on why this won't work. Also I'm running Windows ME (Yeah I know I hate it too s/k). Does this method not work on my platform? I know that there is a way to read disk sectors because WinHex and many other programs do it. TIA to anyone gracious enough to help me out w/this. :)
Posted on 2002-03-02 23:56:26 by vertsk8ta2001
The rest of your CreateFile() call parameters would be helpful.
Posted on 2002-03-03 00:04:11 by comrade
Right... sorry.

here is an excerpt from the prog. (If you need the whole thing, thats not a prob its only about 17Kb zipped)


DiskName db "\\.\A:",0
InvHVal db "Invalid Handle Value!",0

hInstance HINSTANCE ?
CommandLine LPSTR ?
hfReadFile HFILE ?
buffer db 512 dup(?)
var1 DWORD ?


; .
; .
; .

;;; WinMain() and the usual stuff
; .
; .
; .

diskIO proc

mov hfReadFile,eax

;; The CreateFile() above always returns INVALID_HANDLE_VALUE ;;

invoke MessageBox,NULL,ADDR InvHVal,ADDR AppName,MB_OK

invoke ReadFile, hfReadFile, ADDR buffer, 512, ADDR var1, NULL

invoke CloseHandle, hfReadFile

diskIO endp

end start
Posted on 2002-03-03 00:17:53 by vertsk8ta2001
Shouldn't that be \\?\A:\myfiles\Filename.extension (just a sample)

I don't know! Try it! :)
Posted on 2002-03-03 00:22:11 by stryker
I know that works for files but I'm trying to get a handle to the floppy disk device itself. (so I can copy non-FAT formatted disks like my Linux boot disk and such) I want it to be more of a disk imaging program. Thanx tho.
Posted on 2002-03-03 00:30:29 by vertsk8ta2001
Did you try a simple "A:", Win95 doesn't allow this. Or \\\\.\\vwin32 ... if I remember it correctly. It has something to with vwin32.vxd and try searching for vwin32.inc. I can't remember the files. :(

If your using win95 (win98?) : I think you need to use vwin32 then use DeviceIOControl

On NT: You can directly use A: ... then DeviceIOControl

Something like this...Can't remember! (I must have an alzheimer)
Posted on 2002-03-03 00:56:07 by stryker
Yeah, I tried "A:" and that dosn't work either. I'm looking up a buncha crap about DeviceIOCrtl on MSDN now. I hope this works. Oh how I long for the days of Int 13h but that won't work on win32. Oh man.... it's late. Goodnight all.

P.S. thanks to all the nice ppl out there for helping a (semi)newbie ;)
Posted on 2002-03-03 01:27:59 by vertsk8ta2001
Using \\.\A: directly only works under winNT.

Posted on 2002-03-03 03:30:16 by Thomas
As Thomas said... you should read your API reference :). As for
direct floppy access under 9x, search the board, there have been
a fair amount of posts about this.
Posted on 2002-03-03 14:02:54 by f0dder
i've been working on a similar project for quite some time now, here are some snippets of code you may find useful, though i'm not sure if they work as i haven't been able to do any testing. in winnt/2k/xp you can simply use createfile with "\\.\A:" and then use normal readfile and writefile calls to access the device. in win9x however, you have to use createfile with "\\.\VWIN32", save the handle, and do low level (int 25/26) calls with deviceiocontrol. here is a code snippet i have for reading the entire floppy to a file on the hard drive...

xor ecx,ecx
mov Regs.reg_EAX,0
mov Regs.reg_ECX,0
mov Regs.reg_EDI,0
push dword ptr dBuff
pop Regs.reg_EBX
push ecx
mov Regs.reg_EDX,ecx
invoke DeviceIoControl,hMem,VWIN32_DIOC_DOS_INT25,addr Regs,sizeof Regs,addr Regs,sizeof Regs,addr dBytesRead,NULL ;read from disk, store in dBuff
cmp byte ptr Regs.reg_EAX+1,0
jne error
invoke WriteFile,hImage,addr dBuff,512,addr dBytesWrite,NULL ;write dBuff to the file
pop ecx
inc ecx
.until ecx == 2880

Regs is a DIOCRegs struct, which is like this..

DIOCRegs STRUCT ;for DeviceIoControl calls
reg_EBX dd ?
reg_EDX dd ?
reg_ECX dd ?
reg_EAX dd ?
reg_EDI dd ?
reg_ESI dd ?
reg_Flags dd ?

dBuff db 512 dup(?) ;another important one, this stores the data

anyway, as i said, i'm not sure if it works or not, and i left out a few things. hMem is the handle of "\\.\VWIN32" as opened by createfile and hImage is the handle of the file you wish to save the data to. other than that, i think you should be ok. hope this helps!
Posted on 2002-03-04 16:50:42 by mc`