Re: Creating an object an an output parameter
Igor,
This all seems to work but when I return from the call the object has not been
created.
Here is the method that creates the object;
STDMETHODIMP CSomeObj::Extract(RECT roi, ISomeObj** pSomeObjOut)
{
CComObject<CSomeObj>* pSomeObj = 0;
CComObject<CSomeObj>::CreateInstance(&pSomeObj);
pSomeObj ->AddRef();
....
....
....
hr = pSomeObj->QueryInterface(&pSomeObjOut);
pSomeObj ->Release();
return hr;
}
And here is the code that calls the method, and when it returns pNewSomeObj
is NULL. I don't know if it's because I'm using a smart pointer and it goes
out
of scope.
RECT roi;
CComPtr<ISomeObj> pNewSomeObj;
HRESULT hr = pSomeObj->ExtractROI(roi, &pNewSomeObj);
Any help would be greatly appreciated.
"Igor Tandetnik" wrote:
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