Hello,
i want to use a COM-function who is declared like the following
(IDL)
HRESULT SetPlcData (
[in] BSTR bstrPlcString,
[in] SAFEARRAY(long) * lPlcMarkers,
[in] SAFEARRAY(long) * lPlcDWords );
Since i add a reference to my Studio 2003 Project (c#) to the dll-file
who contains this function the declaration changed to
void SetPlcData(System.String bstrPlcString, System.Array lPlcMarkers,
System.Array lPlcDWords)
That's how the Studio interpret this IDL code; fine.
But when i invoke the function later like this
Array arrPlcMarkers = null;
Array arrPlcWords = null;
//...fill the arrays with
split-function...
objPlc.SetPlcData(sParams[2], ref arrPlcMarkers, ref arrPlcWords);
i get the error - "specified array was not of the expected type" !!!
If i invoke it with two long-arrays i can't compile because the
compiler wants two System.Array-types.
I also tried to use a delegate to marshal the parameters - the result
is the same error.
private delegate void MyDelegate(string str,
[MarshalAs(UnmanagedType.SafeArray, SafeArraySubType=VarEnum.VT_I4)]
ref System.Array a, [MarshalAs(UnmanagedType.SafeArray,
SafeArraySubType=VarEnum.VT_I4)] ref System.Array b);
hope you can help me
Mattias Sjögren - 21 Sep 2006 21:32 GMT
> Array arrPlcMarkers = null;
> Array arrPlcWords = null;
> //...fill the arrays with
>split-function...
Split function? Sounds like you're dealing with strings. Did you try
something like
Array arrPlcMarkers = new int[] {1, 2, 3};
Array arrPlcWords = new int[] {4, 5, 6};
Another option is to create a new interop assembly with TlbImp so you
can get strongly typed array parameters.
Mattias

Signature
Mattias Sjögren [C# MVP] mattias @ mvps.org
http://www.msjogren.net/dotnet/ | http://www.dotnetinterop.com
Please reply only to the newsgroup.
ms - 22 Sep 2006 09:35 GMT
I tried it with int's and long's - no way to get i work.
I also tried it with my delegate.
private delegate void MyDelegate(string str,
[MarshalAs(UnmanagedType.LPArray)] ref System.Array a,
[MarshalAs(UnmanagedType.LPArray)] ref System.Array b);
Always the same error!
> Another option is to create a new interop assembly with TlbImp so you
> can get strongly typed array parameters.
---> ??? How can i do this? I don't have the code - it's from another
company.
Thanks
Mattias Sjögren - 25 Sep 2006 20:32 GMT
>> Another option is to create a new interop assembly with TlbImp so you
>> can get strongly typed array parameters.
> ---> ??? How can i do this? I don't have the code - it's from another
>company.
Run Tlbimp.exe from the command line. You don't need the source code,
just the COM library.
Mattias

Signature
Mattias Sjögren [C# MVP] mattias @ mvps.org
http://www.msjogren.net/dotnet/ | http://www.dotnetinterop.com
Please reply only to the newsgroup.
ms - 29 Sep 2006 10:48 GMT
That works. Thank you very much for supporting me.