Hello. This is a P/Invoke question which, quite frankly, is doing my head in.
I need to get a string from a []byte because calling the object.Tostring() method on he variable doesn't yield the correct information.
given the following (which was extracted from p/invoke.net:
Code:
public static extern bool SetupDiGetDeviceRegistryProperty(IntPtr DeviceInfoSet, ref SPDEVINFODATA DeviceInfoData,
uint Property, out uint PropertyRegDataType,
byte[] PropertyBuffer, uint PropertyBufferSize,
out uint RequiredSize);
result = SetupDiGetDeviceRegistryProperty(deviceInfoSet, ref tBuff, (uint)SPDRP.HARDWAREID, out RegType, null, 0, out RequiredSize);
ptrBuf = new byte[RequiredSize];
buffersize = RequiredSize;
result = SetupDiGetDeviceRegistryProperty(deviceInfoSet, ref tBuff, (uint)SPDRP.HARDWAREID, out RegType, ptrBuf, buffersize, out RequiredSize);
I need to retrieve the string returned in that variableI tried string tmp = Marshal.PtrToStringAuto(ptrBuf) but that doesn't work; although this is the way it's used in the p/Invoke example. Then I tried using Encodings (Encoding.Unicode.Getstring() ) and coughed up several other problems.
In short I just need a reliable way to retrieve a string from a []byte and be able to output it to the label on my form
Thank you very much.
!--removed tag-->
No one has replied yet! Why not be the first?
Sign in or Join us (it's free).