I am reading a code in C#, and I am trying to understand a particular part of it. I am having trouble understanding it and I would appreciate if someone can explain that particular part to me.
First, there is a class
[StructLayout(LayoutKind.Sequential, Pack = 2)]
internal class SP_DEVICE_INTERFACE_DETAIL_DATA
{
internal int cbSize;
internal short devicePath;
}
then using the SetupDiGetDeviceInterfaceDetail
function we get an IntPtr
called buffer
as in
SetupDiGetDeviceInterfaceDetail(_deviceInfoSet, interfaceData, buffer ,size, ref size, devData)
therefore now buffer is a pointer to an SP_DEVICE_INTERFACE_DETAIL_DATA to receive information about an interface. (I am assuming that this points to a class like the one above.
From now, it is the part that I get confused. We have
var strPtr = new IntPtr(buffer.ToInt64() + 4);
string devicePath = Marshal.PtrToStringAuto(strPtr);
So I am guessing that now strPtr points to the place where buffer points as a 64 bit integer.
But then PtrToStringAuto
is applied to "allocate a managed string and copy all characters to the first null character".. and I ask myself, what characters?? I thought all these pointers pointed to a class, not a string...
What am I overlooking?