Hi, I'm trying to marshal the DS_SELECTION_LIST struct (http://msdn.microsoft.com/library/default.asp url=/library/en-us/ad/ad/ds_selection_list.asp) to C#. It works, but only the first element is retrieved. I believe this is because the marshaler can not determine the array size.
However, the field cItems in the struct determines the array size. But I can not use the SizeParamIndex with UnmanagedType.ByValArray. So I tried the UnmanagedType.LPArray but then I receive the exception: System.TypeLoadException: Cannot marshal field 'aDsSelection' of type 'ADHelper.DS_SELECTION_LIST': Invalid managed/unmanaged type combination (Arrays fields must be paired with ByValArray or SafeArray).
How should I decorate the aDsSelection field to have the marshaler retrieve it as a dynamic array of DS_SELECTION structs
Here is the code for the struct in C#
[
StructLayout(LayoutKind.Sequential, CharSet = CharSet.Auto)] internal struct DS_SELECTION_LIST{
MarshalAs(UnmanagedType.U4)] public int cItems;[
[
MarshalAs(UnmanagedType.U4)] public int cFetchedAttributes;[
MarshalAs(UnmanagedType.ByValArray, ArraySubType = UnmanagedType.Struct)] public DS_SELECTION[] aDsSelection;}
Cheers,
Chris

Problems reading array in struct
Martin Carolan
Sonymony
See http://www.dotnetinterop.com/faq/ q=VariableLengthStruct for a general description of how to handle it. You probably can't deal with the structure as is, it needs some manual work.
B. Lefferdink