That is correct. The marshaler is going to trust you and the code you
are calling to have allocated (and when the call is completed, to
deallocate) whatever memory the call requires. All it knows is that you
are telling it to pass the address of an array of IntPtr to the
unmanaged code. It will pin the array in memory for the duration of the
call, and then it's up to you to manage the memory (ReleaseComObject(),
FreeCoTaskMem(), etc.) that the unmanaged code allocated for you.

-Andy

-----Original Message-----
From: Moderated discussion of advanced .NET topics.
[mailto:ADVANCED-DOTNET@;DISCUSS.DEVELOP.COM] On Behalf Of Thomas
Tomiczek
Sent: Saturday, October 19, 2002 9:18 AM
To: [EMAIL PROTECTED]
Subject: Re: [ADVANCED-DOTNET] FW: Interop: Handling OUT parameter of
array, gets error "Can not use SizeParamIndex for byref array
parameters."??


Thanks a lot Andrew, but there is one thing I dont get here...

  void Next(int cPins, [MarshalAs(UnmanagedType.LPArray)] IntPtr[]
ppPins, out int pcFetched);

and

    pinArray = new IntPtr[size];
    pinEnum.Next(size, pinArray, out fetched);

Does the Marshaller trust me that the size in pinArray is big enough? I
mean, if I work with my unmanaged code blocks, then he has no choice,
but here - he can hardly know where the stuff is written in the croutine
called.

Thomas Tomiczek
THONA Consulting Ltd.
(Microsoft MVP C#/.NET)

You can read messages from the Advanced DOTNET archive, unsubscribe from Advanced 
DOTNET, or
subscribe to other DevelopMentor lists at http://discuss.develop.com.

Reply via email to