Groups | Blog | Home
all groups > dotnet interop > june 2005 >

dotnet interop : How to correctly set a conformant array argument if a function of an interface is implemented?


Michael Kremser
6/27/2005 11:28:36 PM
Hi NG!

I have a class that derives of an interface (IASysCls) which implements
a function with this argument list (the function is then later be called
by a caller):

public void GetSObjDesc(int Start, int Size, out int Length, out Lib.SOD
ODs)

In the IDL file I found this:

HRESULT IASysCls::GetSObjDesc(long Start, long Size, long * Length,
struct SOD * ODs)

The last argument ("ODs") is a conformant array. My problem is that I
could not yet find a solution how to make such an array in C# and set
the argument.

If I set Length to 1 and set ODs to an instance of Lib.SOD, it works.
But of course I want to give the caller more that one Lib.SOD instance.

Does anyone have an idea?

BR,

Michael

--
http://www.mkcs.at/
Michael Kremser
6/28/2005 5:11:10 AM
Hi Mattias,

Thanks for your answer!

[quoted text, click to view]

No, Length is the size of the array.

I tried your method and also fit the wrapper (I dissassembled it using
disasm, changed the signature from

instance void GetSObjDesc([in] int32 Start,
[in] int32 Size,
[out] int32& Length,
[out] valuetype Lib.SOD&
ODs) runtime managed internalcall

to

instance void GetSObjDesc([in] int32 Start,
[in] int32 Size,
[out] int32& Length,
[out] valuetype Lib.SOD[]&
ODs) runtime managed internalcall

It compliled all successfully, but it did not run as excpected.

I changed the implementation as follows:

public void GetSObjDesc(int Start, int Size, out int
Length,[Out,MarshalAs(UnmanagedType.LPArray, SizeParamIndex=2)] out Lib.SOD[]
ODs)

I also tried to set SizeParamIndex to 1.

I don't have a clue why it does not work and what I did wrong. :-/ I already
thought that I just could "serialize" my array to a byte[] and give the
caller a IntPtr to it. Could this work?

BR,

Michael Kremser
6/28/2005 5:53:10 AM
I also found now another IDL file that is more specific:

HRESULT GetSObjDesc([in] long Start, [in] long Size, [out] long *Length,
Mattias Sjögren
6/28/2005 9:20:55 AM
Michael,

[quoted text, click to view]


If Size is the number of elements in the array, you can try something
like this

void GetSObjDesc(int Start, int Size, out int Length, [Out,
MarshalAs(UnmanagedType.LPArray, SizeParamIndex=1)] Lib.SOD[] ODs);



Mattias

--
Mattias Sjögren [MVP] mattias @ mvps.org
http://www.msjogren.net/dotnet/ | http://www.dotnetinterop.com
AddThis Social Bookmark Button