1 module ds5w.winhelper; 2 3 import core.stdc.stddef : wchar_t; 4 5 import core.sys.windows.windows; 6 7 debug string GetLastErrorAsString() 8 { 9 DWORD errorMessageID = GetLastError(); 10 if (errorMessageID == 0) 11 return "success"; 12 13 LPSTR messageBuffer = null; 14 15 size_t size = FormatMessageA(FORMAT_MESSAGE_ALLOCATE_BUFFER | FORMAT_MESSAGE_FROM_SYSTEM | FORMAT_MESSAGE_IGNORE_INSERTS, 16 NULL, errorMessageID, MAKELANGID(LANG_NEUTRAL, SUBLANG_DEFAULT), cast(LPSTR)&messageBuffer, 0, NULL); 17 18 string message = messageBuffer[0 .. size].dup; 19 20 LocalFree(messageBuffer); 21 22 return message; 23 } 24 25 __gshared const GUID_DEVINTERFACE_HID = GUID( 26 0x4D1E55B2L, 0xF16F, 0x11CF, 27 [0x88, 0xCB, 0x00, 0x11, 0x11, 0x00, 0x00, 0x30] 28 ); 29 30 struct HIDD_ATTRIBUTES 31 { 32 DWORD Size = HIDD_ATTRIBUTES.sizeof; 33 USHORT VendorID; 34 USHORT ProductID; 35 USHORT VersionNumber; 36 } 37 38 alias PHIDP_PREPARSED_DATA = void*; 39 40 struct HIDP_CAPS 41 { 42 ushort Usage; 43 ushort UsagePage; 44 ushort InputReportByteLength; 45 ushort OutputReportByteLength; 46 ushort FeatureReportByteLength; 47 ushort[17] Reserved; 48 49 ushort NumberLinkCollectionNodes; 50 51 ushort NumberInputButtonCaps; 52 ushort NumberInputValueCaps; 53 ushort NumberInputDataIndices; 54 55 ushort NumberOutputButtonCaps; 56 ushort NumberOutputValueCaps; 57 ushort NumberOutputDataIndices; 58 59 ushort NumberFeatureButtonCaps; 60 ushort NumberFeatureValueCaps; 61 ushort NumberFeatureDataIndices; 62 } 63 64 alias PHIDP_CAPS = HIDP_CAPS*; 65 66 @nogc nothrow extern (C): 67 68 ubyte HidD_GetAttributes( 69 HANDLE HidDeviceObject, 70 HIDD_ATTRIBUTES* Attributes 71 ); 72 73 int wcscpy_s(wchar_t*, size_t, const(wchar_t)*); 74 75 BOOLEAN HidD_GetPreparsedData( 76 HANDLE HidDeviceObject, 77 PHIDP_PREPARSED_DATA* PreparsedData 78 ); 79 80 enum HIDP_STATUS_SUCCESS = 1114112; //0x110010; 81 int HidP_GetCaps(PHIDP_PREPARSED_DATA PreparsedData, PHIDP_CAPS Capabilities); 82 83 ubyte HidD_FreePreparsedData(PHIDP_PREPARSED_DATA); 84 85 size_t wcslen(const(wchar_t*)); 86 87 ubyte HidD_GetFeature(HANDLE HidDeviceObject, void* ReportBuffer, ulong ReportBufferLength); 88 ubyte HidD_FlushQueue(HANDLE HidDeviceObject);