SAMPLE: Calling PostMessage from a Virtual Device (VxD)

Last reviewed: February 15, 1996
Article ID: Q72899
The information in this article applies to:
  • Microsoft Windows Device Driver Kit (DDK) for Windows versions 3.0 and 3.1

SUMMARY

In the Microsoft Windows graphical environment, a virtual device (VxD) can indirectly call the PostMessage function. This enables any virtual machine (VM) to communicate with the system VM. The text below briefly describes the steps necessary for this communication. For more information, refer to the VPOSTD file, which implements the techniques discussed below.

Download VPOSTD.EXE, a self-extracting file, from the Microsoft Software Library (MSL) on the following services:

  • Microsoft Download Service (MSDL)

          Dial (206) 936-6735 to connect to MSDL
          Download VPOSTD.EXE (size: 36023 bytes) 
    
  • Internet (anonymous FTP)

          ftp ftp.microsoft.com
          Change to the \softlib\mslfiles directory
          Get VPOSTD.EXE (size: 36023 bytes) 
    

MORE INFORMATION

Although a VxD cannot directly call the PostMessage function, a VxD can call a callback function in a Windows dynamic-link library (DLL), which can in turn call PostMessage.

To accomplish this communication, the callback function called by the VxD must reside in a FIXED code segment of a DLL. Any data accessed by the callback routine must be placed in a FIXED data segment. This is necessary because the callback routine is very similar to an interrupt service routine (ISR). Required code and data must be available in memory at all times. FIXED code and data segments of a Windows DLL are page locked by the Windows memory manager, which keeps the segments present in memory. The callback routine can call only the PostMessage and PostAppMessage functions, because these are the only reentrant Windows functions. The DLL can't call any other Windows functions.

To communicate with the system VM, the VxD must provide a protected mode API through which the DLL can register the address of its callback function. When the VxD receives an event that generates a message, the VxD schedules the system VM for execution. It may also be necessary to wait for the critical section to be free and for interrupts to be enabled. The virtual machine manager (VMM) provides a service called Call_Priority_VM_Event, which is designed for situations such as this.

When the System VM is scheduled and is in an appropriate state, the VxD can use the VMM service Simulate_Far_Call to call the DLL, which can then call PostMessage.

Refer to the "Microsoft Windows Device Driver Kit: Virtual Device Adaptation Guide" (VDAG) for documentation on the VMM services. VPOSTD provides the full source listing for a VxD and DLL, which demonstrates everything required to implement the architecture discussed above.


Additional reference words: 3.00 3.10 DDKVXD softlib VPOSTD.EXE
KBCategory: kbprg kbfile
KBSubcategory: DthreeMiscWinapps


THE INFORMATION PROVIDED IN THE MICROSOFT KNOWLEDGE BASE IS PROVIDED "AS IS" WITHOUT WARRANTY OF ANY KIND. MICROSOFT DISCLAIMS ALL WARRANTIES, EITHER EXPRESS OR IMPLIED, INCLUDING THE WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. IN NO EVENT SHALL MICROSOFT CORPORATION OR ITS SUPPLIERS BE LIABLE FOR ANY DAMAGES WHATSOEVER INCLUDING DIRECT, INDIRECT, INCIDENTAL, CONSEQUENTIAL, LOSS OF BUSINESS PROFITS OR SPECIAL DAMAGES, EVEN IF MICROSOFT CORPORATION OR ITS SUPPLIERS HAVE BEEN ADVISED OF THE POSSIBILITY OF SUCH DAMAGES. SOME STATES DO NOT ALLOW THE EXCLUSION OR LIMITATION OF LIABILITY FOR CONSEQUENTIAL OR INCIDENTAL DAMAGES SO THE FOREGOING LIMITATION MAY NOT APPLY.

Last reviewed: February 15, 1996
© 1998 Microsoft Corporation. All rights reserved. Terms of Use.