I have the following atl com object method:
CGraph::Test(LONG* size, BYTE** pByteBuf)
{
*size = 5;
*pByteBuf = (BYTE*)CoTaskMemAlloc((*size));
for(int i=0; i< *size; i++)
{
pByteBuf[0][i] = i;
}
return S_OK;
}
I have edited the il for this method:
public hidebysig newslot virtual
instance void Test([out] int32& size, [out] native int & pByteBuf)
The C# code is the following:
int numBytes = 0;
IntPtr buffer = IntPtr.Zero;
byte [] array = null;
graph.Test(out numBytes, out buffer);
if (numBytes > 0 && buffer != IntPtr.Zero)
{
array = new byte[numBytes];
Marshal.Copy(buffer, array, 0, numBytes);
}
When I look the at the values in the array, only the first value is correct and rest of them are incorrect. Any ideas what I am doing incorrectly?
TDC - 24 Jul 2006 13:09 GMT
You didn't pre-allocate the byte array.
Tom
> The C# code is the following:
>
[quoted text clipped - 11 lines]
>
> When I look the at the values in the array, only the first value is correct and rest of them are incorrect. Any ideas what I am doing incorrectly?