Solved

How to call VxD API from application?

Posted on 2000-04-06
5
276 Views
Last Modified: 2013-12-03
Hi,

   Could anyone please help me with this question:

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

   BeginProc VSIMPLE_API_Proc, PUBLIC
                    mov [ebp.Client_Word_Reg_Struc.Client_DX],1234h
                    mov [ebp.Client_Reg_Struc.Client_EFLAGS],NOT(CF_Mask)
                    clc
                    ret
   EndProc VSIMPLE_API_PROC

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:

    _asm
    {    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,
Stephen
0
Comment
Question by:chiehlim
  • 3
  • 2
5 Comments
 
LVL 32

Accepted Solution

by:
jhance earned 90 total points
ID: 2693008
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.
0
 

Author Comment

by:chiehlim
ID: 2695928
Hi,

   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
Stephen
0
 
LVL 32

Expert Comment

by:jhance
ID: 2695981
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(
  lpszVxD,
  0,
  0,
  0,
  CREATE_NEW,
  FILE_FLAG_DELETE_ON_CLOSE,
  0
);


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

DeviceIoControl(
  hVxD,
  YOUR_DEVICE_CONTROL_CODE,
  (LPVOID)&InBuffer,
  dwInBufferSize,
  (LPVOID)&OutBuffer,
  dwOutBufferSize,
  &dwBytesReturned,
  NULL
);
0
 

Author Comment

by:chiehlim
ID: 2697361
Hi,

    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
Stephen
0
 
LVL 32

Expert Comment

by:jhance
ID: 2697507
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.

See:

http://msdn.microsoft.com/library/psdk/win95/devio_886c.htm
0

Featured Post

Salesforce Made Easy to Use

On-screen guidance at the moment of need enables you & your employees to focus on the core, you can now boost your adoption rates swiftly and simply with one easy tool.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

What my article will show is if you ever had to do processing to a listbox without being able to just select all the items in it. My software Visual Studio 2008 crystal report v11 My issue was I wanted to add crystal report to a form and show…
For most people, the WrapPanel seems like a magic when they switch from WinForms to WPF. Most of us will think that the code that is used to write a control like that would be difficult. However, most of the work is done by the WPF engine, and the W…
This is Part 3 in a 3-part series on Experts Exchange to discuss error handling in VBA code written for Excel. Part 1 of this series discussed basic error handling code using VBA. http://www.experts-exchange.com/videos/1478/Excel-Error-Handlin…
This video shows how to use Hyena, from SystemTools Software, to bulk import 100 user accounts from an external text file. View in 1080p for best video quality.

830 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question