I am using an api that has method defined as follows:
[DllImport("icsneo40.dll")]
public static extern Int32 icsneoGetMessages(Int32 hObject, ref icsSpyMessage pMsg, ref Int32 pNumberOfMessages, ref Int32 pNumberOfErrors);
with icsSpyMessage parameter described as:
pMsg [out]
This is the address of the first element of an array of
icsSpyMessage structures. This array will be loaded with
messages received by the hardware. This array must be sized to fit
20,000 icsSpyMessage structures
My question is how do I access the other elements in the array when all I have is the first element?
Since you are passing an array you should declare the
icsSpyMessageto be an array:The [out] attribute instructs the p/invoke marshaller to marshal the native memory back to your managed array of structs. The marshaller will marshal elements according to the length of the managed array.
So you need to allocate this array before you call the function. The API you are calling requires that you provide an array of at least 20,000 elements.