You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
This code will eventually throw the following exception in my machine:
An unhandled exception of type 'System.ComponentModel.Win32Exception' occurred in Repro.dll: 'The data area passed to a system call is too small.'
For context, SP_DRVINFO_DETAIL_DATA.cbSize ends up being 1584, however neededSize is 1594.
I tried solving it by allocating my own buffer and then creating a ref SP_DRVINFO_DETAIL_DATA out of it, which kind of works. It doesn't throw anymore, however the SizeConst = 1 makes it so I can only grab one letter (the ref goes through marshaling).
Big bug. Thanks. I've just pushed a commit with some big changes to fix this. You can get the packages on the project's AppVeyor feed. New code to do what you've done above:
publicvoidMain(){usingSafeHDEVINFOdeviceInfoSet=Win32Error.ThrowLastErrorIfInvalid(SetupDiGetClassDevs(Flags:DIGCF.DIGCF_ALLCLASSES|DIGCF.DIGCF_PRESENT));foreach(SP_DEVINFO_DATAdeviceInfoinSetupDiEnumDeviceInfo(deviceInfoSet)){SP_DEVINFO_DATAdiDup=deviceInfo;// Need copy for ref param belowWin32Error.ThrowLastErrorIfFalse(SetupDiBuildDriverInfoList(deviceInfoSet,refdiDup,SPDIT.SPDIT_COMPATDRIVER));foreach(SP_DRVINFO_DATA_V2driverInfoinSetupDiEnumDriverInfo(deviceInfoSet,deviceInfo,SPDIT.SPDIT_COMPATDRIVER)){SP_DRVINFO_DETAIL_DATA_MGDmgd=SetupDiGetDriverInfoDetail(deviceInfoSet,deviceInfo,driverInfo);// Manipulate as needed}}}
Describe the bug and how to reproduce
This code will eventually throw the following exception in my machine:
For context,
SP_DRVINFO_DETAIL_DATA.cbSize
ends up being 1584, howeverneededSize
is 1594.I tried solving it by allocating my own buffer and then creating a
ref SP_DRVINFO_DETAIL_DATA
out of it, which kind of works. It doesn't throw anymore, however theSizeConst = 1
makes it so I can only grab one letter (theref
goes through marshaling).The
CompatIDs
that is supposed to be afterHardwareID
is also missing using this method, since marshaller did not know of its existence.What code is involved
https://github.com/dahall/Vanara/blob/master/PInvoke/SetupAPI/SetupAPI.cs#L3489-L3490
https://github.com/dahall/Vanara/blob/master/PInvoke/SetupAPI/SetupAPI.DiFuncs2.cs#L1774-L1878
Expected behavior
A possible solution is to provide an overload of
SetupDiGetDriverInfoDetail()
that usesnint
instead ofref SP_DRVINFO_DETAIL_DATA
.The text was updated successfully, but these errors were encountered: