"Getinterfacefromglobal" method returning error code "0x8000ffff" ATL COM( win32, VC++) STA project

Rajesh_M 1 Reputation point
2020-11-09T07:22:21.797+00:00

ve implimented a ATL single thread apartment based project .

class ATL_NO_VTABLE CMySrv :
public CComObjectRootEx<ccomsinglethreadmodel>,
public CComCoClass<cmysrv,&clsid_mysrv>,
public IMySrv

In the method, I'm creating multiple worker threads and accessing the interface pointer from one context to another with using COM Interface "IGlobalInterfaceTable"

In the main thread registered the interface

void CMySrv::save()
{
HRESULT hr = 0;
/////
logic
//////
CComQIPtr<imysrv> pMySrv(GetUnknown());
CComPtr<iglobalinterfacetable> l_git;
l_git.CoCreateInstance( CLSID_StdGlobalInterfaceTable );
hr = l_git->RegisterInterfaceInGlobal(pMySrv, __uuidof(IMySrv), &dwCookie );

if(FAILED(hr))
{
//problem with REGISTER Interface....
}

for(int i=0;i<9;i++)
_beginthreadex( 0,0,&(CParllelThreadOperations::ThreadFunc),LPVOID(&dwCookie), 0, &dwThId);

////logic implemented to wait for all the child threads

if (dwCookie != 0)
{
hr =l_git->RevokeInterfaceFromGlobal(dwCookie );
if(FAILED(hr))
{
//problem with revoke Interface....
}
}

}

In the worker thread I'm passing the cookie information and would get the interface

CComPtr<iglobalinterfacetable> git;
CComPtr<imysrv> pMySrv;
HRESULT hr= 0;
if(git.CoCreateInstance( CLSID_StdGlobalInterfaceTable)>=0)
hr= git->GetInterfaceFromGlobal( dwCookie, __uuidof(IMySrv), (void**)&pMySrv);

Most time of the time the implemented code is working fine . But very few times "GetInterfaceFromGlobal" api failed and returning "0x8000ffff" error code for 8 out of 9 worker threads.

Could you please let me know what causes the "GetInterfaceFromGlobal" api to generate "0x8000ffff" error code ,
how can I avoid this scenario.

Note: I can't share the code as it's confidentiality.

Windows development Windows API - Win32
Developer technologies C++
{count} votes

Your answer

Answers can be marked as Accepted Answers by the question author, which helps users to know the answer solved the author's problem.