Marshall [out] arrays?

May 1, 2010 at 10:53 AM
Edited May 1, 2010 at 11:01 AM
I'm trying to import an interface with conformant C-Style Arrays:
interface ITest: IUnknown
{
  HRESULT setBuf([in] long size, [in, size_is(size)] byte* buf);
  HRESULT getBuf([out] long* size, [out, size_is(, *size)] byte** buf);
}
There is no problem with setBuf(), I've created ConvertTo() action for tlbimp2
    <Action Name="ConvertTo">
      <Parameter Key="Direction" Value="[In]" />
      <Parameter Key="ByRef" Value="False" />
      <Parameter Key="ManagedType" Value="LPArray" />
      <Parameter Key="MarshalAs" Value="(default)" />
      <Parameter Key="Attributes" Value="[SizeParamIndexOffset=-1]" />
    </Action>
and it's marshalled as
public virtual extern void setBuf(int size, byte[] buf);
(I would like to get rid of size but can live with such signature). But how to handle getBuf()? Direct
    <Action Name="ConvertTo">
      <Parameter Key="Direction" Value="[Out]" />
      <Parameter Key="ByRef" Value="True" />
      <Parameter Key="ManagedType" Value="LPArray" />
      <Parameter Key="MarshalAs" Value="(default)" />
      <Parameter Key="Attributes" Value="[SizeParamIndexOffset=-1]" />
    </Action>
gives
public virtual extern void getBuf(out int size, out IntPtr[] buf);
while I need
public virtual extern void getBuf(out int size, out byte[] buf);
Any idea?