cliechti | a7bafcb | 2005-01-27 00:47:15 +0000 | [diff] [blame] | 1 | // Parallel port extension for Win32 |
| 2 | // "inp" and "outp" are used to access the parallelport hardware |
| 3 | // needs giveio.sys driver on NT/2k/XP |
| 4 | // |
| 5 | // (C) 2005 Chris Liechti <cliechti@gmx.net> |
| 6 | // this is distributed under a free software license, see license.txt |
| 7 | |
| 8 | #include <windows.h> |
| 9 | #include <conio.h> |
| 10 | |
| 11 | #define DRIVERNAME "\\\\.\\giveio" |
| 12 | |
| 13 | /* module-functions */ |
| 14 | |
| 15 | WINAPI void outp(int port, int value) { |
| 16 | _outp(port, value); |
| 17 | } |
| 18 | |
| 19 | WINAPI int inp(int port) { |
| 20 | int value; |
| 21 | value = _inp(port); |
| 22 | return value; |
| 23 | } |
| 24 | |
| 25 | WINAPI int init(void) { |
| 26 | OSVERSIONINFO vi; |
| 27 | |
| 28 | //detect OS, on NT,2k,XP the driver needs to be loaded |
| 29 | vi.dwOSVersionInfoSize = sizeof(vi); |
| 30 | GetVersionEx(&vi); |
| 31 | if (vi.dwPlatformId == VER_PLATFORM_WIN32_NT) { |
| 32 | HANDLE h; |
| 33 | //try to open driver |
| 34 | h = CreateFile(DRIVERNAME, GENERIC_READ, 0, NULL, |
| 35 | OPEN_EXISTING, FILE_ATTRIBUTE_NORMAL, NULL); |
| 36 | if (h == INVALID_HANDLE_VALUE) { |
| 37 | //if it fails again, then we have a problem... -> exception |
| 38 | //"Couldn't access giveio device"; |
| 39 | return 1; |
| 40 | } |
| 41 | //close again immediately. |
| 42 | //the process is now tagged to have the rights it needs, |
| 43 | //the giveio driver remembers that |
| 44 | if (h != NULL) CloseHandle(h); //close the driver's file |
| 45 | } |
| 46 | return 0; |
| 47 | } |