Categories: MSDN / DotNet / Java / Scripts / Linux / PHP Ask - La ask - La Answer

Passing Arrays in COM

Need help with passing a BYTE array in COM.

I think i have done it right but i only get the first byte passed.

Here is the idl:

interface ICOMtestObject : IUnknown
{
[id(1), helpstring("method GetData")] HRESULT GetData([out]ULONG *sz,[out,size_is(,*sz)]BYTE **data);
};

Here is the implementation in the COM server:

STDMETHODIMP CCOMtestObject::GetData(ULONG *sz, BYTE **data)
{
// TODO: Add your implementation code here

*data = (BYTE*)CoTaskMemAlloc( 5 * sizeof( BYTE));

(*data)[0]='T';
(*data)[1]='e';
(*data)[2]='s';
(*data)[3]='t';
(*data)[4]='\0';
*sz=5;
return S_OK;
}

Here is the implementation in the client:

HRESULT hr = m_objPtr.CoCreateInstance(L"Comtest.COMtestObject.1");

ULONG sz;BYTE *data;
hr = m_objPtr->GetData(&sz,&data);

The data array includes only the first byte.

Please help me with this one.
[1042 byte] By [Johan Odin] at [2007-11-11 8:13:28]