J
Jayme Pechan
I have a ATL COM object that is loaded through Interop in a C# application.
The COM object fires an event and one of the parameters is another object
created inside the object. This object has a property on it that is also
another object.
private void pIObj_EventProc(MObj.MainObj pObj)
{
MObj.Obj mainobj = pObj.Obj;
// IF I DON'T DO THE NEXT LINE, THE APPLICATION HANGS AT SOME LATER TIME
// THE UI DOESN'T EVEN UPDATE.
System.Runtime.InteropServices.Marshal.ReleaseComObject(mainobj);
}
Property in ATL Object that returns another object...
HRESULT CMainObj::get_Obj(IObj** pVal)
{
IObj* pIObj= NULL;
CComObject<CObj>* pObj;
if (S_OK == CComObject<CObj>::CreateInstance(&pObj)
&& S_OK == pObj->QueryInterface(IID_IObj, (void**)&pIObj))
{
*pVal = pIObj;
return S_OK;
}
}
I don't fully understand interop but I'm thinking this could be the source
of my problem. Is there a way to make this reliable from the COM object
perspective? I'd rather not require the user to do the ReleaseComObject in
order to prevent their application from hanging at some random time.
Everything works correctly if the host is C++ or JScript or other such
languages.
Any help would be appreciated.
The COM object fires an event and one of the parameters is another object
created inside the object. This object has a property on it that is also
another object.
private void pIObj_EventProc(MObj.MainObj pObj)
{
MObj.Obj mainobj = pObj.Obj;
// IF I DON'T DO THE NEXT LINE, THE APPLICATION HANGS AT SOME LATER TIME
// THE UI DOESN'T EVEN UPDATE.
System.Runtime.InteropServices.Marshal.ReleaseComObject(mainobj);
}
Property in ATL Object that returns another object...
HRESULT CMainObj::get_Obj(IObj** pVal)
{
IObj* pIObj= NULL;
CComObject<CObj>* pObj;
if (S_OK == CComObject<CObj>::CreateInstance(&pObj)
&& S_OK == pObj->QueryInterface(IID_IObj, (void**)&pIObj))
{
*pVal = pIObj;
return S_OK;
}
}
I don't fully understand interop but I'm thinking this could be the source
of my problem. Is there a way to make this reliable from the COM object
perspective? I'd rather not require the user to do the ReleaseComObject in
order to prevent their application from hanging at some random time.
Everything works correctly if the host is C++ or JScript or other such
languages.
Any help would be appreciated.