Reputation: 8951
I'm calling the Setup API function SetupDiGetDriverInfoDetail like this:
SP_DRVINFO_DETAIL_DATA_W driverDetailData = SP_DRVINFO_DETAIL_DATA_W();
driverDetailData.cbSize = sizeof(SP_DRVINFO_DETAIL_DATA_W);
DWORD reqSize = 0;
ok = SetupDiGetDriverInfoDetailW(deviceList, nullptr, &driverData, &driverDetailData, sizeof(SP_DRVINFO_DETAIL_DATA_W), &reqSize);
The call returns false, the last Windows error code is 0x7a ("ERROR_INSUFFICIENT_BUFFER"). When I compare cbSize and reqSize I can see why: cbSize is 1584 bytes, reqSize is 1622 bytes.
If I understand the MSDN page on SetupDiGetDriverInfoDetail correctly (https://learn.microsoft.com/en-us/windows/win32/api/setupapi/nf-setupapi-setupdigetdriverinfodetailw), my call should work as expected.
What did I miss? How does one call SetupDiGetDriverInfoDetail correctly, so that the input buffer is large enough for the call to succeed?
Upvotes: 1
Views: 362
Reputation: 17668
SP_DRVINFO_DETAIL_DATA
is a variable length structure because of the HardwareID[ANYSIZE_ARRAY];
buffer at the end. Once the required size is known, it can be allocated dynamically.
DWORD reqSize = 0;
SetupDiGetDriverInfoDetailW(deviceList, nullptr, &driverData, NULL, 0, &reqSize);
SP_DRVINFO_DETAIL_DATA_W *driverDetailData = (SP_DRVINFO_DETAIL_DATA_W *)calloc(1, reqSize);
driverDetailData->cbSize = sizeof(SP_DRVINFO_DETAIL_DATA_W);
SetupDiGetDriverInfoDetailW(deviceList, nullptr, &driverData, driverDetailData, reqSize, &reqSize);
Upvotes: 1