home *** CD-ROM | disk | FTP | other *** search
/ The Pier Shareware 6 / The_Pier_Shareware_Number_6_(The_Pier_Exchange)_(1995).iso / 046 / dosq1194.exe / POSTMSG.ASM next >
Assembly Source File  |  1994-11-01  |  6KB  |  170 lines

  1. ;******************************************************************************
  2. ; POSTMSG.386 is a simple VxD that allows an MS-DOS application to send
  3. ; messages to a Windows application.
  4. ;
  5. ; Note: The device ID used by POSTMSG is not registered. Therefore, there
  6. ; is no guarantee that it will not conflict with other VxDs, although the
  7. ; possibility of a conflict is remote.
  8. ;******************************************************************************
  9.  
  10.         .386p
  11.  
  12. ;******************************************************************************
  13. ;                             I N C L U D E S
  14. ;******************************************************************************
  15.  
  16.         .XLIST
  17.         INCLUDE VMM.INC
  18.         .LIST
  19.  
  20. ;******************************************************************************
  21. ;                             E Q U A T E S
  22. ;******************************************************************************
  23.  
  24. POSTMSG_Major_Ver   equ     1
  25. POSTMSG_Minor_Ver   equ     0
  26. POSTMSG_Device_ID   equ     4321h
  27. WM_USER             equ     400h
  28.  
  29. ;******************************************************************************
  30. ;              V I R T U A L   D E V I C E   D E C L A R A T I O N
  31. ;******************************************************************************
  32.  
  33. Declare_Virtual_Device POSTMSG,\
  34.                        POSTMSG_Major_Ver,\
  35.                        POSTMSG_Minor_Ver,\
  36.                        POSTMSG_Control,\
  37.                        POSTMSG_Device_ID,\
  38.                        Undefined_Init_Order,\
  39.                        POSTMSG_V86_API_Proc,\
  40.                        POSTMSG_PM_API_Proc
  41.  
  42. ;******************************************************************************
  43. ;                                D A T A
  44. ;******************************************************************************
  45.  
  46. VxD_DATA_SEG
  47.  
  48. hwnd            dw      0           ;Handle of window to receive messages
  49. CallbackOff     dw      ?           ;Offset address of callback function
  50. CallbackSeg     dw      ?           ;Segment address of callback function
  51. wParam          dw      ?           ;wParam
  52. lParamLo        dw      ?           ;Low word of lParam
  53. lParamHi        dw      ?           ;High word of lParam
  54.  
  55. VxD_DATA_ENDS
  56.  
  57. ;******************************************************************************
  58. ;                      P A G E - L O C K E D   C O D E
  59. ;******************************************************************************
  60.  
  61. VxD_LOCKED_CODE_SEG
  62.  
  63. BeginProc POSTMSG_Control
  64.  
  65.         clc
  66.         ret
  67.  
  68. EndProc POSTMSG_Control
  69.  
  70. VxD_LOCKED_CODE_ENDS
  71.  
  72. ;******************************************************************************
  73. ;                               C O D E
  74. ;******************************************************************************
  75.  
  76. VxD_CODE_SEG
  77.  
  78. ;
  79. ; POSTMSG_V86_API_Proc is the exported API procedure that an MS-DOS app
  80. ; calls to post a message to a Windows app. On entry, BX specifies the value
  81. ; of the wParam parameter that will be passed to the Windows app, and DX:AX
  82. ; specifies the value of lParam. On return, carry set means a Windows app
  83. ; has not registered to receive messages.
  84. ;
  85.  
  86. BeginProc POSTMSG_V86_API_Proc
  87.  
  88.         cmp     hwnd,0                          ;Exit now if no Windows app
  89.         je      VP_Error                        ;is registered
  90.  
  91.         mov     ax,[ebp.Client_BX]              ;Save the message parameters
  92.         mov     wParam,ax                       ;passed in the AX, BX, and DX
  93.         mov     ax,[ebp.Client_AX]              ;registers
  94.         mov     lParamLo,ax
  95.         mov     ax,[ebp.Client_DX]
  96.         mov     lParamHi,ax
  97.  
  98.         mov     eax,High_Pri_Device_Boost       ;Schedule a callback event
  99.         VMMcall Get_Sys_VM_Handle               ;for the system VM
  100.         mov     ecx,PEF_Wait_For_STI OR PEF_Wait_Not_Crit
  101.         mov     esi,OFFSET32 POSTMSG_DoCallback
  102.         VMMcall Call_Priority_VM_Event
  103.  
  104.         and     [ebp.Client_EFlags], NOT (CF_MASK)  ;Exit with carry clear
  105.         ret                                         ;indicating success
  106.  
  107. VP_Error:
  108.         or      [ebp.Client_EFlags], CF_MASK    ;Exit with carry set
  109.         ret                                     ;indicating failure
  110.  
  111. EndProc POSTMSG_V86_API_Proc
  112.         
  113. ;
  114. ; POSTMSG_DoCallback posts a message to a Windows app by performing a far
  115. ; call to the app's callback function, which in turn calls PostMessage.
  116. ;       
  117.         
  118. BeginProc POSTMSG_DoCallback
  119.  
  120.         Push_Client_State                       ;Save client registers
  121.         VMMcall Begin_Nest_Exec                 ;Start nested execution block
  122.  
  123.         mov     ax,hwnd                         ;Put PostMessage parameters
  124.         VMMcall Simulate_Push                   ;on the stack in preparation
  125.         mov     ax,WM_USER                      ;for the call
  126.         add     ax,100h
  127.         VMMcall Simulate_Push
  128.         mov     ax,wParam
  129.         VMMcall Simulate_Push
  130.         mov     ax,lParamHi
  131.         VMMcall Simulate_Push
  132.         mov     ax,lParamLo
  133.         VMMcall Simulate_Push
  134.  
  135.         mov     cx,CallbackSeg                  ;Perfor a far call to the
  136.         movzx   edx,CallbackOff                 ;Windows app's callback
  137.         VMMcall Simulate_Far_Call               ;procedure
  138.  
  139.         VMMcall Resume_Exec                     ;Resume execution of this VM
  140.         VMMcall End_Nest_Exec                   ;End nested execution
  141.         Pop_Client_State                        ;Restore client registers
  142.         ret                                     ;Done
  143.  
  144. EndProc POSTMSG_DoCallback
  145.  
  146. ;
  147. ; POSTMSG_PM_API_Proc is the exported API procedure that a protected mode
  148. ; Windows app calls to register itself with POSTMSG. On entry, AX holds the
  149. ; handle of the window to which messages will be posted, and CX:BX holds the
  150. ; segment:offset address of the app's callback procedure, which should be in
  151. ; a fixed, nondiscardable code segment.
  152. ;
  153.  
  154. BeginProc POSTMSG_PM_API_Proc
  155.  
  156.         mov     ax,[ebp.Client_AX]              ;Save the window handle
  157.         mov     hwnd,ax
  158.         mov     ax,[ebp.Client_BX]              ;Save the address of the
  159.         mov     CallbackOff,ax                  ;callback function
  160.         mov     ax,[ebp.Client_CX]
  161.         mov     CallbackSeg,ax
  162.         ret
  163.  
  164. EndProc POSTMSG_PM_API_Proc
  165.  
  166. VxD_CODE_ENDS
  167.  
  168.         END
  169.  
  170.