StdGlobalInterfaceTable provides a way for COM objects to be used from multiple threads in an application, when the threading model of the object doesn’t allow the cross-thread calls to be made from the pointer returned when the object was created.
The sequence of events is as follows:
- Create the com object on some thread.
- Get a StdGlobalInterfaceTable object.
- Register the interface with the Global Interface Table.
- Using the cookie returned when the object was registered, get a safe pointer from any thread.
- Use that pointer to make calls on the interface.
Create the COM object:
HRESULT hr = m_pDspX.CreateInstance(__uuidof(Dsp));
Now create a StdGlobalInterfaceTable object:
hr = CoCreateInstance(CLSID_StdGlobalInterfaceTable,
Now register our object with the GIT:
hr = pGIT->RegisterInterfaceInGlobal(m_pDspX, __uuidof(IDsp), &m_dsp_cookie);
// m_dsp_cookie now gives us a way to access the dsp from different threads
Use the GIT to get a pointer to the object (in a function that can be called from any thread)
bool CPecoDsp::ReadProbe(int Mask)
HRESULT hr = pGIT->GetInterfaceFromGlobal( m_dsp_cookie, __uuidof(IDsp), (void**)&pDsp );
pDsp = NULL;