Is there a way to write to a file from a vxd? something like CreateFile and WriteFile?
Posted on 2002-07-07 07:29:58 by darester
Well... AFAIK you can't, because files are an OS thing, and if you're a VxD you ARE the OS... maybe you can do something like write directly to a disk anyway...

Let me guess: you're trying to debug a VxD and looking for some way to output errors, ne?
Posted on 2002-07-07 20:52:44 by AmkG

Check out the IFSMgr_Ring0_FileIO series of calls in the Win98DDK. I can post more code if you want it, but as an example this is how you might create the file:

; Create the file
mov ebx,02011h ; read/write|share:read/write|no INT24
mov ecx,020h ; archive
mov edx,11h ; create if does not exist / open if exists
mov esi,[edi].pFileName
VxDCall IFSMgr_Ring0_FileIO
jc Exhandler

You'll use these other flags as well.

Posted on 2002-07-07 23:23:08 by Kayaker
thanks for your replies so far.
i'll try this IFSMgr_Ring0_FileIO
Posted on 2002-07-10 05:34:11 by darester
Maybe TrueDPMI functions wiil work from the VXDs? As far as I know they are implemented in all the Win32 versions when you use DPMI from the command line subsystem. But I don't know if interrupt calls are avaiable to VXDs.
Posted on 2002-07-10 05:48:11 by Tomasz Grysztar
well, with Kayakers code, i can successfully open/create the file:

LogFileName DB "C:\Windows\xyzzyx.bin", 0


mov ebx, 02011h
mov ecx, 020h
mov edx, 011
mov esi, OFFSET32 LogFileName
VxDCall IFSMgr_Ring0_FileIO
jc _exit
mov ebx, eax ; ebx = file handle

but when i try to write to the file, it doesn't work (i don't know why, but the file is empty):

mov eax, R0_WRITEFILE
mov ecx, 015h ; length of LogFileName
mov edx, 00h ; start to write at pos. 0
mov esi, OFFSET32 LogFileName
VxDCall IFSMgr_Ring0_FileIO

with this code, nothing happens...why is this? what am i doing wrong?
Posted on 2002-07-10 09:13:37 by darester
The high word of ebx should be set to zero.
Posted on 2002-07-10 12:35:29 by Sephiroth3
if i use the same code as above and change the code where i save the file handle to ebx to the following:

VxDCall IFSMgr_Ring0_FileIO ; open/create file
jc _exit ; error
xor ebx, ebx ;
mov bx, ax ; new save file handle code

i replaced
mov ebx, eax
xor ebx, ebx
mov bx, ax

this causes a bluescreen.

any other suggestions?
Posted on 2002-07-11 09:18:35 by darester
try using TrueDPMI functions:

xor cx,cx
mov edx,offset _file_name
mov ah,3Ch
int 21h
mov ebx,eax
mov edx,offset _data
mov ecx,_data_size
mov ah,40h
int 21h
Posted on 2002-07-11 09:47:25 by Tomasz Grysztar

you cant use int 21h directly in ring 0 in win9x, this works in ring 3 only and not for system vm because there it is trapped by windows to prevent win32 apps using it.

But I wonder why not using the standard functions "BeginNestExec", "ExecInt" and "EndNestExec" for int 21h file functions, at least at appy time. Are there any disadvantages?
Posted on 2002-07-11 10:12:51 by japheth
Oh, I thought I had seen some DPMI calls in the disassembly of one of Win95 built-in VxDs one day, when I was viewing it with HIEW to see the LE executable structure. But I might be wrong.
Posted on 2002-07-11 10:20:33 by Tomasz Grysztar
One caveat with using IFSMgr_Ring0_FileIO is I don't think they can be used from within an interrupt service routine, there seems to be a whole host of reentrancy / asynchronous operation issues with writing to disk from within an ISR. The write operation is apparently queued by the system, but the actual disk i/o occurs later at some undetermined time, giving all sorts of timing problems. Just something to be aware of depending on what you're using this for.

Just out of curiosity, can you use R0_GETFILESIZE or R0_DELETEFILE for example on the opened file, indicating the handle is OK and it's definitely a R0_WRITEFILE problem? Your original code appears to be OK the way you've written it...
Posted on 2002-07-11 10:32:45 by Kayaker