Quantcast
Channel: Common Language Runtime Internals and Architecture forum
Viewing all articles
Browse latest Browse all 1710

SetupDiGetDeviceRegistryProperty

$
0
0

I have a C# application using P/Invoke to call several SetupApi.dll methods.  I'm not getting an error when I call SetupDiGetDeviceRegistryProperty(), but I'm not getting the desired result either.

At first, I followed the example code on pinvoke.net (http://pinvoke.net/default.aspx/setupapi.SetupDiGetDeviceRegistryProperty), but I got an error at the line "string ControllerDeviceDesc = Marshal.PtrToStringAuto(ptrBuf)".  I think this is because the sample code defined ptrBuf as a byte[].  So I defined my ptBuf as IntPtr and now the following code runs:

[...]IntPtr ptrBuffer = new IntPtr();UInt32 requiredSize;UInt32 regType = REG_SZ (which is defined as 1);string deviceName;if (SetupDiGetDeviceRegistryProperty(deviceInfoSet, ref devInfoData, SPDRP_DEVICEDESC, out regType, out ptrBuffer, BUFFER_SIZE, out requiredSize) {   deviceName = Marshal.PtrToStringAuto(ptrBuffer);   MessageBox.Show("Device Name = " + deviceName);} else{   MessageBox.Show(GetLastWin32Error());}[...]

The code runs, but the message box only has "Device Name = ". 

If you need additional details, please let me know.  But I'm quite perplexed!

Thanks!


Viewing all articles
Browse latest Browse all 1710

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>