So I have the following record structure in a Delphi DLL that I am calling from C#.
TItemPic = record
x, y : Integer;
id : Integer;
Hue : Integer;
Page : Integer;
ElemNum : Integer;
end;
TItemToken = record
id : Cardinal;
Arguments : String;
ElemNum : Integer;
end;
TItemType = record
ID : Integer;
Hue : Integer;
ItemPics : array of TItemPic;
ItemToken : array of TItemToken;
end;
And function :
function GetItemInfo(index : Word) : TItemType;
Now I have the following translated structs in C#:
public struct TItemPic
{
public int X { get; set; }
public int Y { get; set; }
public int ID { get; set; }
public int Hue { get; set; }
public int Page { get; set; }
public int ElemNum { get; set; }
}
public struct TItemToken
{
public uint ID { get; set; }
public TPCharStr Arguments { get; set; }
public int ElemNum { get; set; }
}
public struct TItemType
{
public uint ID { get; set; }
public int Hue { get; set; }
public TItemPic[] ItemPics { get; set; }
public TItemToken[] ItemToken { get; set; }
}
[DllImport("mydelphi.dll", EntryPoint = "GetItemInfo", CallingConvention = CallingConvention.StdCall, CharSet = CharSet.Unicode)]
internal static extern TItemType GetItemInfo(ushort index);
The goal being something like :
TItemType myItem = GetItemInfo(1);
I am unsure how to go about handling the open arrays in the TItemType record ItemPics : array of TItemPic; and ItemToken : array of TItemToken;
Reading some of David Heffernan's answers, I believe I probably should be declaring these as IntPtr then copying the data into an array -- however I'm not sure how to get the number of elements stored. He states that Delphi open arrays store a reference count and array size at a negative offset to the pointer that is passed ... but I am unsure how to retrieve this information and convert it :-)