|
-
April 21st, 1999, 09:38 AM
#1
How do I pass an array of BSTRs in COM?
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])
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|