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

驱动编程

开发平台:

Visual C++

  1. #include <stdio.h>
  2. #include <stdlib.h>
  3. #include <conio.h>
  4. #include <windows.h>
  5. #include "dmabuf.h"
  6. HANDLE hDevice;
  7. DMA_BUFFER_DESCRIPTOR dmadesc;
  8. void main(int ac, char* av[])
  9. {
  10. DWORD   cbBytesReturned;
  11. DWORD err;
  12. const PCHAR VxDName = "\\.\DMABUF.VXD";
  13. hDevice = CreateFile(VxDName, 0,0,0,
  14.                         CREATE_NEW, FILE_FLAG_DELETE_ON_CLOSE, 0);
  15. if (hDevice == INVALID_HANDLE_VALUE)
  16. {
  17. err = GetLastError();
  18.         fprintf(stderr, "Cannot load VxD, error=%08lxn", err );
  19. if (err == ERROR_NOT_SUPPORTED)
  20. {
  21. DeleteFile("\\.\DMABUF");
  22. }
  23.   exit(1);
  24. }
  25. dmadesc.Size = 32 * 1024;
  26. if (!DeviceIoControl(hDevice, DMABUF_FUNC_ALLOCBUFFER,
  27.                &dmadesc, sizeof(DMA_BUFFER_DESCRIPTOR), 
  28.                NULL, 0, &cbBytesReturned, NULL))
  29.    {
  30. printf("DeviceIoControl failed, error=%dn", GetLastError() );
  31.    }
  32. else
  33. {
  34. printf( "Physical=%08lXnLinear=%08lXn", dmadesc.PhysAddr, dmadesc.LinAddr );
  35. if (!DeviceIoControl(hDevice, DMABUF_FUNC_FREEBUFFER,
  36.                 &dmadesc, sizeof(DMA_BUFFER_DESCRIPTOR), 
  37.                 NULL, 0, &cbBytesReturned, NULL)
  38.    )
  39.       {
  40. printf("DeviceIoControl failed, error=%dn", GetLastError() );
  41. }
  42. }
  43. CloseHandle( hDevice );
  44. }