SetupDi problem

  • Thread starter Thread starter Steve
  • Start date Start date
S

Steve

Hi all,

Thanks to repies from my previous post, I am now able to get device info
from the system. However, I am having a problem with the final part,
getting a device description. Here is the snippet:

..
..
' Get the device description, 1st call

SetupDiGetDeviceRegistryProperty( _
hDevInfo, DeviceInfoData,SPDRP_DEVICEDESC, vbNull, IntPtr.Zero, buffersize,
buffersize)

' create a buffer to receive the decsription

Err.Clear()
Dim Buffer As IntPtr = Marshal.AllocHGlobal(buffersize)
RetError = Err.LastDllError

'2nd cal
SetupDiGetDeviceRegistryProperty( _
hDevInfo, DeviceInfoData,SPDRP_DEVICEDESC, vbNull, Buffer, buffersize,
buffersize)

Now, the problem is that the Dim to create the Buffer returns
ERROR_INSUFFICIENT_BUFFER which I dont understand, as I am creating the
buffer in the first place!
The two calls to get the device work as expected, but the second does not
return any data because the buffer has not been created. What am I doing
wrong?

Many thanks in advance,
Steve.
 
Now, the problem is that the Dim to create the Buffer returns
ERROR_INSUFFICIENT_BUFFER which I dont understand, as I am creating the
buffer in the first place!

That error code is probably coming from the first
SetupDiGetDeviceRegistryProperty call, not the allocation. AllocHGlobal would
throw an exception if it failed.

The two calls to get the device work as expected, but the second does not
return any data because the buffer has not been created. What am I doing
wrong?

What do you mean by "the buffer has not been created"? Is Buffer =
IntPtr.Zero? If not, what does LastDllError give you after the second call to
SetupDiGetDeviceRegistryProperty?


Mattias
 
hi,

The error occurs when I try and create the buffer. There is no exception
thrown and Buffer = IntPtr.Zero. The second call does not return any error,
in fact, it reports success, but, as the buffer has not been created, there
is no data.

Steve
 
Back
Top