Port32.cpp
上传用户:ason123
上传日期:2010-03-31
资源大小:177k
文件大小:2k
源码类别:

并口编程

开发平台:

C++ Builder

  1. // ---------------------------------------------------- //
  2. //                      WinIo v2.0                      //
  3. //  Direct Hardware Access Under Windows 9x/NT/2000/XP  //
  4. //           Copyright 1998-2002 Yariv Kaplan           //
  5. //               http://www.internals.com               //
  6. // ---------------------------------------------------- //
  7. #include <windows.h>
  8. #include <winioctl.h>
  9. #include <conio.h>
  10. #include "port32.h"
  11. #include "..drvntwinio_nt.h"
  12. #include "..drv9xwinio_9x.h"
  13. #include "winio.h"
  14. bool _stdcall GetPortVal(WORD wPortAddr, PDWORD pdwPortVal, BYTE bSize)
  15. {
  16.   tagPort32Struct Port32Struct;
  17.   DWORD dwBytesReturned;
  18.   
  19.   if (!IsWinIoInitialized)
  20.     return false;
  21.   if (IsNT)
  22.   {
  23.     switch (bSize)
  24.     {
  25.       case 1:
  26.         *pdwPortVal = _inp(wPortAddr);
  27.       break;
  28.       case 2:
  29.         *pdwPortVal = _inpw(wPortAddr);
  30.       break;
  31.       case 4:
  32.         *pdwPortVal = _inpd(wPortAddr);
  33.       break;
  34.     }
  35.   }
  36.   else
  37.   {
  38.    Port32Struct.bSize = bSize;
  39.    Port32Struct.wPortAddr = wPortAddr;
  40.    
  41.    return DeviceIoControl(hDriver, WINIO_READPORT, &Port32Struct, sizeof(Port32Struct),
  42.                           pdwPortVal, sizeof(DWORD), &dwBytesReturned, NULL);
  43.   }
  44.   return true;
  45. }
  46. bool _stdcall SetPortVal(WORD wPortAddr, DWORD dwPortVal, BYTE bSize)
  47. {
  48.   tagPort32Struct Port32Struct;
  49.   DWORD dwBytesReturned;
  50.   if (!IsWinIoInitialized)
  51.     return false;
  52.   if (IsNT)
  53.   {
  54.     switch (bSize)
  55.     {
  56.       case 1:
  57.         _outp(wPortAddr, dwPortVal);
  58.       break;
  59.       case 2:
  60.         _outpw(wPortAddr, (WORD)dwPortVal);
  61.       break;
  62.       case 4:
  63.         _outpd(wPortAddr, dwPortVal);
  64.       break;
  65.     }
  66.   }
  67.   else
  68.   {
  69.    Port32Struct.bSize = bSize;
  70.    Port32Struct.dwPortVal = dwPortVal;
  71.    Port32Struct.wPortAddr = wPortAddr;
  72.    
  73.    return DeviceIoControl(hDriver, WINIO_WRITEPORT, &Port32Struct, sizeof(Port32Struct),
  74.                           NULL, 0, &dwBytesReturned, NULL);
  75.   }
  76.   
  77.   return true;
  78. }