Hello,
I'm creating a COM callable .net assembly and now trying to use it from legacy COM clients (VB6 client in my case).
Assembly should expose API style interface, so typical function declaration would look like this:
int myRoutine (object inParam, out object result);
The problem is when I trying to use function declared as:
int GetMultipleItems (out ItemData[] itemList);
In VB6 this translated to function that have array to be passed as parameter which fails when I'm calling it with 'Invalid procedure call or argument'.
Actual call looks like:
Dim items() As ItemData
result = SCServer.GetMultipleItems (items)
Investigated further, I tried several different ways of marking up my library with MarshalAs attributes. From my point of view, the problem is argument has to be array to be passed in and - on the other hand - a variant to be returned to VB code.
After several experiments, I got following to work (1):
int GetMultipleItems ([Out, MarshalAs (UnmanagedType.SafeArray,
SafeArraySubType = VarEnum.VT_DISPATCH)]out object[] itemList);
(having items() declared as Object at the client side).
But I have to use exactly my initial signature (2),
int GetMultipleItems ([Out, MarshalAs (UnmanagedType.SafeArray,
SafeArraySubType = VarEnum.VT_DISPATCH)]out ItemData[] itemList);
Which does not work either with Object or with ItemData array type declaration at client.
So, questions are:
- why (1) works while (2) not. What should I change in attribute declaration or in client to get to work with my actual type in signature (it exposes an interface which has been exported to tlb as well, so seems all should be OK here)
- what is recommended way to define sugh [out] parameter arrays
- maybe I lack some essential reading, I would be grateful for the links... still I need to get the sample working in a day or two.
Thanks in advance.