I’m using a third party library. One of the methods requires passing an array via ref that will be populated with some info. Here’s the definition for the method:
int GetPositionList(ref Array arrayPos)
How do I construct arrayPos so that this method will work? In the library’s not so complete documentation it defines the method as such:
long GetPositionList(structSTIPosUpdate() arrayPos)
I’ve tried this but of course I’m getting errors:
System.Array position_list = new System.Array();
sti_position.GetPositionList(ref position_list);
Any ideas?
This is the Sterling Trader Pro ActiveX API, right? Did you create an Interop dll using
tlbimp.exe? TheGetPositionListAPI expects an array which will hold structs of typestructSTIPositionUpdate. Normally anoutmodifier is used if the callee initializes the passed-in data, andrefif the data is to be initialized. According to the meaning of the API the modifier should beout, so that this should work:Alternatively, try creating an array of these structs which is big enough to hold the expected number of entries, then pass it to the function:
Update: If you are getting type mismatches with
System.Array, trywhere N is the number of elements in the array.