We have:
[StructLayout(LayoutKind.Sequential, CharSet= CharSet.Ansi)]
public unsafe struct SP_DEVICE_INTERFACE_DETAIL_DATA {
public int cbSize;
[MarshalAs(UnmanagedType.ByValArray, SizeConst=84)]
public char[] DevicePath;
}
The setupapi.dll method SetupDiGetDeviceInterfaceDetail requires us to
call it once to find the size of the output buffer "DevicePath", and
then to call it again, after allocating the char[] to fetch the
details.
The code above is kludged to marshal a fixed size. It works fine. What
I can't seem to figure is how to accomplish this without the kludging
to a pre-determined size.
Is there no way to do this without a C library as a go-between?
This idiom occurs so often in Win32 that I find it hard to believe that
theres not a simple solution. I tried manual marshalling with
Marshal.AllocHGlobal, which was successfully used to retrieve the
details, but then extracting "DevicePath" from an IntPtr was
problematic. Marshal.PtrToStructure doesn't work on valueTypes and I
couldn't figure a way to get from (coerce) the IntPtr into a char[] for
Marshal.copy.
Thanks in advance for any ideas,
bullshark
Winista - 02 Aug 2006 16:43 GMT
See if this helps..
http://www.netomatix.com/Development/EmbedStruct.aspx
> We have:
> [StructLayout(LayoutKind.Sequential, CharSet= CharSet.Ansi)]
[quoted text clipped - 26 lines]
>
> bullshark