Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
HomeAnnouncementsFree MagazinesWhite PapersSubmit Content
Discussion GroupsASP.NETWindows FormsLanguages.NET FrameworkVisual Studio.NET
Articles.NET FrameworkASP.NETToolsWindows Forms
.NET DirectoryOpen Source ProjectsUser GroupsWeb Resources
Related Topics
Visual Basic 6SQL ServerMS AccessOther DB ProductsMS Server ProductsMore Topics ...

.NET Forum / .NET Framework / Interop / June 2005

Tip: Looking for answers? Try searching our database.

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

Thread view: 
Enable EMail Alerts  Start New Thread
Thread rating: 
Michael Kremser - 27 Jun 2005 22:28 GMT
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

Signature

http://www.mkcs.at/
The specified e-mail-address is valid and will be read.

Mattias Sjögren - 28 Jun 2005 08:20 GMT
Michael,

>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
[quoted text clipped - 4 lines]
>
>Does anyone have an idea?

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

Signature

Mattias Sjögren [MVP]  mattias @ mvps.org
http://www.msjogren.net/dotnet/ | http://www.dotnetinterop.com
Please reply only to the newsgroup.

Michael Kremser - 28 Jun 2005 13:11 GMT
Hi Mattias,

Thanks for your answer!

> 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);

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
Michael Kremser - 28 Jun 2005 13:53 GMT
I also found now another IDL file that is more specific:

HRESULT GetSObjDesc([in] long Start, [in] long Size, [out] long *Length,
[out, size_is(Size), length_is(*Length)] SOD * ODs);

Rate this thread:







Free Magazines

Get these publications absolutely FREE for up to 12 months. There are no hidden fees and no obligation. Simply choose a title, complete the application form and submit it. Read more ...

Oracle MagazineNetwork ComputingComputer WorldBio-IT WorldeWeekInformation WeekInfosecurity
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2008 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.