Hi!

I need to pass an array of strings from a COM object to a client. I have tried with the CComArray class I found on this site, but I didn't get it to work.
Here's what I did:


<COM object>
<idl>
[id(1), helpstring("method Testing")] HRESULT Testing([out] VARIANT* p_pVar);
<source>
STDMETHODIMP CBOGraph::Testing(VARIANT* p_pVar)
{
CComArray<BSTR> array;
if (!array.Initialize(p_pVar, 1, false))
return E_FAIL;

BSTR bstrTmp;
bstrTmp = ::SysAllocString(OLESTR("teststring"));
array.SetAt(0, bstrTmp);

return S_OK;
}

<CLIENT>
void TestTesting()
{
VARIANT var;
m_pBOGraph->Testing(&var);
CComArray<BSTR> array;
if (array.Attach(&var, true))
{
BSTR d;
bool bContinue = true;
int nSize = array.Size();
for (int i = 0; bContinue && i < nSize; i++)
{
bContinue = array.GetAt(i, d);
if (bContinue)
{
CString sTmp = OLE2T(d);
TRACE(_T("TestTesting(): sTmp = %s"), sTmp);
}
}
}
}




What do I do wrong?
Or is there a better way to pass an array of strings in COM?

Thanks,
/Henrik Johansson, ([email protected])