|
|
1.1 ! root 1: /*++ ! 2: ! 3: Copyright (c) 1993 Microsoft Corporation ! 4: ! 5: Module Name: ! 6: ! 7: kbd_attr.c ! 8: ! 9: Abstract: ! 10: ! 11: A user mode test app demoing how to create a symbolic link ! 12: ( a Win32 alias that an app can spcify in CreateFile() ) for ! 13: a keyboard device, open the device, and send it an i/o request. ! 14: ! 15: Environment: ! 16: ! 17: User mode only ! 18: ! 19: Revision History: ! 20: ! 21: 05-26-93 : created ! 22: ! 23: --*/ ! 24: ! 25: #include <windows.h> ! 26: #include <winioctl.h> ! 27: #include <stdio.h> ! 28: #include <stdlib.h> ! 29: #include <ntddkbd.h> ! 30: ! 31: ! 32: ! 33: int ! 34: main( ! 35: IN int argc, ! 36: IN char *argv[] ! 37: ) ! 38: /*++ ! 39: ! 40: Routine Description: ! 41: ! 42: Creates a symbilic link to \Device\KeyboardPort0, opens the ! 43: device, and send it an i/o request. ! 44: ! 45: Arguments: ! 46: ! 47: argc - count of command line arguments ! 48: ! 49: argv - command line arguments ! 50: ! 51: Return Value: ! 52: ! 53: 1 if success ! 54: 0 if an error occurs ! 55: ! 56: --*/ ! 57: { ! 58: ! 59: int rc = 1; // be optomistic, assume success ! 60: HANDLE hDriver; ! 61: DWORD cbReturned; ! 62: char deviceName[] = "KBD"; ! 63: char targetPath[] = "\\Device\\KeyboardClass0"; ! 64: char completeDeviceName[] = "\\\\.\\KBD"; ! 65: ! 66: KEYBOARD_ATTRIBUTES kbdattrs; ! 67: ! 68: // ! 69: // The kuid=0 here corresponds to the keyboard port device # 0 ! 70: // (e.g. \Device\KeyboardPort). We go through the keyboard ! 71: // class device # 0 to get to the kbd port device # 0. ! 72: // ! 73: ! 74: KEYBOARD_UNIT_ID_PARAMETER kuid = { 0 }; ! 75: ! 76: ! 77: // ! 78: // First create a symbolic link to the NT keyboard object (number 0- ! 79: // there may be more than 1) ! 80: // ! 81: ! 82: if (DefineDosDevice (DDD_RAW_TARGET_PATH, ! 83: deviceName, ! 84: targetPath ! 85: )) ! 86: { ! 87: printf ("\nDefinedDosDevice (%s, %s) worked\n", ! 88: deviceName, ! 89: targetPath ! 90: ); ! 91: } ! 92: else ! 93: { ! 94: printf ("\nDefinedDosDevice (%s, %s) faileded\n", ! 95: deviceName, ! 96: targetPath ! 97: ); ! 98: ! 99: return 0; ! 100: } ! 101: ! 102: ! 103: ! 104: // ! 105: // Next, try to open the device ! 106: // ! 107: ! 108: if ((hDriver = CreateFile (completeDeviceName, ! 109: GENERIC_READ | GENERIC_WRITE, ! 110: 0, ! 111: NULL, ! 112: OPEN_EXISTING, ! 113: FILE_ATTRIBUTE_NORMAL, ! 114: NULL ! 115: )) != ((HANDLE)-1)) ! 116: ! 117: printf ("\nRetrieved valid handle for %s\n", ! 118: deviceName ! 119: ); ! 120: ! 121: ! 122: else ! 123: { ! 124: printf ("Can't get a handle to %s\n", ! 125: deviceName ! 126: ); ! 127: ! 128: rc = 0; ! 129: ! 130: goto delete_dos_device; ! 131: } ! 132: ! 133: ! 134: ! 135: // ! 136: // Send it a request ! 137: // ! 138: ! 139: if (DeviceIoControl (hDriver, ! 140: (DWORD) IOCTL_KEYBOARD_QUERY_ATTRIBUTES, ! 141: &kuid, ! 142: sizeof(KEYBOARD_UNIT_ID_PARAMETER), ! 143: &kbdattrs, ! 144: sizeof(KEYBOARD_ATTRIBUTES), ! 145: &cbReturned, ! 146: 0 ! 147: )) ! 148: { ! 149: printf ("DeviceIoControl worked\n\n"); ! 150: ! 151: printf ("\tkbd_attr.KeyboardIdentifier.Type = %d\n", ! 152: (int) kbdattrs.KeyboardIdentifier.Type ! 153: ); ! 154: ! 155: printf ("\tkbd_attr.KeyboardIdentifier.Subtype = %d\n", ! 156: (int) kbdattrs.KeyboardIdentifier.Subtype ! 157: ); ! 158: ! 159: printf ("\tkbd_attr.KeyboardMode = %d\n", ! 160: (int) kbdattrs.KeyboardMode ! 161: ); ! 162: ! 163: printf ("\tkbd_attr.NumberOfFunctionKeys = %d\n", ! 164: (int) kbdattrs.NumberOfFunctionKeys ! 165: ); ! 166: ! 167: printf ("\tkbd_attr.NumberOfIndicators = %d\n", ! 168: (int) kbdattrs.NumberOfIndicators ! 169: ); ! 170: ! 171: printf ("\tkbd_attr.NumberOfKeysTotal = %d\n", ! 172: (int) kbdattrs.NumberOfKeysTotal ! 173: ); ! 174: ! 175: printf ("\tkbd_attr.InputDataQueueLength = %d\n", ! 176: (int) kbdattrs.InputDataQueueLength ! 177: ); ! 178: ! 179: printf ("\tkbd_attr.KeyRepeatMinimum.UnitId = %d\n", ! 180: (int) kbdattrs.KeyRepeatMinimum.UnitId ! 181: ); ! 182: ! 183: printf ("\tkbd_attr.KeyRepeatMinimum.Rate = %d\n", ! 184: (int) kbdattrs.KeyRepeatMinimum.Rate ! 185: ); ! 186: ! 187: printf ("\tkbd_attr.KeyRepeatMinimum.Delay = %d\n", ! 188: (int) kbdattrs.KeyRepeatMinimum.Delay ! 189: ); ! 190: ! 191: printf ("\tkbd_attr.KeyRepeatMaximum.UnitId = %d\n", ! 192: (int) kbdattrs.KeyRepeatMaximum.UnitId ! 193: ); ! 194: ! 195: printf ("\tkbd_attr.KeyRepeatMaximum.Rate = %d\n", ! 196: (int) kbdattrs.KeyRepeatMaximum.Rate ! 197: ); ! 198: ! 199: printf ("\tkbd_attr.KeyRepeatMaximum.Delay = %d\n", ! 200: (int) kbdattrs.KeyRepeatMaximum.Delay ! 201: ); ! 202: } ! 203: else ! 204: { ! 205: DWORD err = GetLastError(); ! 206: ! 207: printf ("DeviceIoControl failed, err = %d\n(%x)\n", ! 208: err, ! 209: err ! 210: ); ! 211: ! 212: rc = 0; ! 213: } ! 214: ! 215: ! 216: ! 217: // ! 218: // Clean up ! 219: // ! 220: ! 221: CloseHandle(hDriver); ! 222: ! 223: delete_dos_device: ! 224: ! 225: DefineDosDevice (DDD_REMOVE_DEFINITION, ! 226: deviceName, ! 227: NULL ! 228: ); ! 229: ! 230: return rc; ! 231: }
This archive runs on limited infrastructure. Preserving old code on modern bandwidth. Automated agents are requested to crawl responsibly.