WIN16APP.C
上传用户:lx1888888
上传日期:2007-01-04
资源大小:136k
文件大小:2k
源码类别:

驱动编程

开发平台:

Visual C++

  1. #include <string.h>
  2. #include <windows.h>
  3. #include "dmabuf.h"
  4. typedef void (far * PVOIDFN)( void );
  5. static char MsgBoxBuf[ 1024 ] = { 0 };
  6. PVOIDFN  pfDmaBufApi;
  7. DMA_BUFFER_DESCRIPTOR dmadesc;
  8. PVOIDFN GetVxdApiEntry( int VxdId )
  9. {
  10.   PVOIDFN pfApi;
  11.   _asm
  12.   {
  13.      xor di, di
  14.      mov es, di
  15.      mov bx, VxdId
  16.      mov ax, 1684h
  17.      int 2fh
  18.      mov WORD PTR pfApi+2, es
  19.      mov WORD PTR pfApi, di
  20.   }
  21.   return( pfApi );
  22. }
  23. int PASCAL WinMain( HANDLE hInstance, HANDLE hPrevInstance, 
  24.                     LPSTR lpCmdLine, int nCmdShow )
  25. {
  26. char far *DmaBufPtr;
  27. unsigned short usSel, myds;
  28.    WORD  err;
  29. pfDmaBufApi = GetVxdApiEntry( DMABUF_ID );
  30. if (!pfDmaBufApi)
  31. {
  32. MessageBox( NULL, "Error, couldn't get VxD API", "USEAPI", MB_OK );
  33. }
  34. else
  35. {
  36.     dmadesc.Size = 32L * 1024L;
  37.     _asm
  38.     {
  39.        mov ax, DMABUF_FUNC_ALLOCBUFFER
  40.        lea si, dmadesc     ; small model, don't need to load DS
  41.        call DWORD PTR pfDmaBufApi
  42.          mov err, ax
  43.     }
  44.       if (err)
  45.       {
  46.     MessageBox( NULL, "Error calling AllocBuffer", "USEAPI", MB_OK );
  47.       }
  48.     else
  49.     {
  50.        _asm mov myds, ds
  51.     usSel = AllocSelector( myds );
  52.     SetSelectorBase( usSel, dmadesc.LinAddr );
  53.     SetSelectorLimit( usSel, dmadesc.Size );
  54.     DmaBufPtr = MAKELP( usSel, 0 );
  55.     wsprintf( MsgBoxBuf, "Physical=%08lXnLinear=%08lXSelector=%Xn", 
  56.                              dmadesc.PhysAddr, dmadesc.LinAddr, usSel );
  57.        MessageBox( NULL, MsgBoxBuf, "USEAPI", MB_OK );
  58.     FreeSelector( usSel );
  59.     _asm
  60.     {
  61.        mov ax, DMABUF_FUNC_FREEBUFFER
  62.        call DWORD PTR pfDmaBufApi
  63.     }
  64.     }
  65. }
  66. return 0;
  67. }