GIT Catastropic Error !

G

Guest

Hi Friends,
_____________________________________________________________________
Operating System: Windows XP
Language :Vc++ 6.0
_____________________________________________________________________
FinalConstruct Finalrelease
(Thread and Event Creation) (Thread and event handle Closed)


(called from client)
ThreadFunction Incoming
Interface Function
Wait for signal from main thread signals the
workerthread

When thread function receives the signal from Incoming Interface Function it
calls the public function of the class (connection point helper).Inside this
it callback to the client. The code for this is given below

||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
int nsize=p->m_vec.GetSize();

for(int index=0;index<nsize;index++)
{
CComPtr<IUnknown> pUnk = p->m_vec.GetAt(index);
if(pUnk != NULL)
{
CComQIPtr<IsampleEvent> pIsampleEvent(pUnk);
hr = pIsampleEvent ->Callback (m_pCurrentCassette, m_setBy);
}
}

||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
************************************************************
In the IConnectionPointImpl<CSampleConPt,&IID_IOutConPt,
CComDynamicUnkArray_GIT> this class is added for GIT .so whenever the client
calls the advise marshaled interface pointer will be added to the
vector(GIT). This is the interface pointer getting from the vector.

here when the interface pointer calls the callback function of client it
fails with catastrophic error.
************************************************************
what could be the case ?

Thanks in advance,
David
 
Joined
Nov 21, 2008
Messages
1
Reaction score
0
I had the same problem.
Here's the solution:

#pragma once

#pragma warning(disable:4530) //Template memory warning
#pragma warning(disable:4786) //Template memory warning

#include <map>
#include <comdef.h>
#include <atlcom.h>
#include <comutil.h>
using namespace std;

class CComDynamicUnkArray_GIT : public CComDynamicUnkArray
{
private:
CComPtr<IGlobalInterfaceTable> GIT;

public:

CComDynamicUnkArray_GIT() : CComDynamicUnkArray(),
GIT(NULL)
{
_com_util::CheckError(
GIT.CoCreateInstance(CLSID_StdGlobalInterfaceTable, NULL, CLSCTX_INPROC_SERVER));





}

~CComDynamicUnkArray_GIT()
{
clear();
GIT.Release();
}



DWORD Add(IUnknown* pUnk);
BOOL Remove(DWORD dwCookie);

CComPtr<IUnknown> GetAt(int nIndex)
{
IUnknown * p1 = CComDynamicUnkArray::GetAt(nIndex);
if(NULL == p1)
{
ATLASSERT(0);
return NULL;
}

DWORD dwCookie = CComDynamicUnkArray::GetCookie(&p1);
if( dwCookie == 0 )
{
ATLASSERT(0);
return NULL;
}

if( CookieMap.find( dwCookie ) == CookieMap.end() )
{
ATLASSERT(0);
return NULL;
}

CComPtr<IUnknown> ppv;

HRESULT hr = GIT->GetInterfaceFromGlobal(
CookieMap[dwCookie], //Cookie identifying the desired global
//interface and its object
__uuidof(IUnknown), //IID of the registered global interface
reinterpret_cast< void** >(&ppv) //Indirect pointer to the desired interface
);

if(FAILED(hr)) // would be better not to swallow this hr, but we must not break
// CComDynamicUnkArray::GetAt's signature that just returns NULL in case of failure
{
ATLASSERT(0);
return NULL;
}

return ppv;
}

void clear()
{
CComDynamicUnkArray::clear();

CookieMap_t::iterator iter;
for( iter = CookieMap.begin(); iter != CookieMap.end(); ++iter )
{
#pragma warning(disable: 4189)
HRESULT hr = GIT->RevokeInterfaceFromGlobal(
iter->second //Cookie that was returned from
//RegisterInterfaceInGlobal
);
ATLASSERT(SUCCEEDED(hr));
}

CookieMap.clear();
}

int GetSize() const
{
// CComDynamicUnkArray::GetSize() returns 4 regardless if less than 4 CPs are registered :-(
return CookieMap.size();
}

protected:
typedef map< DWORD, DWORD > CookieMap_t;
CookieMap_t CookieMap; // < CComDynamicUnkArray_Key , GIT_Key>
};

inline DWORD CComDynamicUnkArray_GIT::Add(IUnknown* pUnk)
{
DWORD Result = CComDynamicUnkArray::Add( pUnk );
if(0 == Result)
{
ATLASSERT(0);
return 0;
}

DWORD pdwCookie = 0;

HRESULT hr = GIT->RegisterInterfaceInGlobal(

pUnk, //Pointer to interface of type riid of object
//containing global interface
__uuidof(IUnknown), //IID of the interface to be registered
&pdwCookie //Supplies a pointer to the cookie that provides
//a caller in another apartment access to the
//interface pointer
);

if(FAILED(hr)) //it would be better not to swallow this hr but CComDynamicUnkArray::Add would return 0 on error
{
ATLASSERT(0);
return 0;
}

CookieMap[Result] = pdwCookie;
return Result;
}

inline BOOL CComDynamicUnkArray_GIT::Remove(DWORD dwCookie)
{
BOOL Result = CComDynamicUnkArray::Remove( dwCookie );
if(FALSE == Result)
{
ATLASSERT(0);
return FALSE;
}

HRESULT hr = GIT->RevokeInterfaceFromGlobal(CookieMap[dwCookie]);
if(FAILED(hr)) // it would be better not to swallow this hr, but CComDynamicUnkArray::Remove returns FALSE on error
{
ATLASSERT(0);
return FALSE;
}

CookieMap.erase(dwCookie);
return Result;
}
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top