VxD Programming Hints


This contains answers to questions many people have when doing VxD programming. If you know something that may help people, please email me.

Last updated Aug 5, 1998


How to open a file in a VxD

There are two methods to open a file in a VxD. If you are using VToolsD, there is a function R0_ReadFile that can be used for this. If you aren't, there is a IFS manager service, IFSMgr_Ring0_FileIO. See the help file for more documentation.


How to tell if a VxD is loaded

If you are trying to detect the VxD from a Win32 executable, there is a method using CreateFile.

The key is to open the device name, not the VxD name. This is the name used in the Declare_Virtual_Device macro.

Example:
Check if the vxd "vxdmy.vxd" is loaded. This vxd has a device name of MYVXD.

hDevice = CreateFile("\\\\.\\MYVXD", 0, 0, NULL, 0, 0, NULL);
If the CreateFile call fails, vxdmy.vxd isn't loaded.

How to load a static vxd

Thanks to Gregg Conklin and Ripon Bhattacharjee for information about the KnownVxDs registry key.

Static VxD's are loaded on Windows startup, and stay loaded until Windows shutdown. There are three ways to do this:

  1. Place the driver name in the system.ini file. It will be in the 386Enh section.

    Example:
    Load myvxd.vxd from the system.ini file.

    [386Enh]
    device=myvxd.vxd
    
  2. Place the driver name in the registry. There are two possible paths to place them. One key will be under this path:
    [HKEY_LOCAL_MACHINE\System\CurrentControlSet\control\SessionManager\KnownVxDs]
    The keyname will be the device name, and the value will be the path. So, a vxd with a device name of AVXD, and a driver name of myvxd.vxd, located in the system directory would look like:
    "AVXD"="C:\\WINDOWS\\SYSTEM\\MYVXD.VXD"
    
    The other path is:
    [HKEY_LOCAL_MACHINE\System\CurrentControlSet\Services\VxD]
    
    The keynames are dependent on the type of driver.
  3. The last way is to have a TSR load the driver when Windows starts. This method is much more complicated than the last 2. If a TSR is written to run during Windows operation, chances are it has hooked interrupt 2F. When that function is called, check for function 1605h, Windows Initialization Notification. Windows calls this function to tell all MS-DOS programs that Windows is now starting. Now a Win386_Startup_Info_Struc structure can be initialized and the address of the structure should be placed in the ES:BX register pair. The part of the structure that is concerned with VxD's is SIS_Virt_Dev_File_Ptr. That member should hold the address of the name, or the path and name of the vxd. If data should be sent to the VxD, place the address in SIS_Reference_Data.

Go to driver annotation page