How to call VxD API from application?


   Could anyone please help me with this question:

I am trying to write a simple VxD, which exports a simple API function. For example:

                    mov [ebp.Client_Word_Reg_Struc.Client_DX],1234h
                    mov [ebp.Client_Reg_Struc.Client_EFLAGS],NOT(CF_Mask)

The above code simple returns the value 1234h in DX of the calling VM. I added the name of the API in the DDB, in both the V86_API_PROC and PM_API_PROC macro input, so that this API can be called by both V86 and PM VMs.

To test my API, I wrote a simple program in Visual C++ Win32 Console Application, that has this:

    {    mov  ax,1684h
          mov  bx, 0    ; 0 for Undefined_Device_ID
          int 2fh
          mov  entry,di    ; get the entry point
          mov  entryseg, es

However, what I get is the blue screen Protection Fault. At first I thought my  VxD is faulty, so I tried int 2fh, with ax=1600h. Still, I got the error.

Could anyone tell me what is the real way of calling an API? Is int 2fh permitted in a win32 console application? Or only specific applications with higher priviledge are permitted of calling a VxD API?

Thank you very much.

Yours sincerely,
Who is Participating?

Improve company productivity with a Business Account.Sign Up

jhanceConnect With a Mentor Commented:
Under WIN32 you don't use INT 2F to call into a VxD.  Use DeviceIoControl instead.

Basically the process is:

1) Use CreateFile to open the VxD's virtual device and get a handle to it.

2) Use DeviceIoControl to talk to the VxD.

3) Use CloseHandle() to close the handle when you are done.

Based on the code you've posted above, however, it's unlikely that this will work since your VxD must be written to receive the W32_DEVICEIOCONTROL message that the DeviceIoControl API function generates.

What is your source of information for writing this VxD?  If you are trying to do it just using the DDK, good luck, that is a very incomplete resource.  I'd suggest the book, "Writing Windows VxDs and Device Drivers" by Karen Hazzah and published by R&D Books.
chiehlimAuthor Commented:

   Thanks for the answer. I did look for answers myself and found the same as what you mentioned. Could you give me more details on createfile() and DeviceIOControl()?

   One question about DeviceIOControl() is that, one of the parameters is an address to an input buffer. OK, I am just a beginner to Win32 programming so my question might be a trivial one:

   Do I need to use MAP_FLAT of the VMM service to make the address sent to my VxD into a 32-bit flat model address? In other words, are the addresses sent by my application to my VxD compatible (both 32-bit flat model address?)? I know VxD's use 32-bit flat model, with all selectors using the base address of 0. But what about win32 applications. Are the selectors in win32 applications pointing to the descriptor with base address of 0 as well?

   If you can provide me with this answer, then I will be satisfied. Thanks

Yours sincerely
Any address passed via DeviceIoControl will be a "virtual" address from the point of view of the calling process, but Windows translates this to a physical address for the VxD during the call to DeviceIoControl().  This keeps you from having to mess with mapping the address.

So you might open a VxD like this:

const char *lpszVxD = "\\\\.\\TEST.VXD"
HANDLE hVxD = CreateFile(

Now you have a handle (hVxD) that can be used in a call to DeviceIoControl:

chiehlimAuthor Commented:

    Thank you very much. I tried it out and found that it worked. One last question, how do I specify my path in the createfile function? If my vxd is "c:\masm32\test.vxd", how do I specify in the createfile function?

   I tried "c:\\masm32\\test.vxd" but it didn't work. The error was file already existed. Strange, I put my vxd in the current directory of my calling application, with the same syntax but this time using "\\\\.\\test.vxd", and it worked.

   Thanks again.

Yours sincerely
The \\\\.\\TEST.VXD is not the filesystem pathname to the VxD, it's the specification for the module name.  So for this to work, the VxD file must be in the standard search path.

Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.