With input from Zebediah Figura
Signed-off-by: Aric Stewart aric@codeweavers.com --- dlls/winebus.sys/bus_sdl.c | 66 +++++++++++++++++++++++++++++++++++++++++++--- 1 file changed, 63 insertions(+), 3 deletions(-)
On 3/7/19 11:36 AM, Aric Stewart wrote:
ULONG index = 0;
KEY_VALUE_PARTIAL_INFORMATION *info;
DWORD length, result_len;
NTSTATUS status;
length = sizeof(KEY_VALUE_PARTIAL_INFORMATION) + (1000 *
sizeof(WCHAR));
info = HeapAlloc(GetProcessHeap(), 0, length);
do {
status = NtEnumerateValueKey(key, index,
KeyValuePartialInformation,
info, length, &result_len);
if (status == STATUS_SUCCESS)
{
CHAR mapping[1000] = {0};
WideCharToMultiByte(CP_ACP, 0, info->Data,
(info->DataLength / sizeof(WCHAR)), mapping,
sizeof(mapping),
NULL, NULL);
if (mapping[0] != 0)
{
TRACE("Setting mapping
%s\n",debugstr_a(mapping));
pSDL_GameControllerAddMapping(mapping);
} else {
ERR("Failed to convert mapping
%s\n",debugstr_w(info->Data));
}
index ++;
}
} while (status == STATUS_SUCCESS);
HeapFree(GetProcessHeap(), 0, info);
NtClose(key);
I have to imagine that these strings can be arbitrarily long, and so I'd think it would be better to dynamically reallocate the structure.
I still don't like the use of NT APIs here: just because a real native driver uses it doesn't mean we have to, and they're generally more complex and harder to read. Still, if you insist...
On 3/15/19 9:47 AM, Zebediah Figura wrote:
On 3/7/19 11:36 AM, Aric Stewart wrote:
+ ULONG index = 0; + KEY_VALUE_PARTIAL_INFORMATION *info; + DWORD length, result_len; + NTSTATUS status;
+ length = sizeof(KEY_VALUE_PARTIAL_INFORMATION) + (1000 * sizeof(WCHAR)); + info = HeapAlloc(GetProcessHeap(), 0, length);
+ do { + status = NtEnumerateValueKey(key, index, KeyValuePartialInformation, + info, length, &result_len); + if (status == STATUS_SUCCESS) + { + CHAR mapping[1000] = {0}; + WideCharToMultiByte(CP_ACP, 0, info->Data, + (info->DataLength / sizeof(WCHAR)), mapping, sizeof(mapping), + NULL, NULL); + if (mapping[0] != 0) + { + TRACE("Setting mapping %s\n",debugstr_a(mapping)); + pSDL_GameControllerAddMapping(mapping); + } else { + ERR("Failed to convert mapping %s\n",debugstr_w(info->Data)); + } + index ++; + } + } while (status == STATUS_SUCCESS); + HeapFree(GetProcessHeap(), 0, info); + NtClose(key);
I have to imagine that these strings can be arbitrarily long, and so I'd think it would be better to dynamically reallocate the structure.
Agreed, patch sent.
I still don't like the use of NT APIs here: just because a real native driver uses it doesn't mean we have to, and they're generally more complex and harder to read. Still, if you insist...
It is easier for me here as I am being passed a UNICODE_STRING with the full path for the driver registry path in an NT API format.
-aric
On 03/15/2019 02:35 PM, Aric Stewart wrote:
It is easier for me here as I am being passed a UNICODE_STRING with the full path for the driver registry path in an NT API format.
-aric
For opening the key, yes, better to use NtOpenKey(). But there's no need to use NtEnumerateValueKey(); you can pass the same handle to RegEnumValue(). This would also let you use RegEnumValueA() instead of doing the conversion yourself.
On 3/15/19 2:45 PM, Zebediah Figura wrote:
On 03/15/2019 02:35 PM, Aric Stewart wrote:
It is easier for me here as I am being passed a UNICODE_STRING with the full path for the driver registry path in an NT API format.
-aric
For opening the key, yes, better to use NtOpenKey(). But there's no need to use NtEnumerateValueKey(); you can pass the same handle to RegEnumValue(). This would also let you use RegEnumValueA() instead of doing the conversion yourself.
I had not thought about mixing the NT registry functions and the advapi32 ones... That feels like crossing the streams bad. :)
-aric