WinIo.c
上传用户: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. #define DEVICE_MAIN
  8. #include "winio_9x.h"
  9. #undef DEVICE_MAIN
  10. #include "winio.h"
  11. Declare_Virtual_Device(WINIO)
  12. DefineControlHandler(SYS_DYNAMIC_DEVICE_INIT, OnSysDynamicDeviceInit);
  13. DefineControlHandler(SYS_DYNAMIC_DEVICE_EXIT, OnSysDynamicDeviceExit);
  14. DefineControlHandler(W32_DEVICEIOCONTROL, OnW32DeviceIoControl);
  15. BOOL ControlDispatcher(DWORD dwControlMessage, DWORD EBX, DWORD EDX, DWORD ESI, DWORD EDI, DWORD ECX)
  16. {
  17.   START_CONTROL_DISPATCH
  18.   ON_SYS_DYNAMIC_DEVICE_INIT(OnSysDynamicDeviceInit);
  19.   ON_SYS_DYNAMIC_DEVICE_EXIT(OnSysDynamicDeviceExit);
  20.   ON_W32_DEVICEIOCONTROL(OnW32DeviceIoControl);
  21.   END_CONTROL_DISPATCH
  22.   return TRUE;
  23. }
  24. BOOL OnSysDynamicDeviceInit()
  25. {
  26.   return TRUE;
  27. }
  28. BOOL OnSysDynamicDeviceExit()
  29. {
  30.   return TRUE;
  31. }
  32. DWORD OnW32DeviceIoControl(PIOCTLPARAMS p)
  33. {
  34.   struct tagPort32Struct *pPort32Struct;
  35.   unsigned int *pdwPortVal;
  36.   switch (p->dioc_IOCtlCode)
  37.   {
  38.     case DIOC_OPEN:
  39.     case DIOC_CLOSEHANDLE:
  40.     break;
  41.     case WINIO_WRITEPORT:
  42.       
  43.       pPort32Struct = p->dioc_InBuf;
  44.       switch (pPort32Struct->bSize)
  45.       {
  46.         case 1:
  47.           _outp(pPort32Struct->wPortAddr, pPort32Struct->dwPortVal);
  48.         break;
  49.         case 2:
  50.           _outpw(pPort32Struct->wPortAddr, pPort32Struct->dwPortVal);
  51.         break;
  52.         case 4:
  53.           _outpd(pPort32Struct->wPortAddr, pPort32Struct->dwPortVal);
  54.         break;
  55.       }
  56.       
  57.     break;
  58.     case WINIO_READPORT:
  59.       pPort32Struct = p->dioc_InBuf;
  60.       pdwPortVal = p->dioc_OutBuf;
  61.       switch (pPort32Struct->bSize)
  62.       {
  63.         case 1:
  64.           *pdwPortVal = _inp(pPort32Struct->wPortAddr);
  65.         break;
  66.         case 2:
  67.           *pdwPortVal = _inpw(pPort32Struct->wPortAddr);
  68.         break;
  69.         case 4:
  70.           *pdwPortVal = _inpd(pPort32Struct->wPortAddr);
  71.         break;
  72.       }
  73.     break;
  74.   }
  75.   return 0;
  76. }