{"id":309,"date":"2012-04-24T19:49:48","date_gmt":"2012-04-24T23:49:48","guid":{"rendered":"http:\/\/templesystems.com\/?page_id=309"},"modified":"2012-04-24T19:49:56","modified_gmt":"2012-04-24T23:49:56","slug":"stdglobalinterfacetable","status":"publish","type":"page","link":"https:\/\/templesystems.com\/?page_id=309","title":{"rendered":"StdGlobalInterfaceTable"},"content":{"rendered":"<p>StdGlobalInterfaceTable provides a way for COM objects to be used from multiple threads in an application, when the threading model of the object doesn&#8217;t allow the cross-thread calls to be made from the pointer returned when the object was created.<\/p>\n<p>The sequence of events is as follows:<\/p>\n<ol>\n<li>Create the com object on some thread.<\/li>\n<li>Get a StdGlobalInterfaceTable object.<\/li>\n<li>Register the interface with the Global Interface Table.<\/li>\n<li>Using the cookie returned when the object was registered, get a safe pointer from any thread.<\/li>\n<li>Use that pointer to make calls on the interface.<\/li>\n<\/ol>\n<p>&nbsp;<\/p>\n<p><strong>Create the COM object:<\/strong><\/p>\n<p>IDspPtr m_pDspX;<\/p>\n<p>HRESULT hr = m_pDspX.CreateInstance(__uuidof(Dsp));<\/p>\n<p><strong>Now create a StdGlobalInterfaceTable object:<\/strong><\/p>\n<p>CComPtr&lt;IGlobalInterfaceTable&gt; pGIT;<\/p>\n<p>hr = CoCreateInstance(CLSID_StdGlobalInterfaceTable,<br \/>\nNULL,<br \/>\nCLSCTX_INPROC_SERVER,<br \/>\nIID_IGlobalInterfaceTable,<br \/>\n(void **)&amp;pGIT);<\/p>\n<p><strong>Now register our object with the GIT:<\/strong><\/p>\n<p>DWORD m_dsp_cookie;<br \/>\nhr = pGIT-&gt;RegisterInterfaceInGlobal(m_pDspX, __uuidof(IDsp), &amp;m_dsp_cookie);<br \/>\n\/\/ m_dsp_cookie now gives us a way to access the dsp from different threads<\/p>\n<p><strong>Use the GIT to get a pointer to the object (in a function that can be called from any thread)<\/strong><\/p>\n<p>bool CPecoDsp::ReadProbe(int Mask)<br \/>\n{<br \/>\nIDspPtr pDsp;<br \/>\nHRESULT hr = pGIT-&gt;GetInterfaceFromGlobal( m_dsp_cookie, __uuidof(IDsp), (void**)&amp;pDsp );<br \/>\nif(FAILED(hr))<br \/>\n{<br \/>\npDsp = NULL;<br \/>\nreturn false;<br \/>\n}<br \/>\nreturn true;<br \/>\n}<\/p>\n","protected":false},"excerpt":{"rendered":"<p>StdGlobalInterfaceTable provides a way for COM objects to be used from multiple threads in an application, when the threading model of the object doesn&#8217;t allow the cross-thread calls to be made from the pointer returned when the object was created. &hellip; <a href=\"https:\/\/templesystems.com\/?page_id=309\">Continue reading <span class=\"meta-nav\">&rarr;<\/span><\/a><\/p>\n","protected":false},"author":1,"featured_media":0,"parent":305,"menu_order":0,"comment_status":"open","ping_status":"open","template":"","meta":{"footnotes":""},"class_list":["post-309","page","type-page","status-publish","hentry"],"_links":{"self":[{"href":"https:\/\/templesystems.com\/index.php?rest_route=\/wp\/v2\/pages\/309","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/templesystems.com\/index.php?rest_route=\/wp\/v2\/pages"}],"about":[{"href":"https:\/\/templesystems.com\/index.php?rest_route=\/wp\/v2\/types\/page"}],"author":[{"embeddable":true,"href":"https:\/\/templesystems.com\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/templesystems.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=309"}],"version-history":[{"count":3,"href":"https:\/\/templesystems.com\/index.php?rest_route=\/wp\/v2\/pages\/309\/revisions"}],"predecessor-version":[{"id":312,"href":"https:\/\/templesystems.com\/index.php?rest_route=\/wp\/v2\/pages\/309\/revisions\/312"}],"up":[{"embeddable":true,"href":"https:\/\/templesystems.com\/index.php?rest_route=\/wp\/v2\/pages\/305"}],"wp:attachment":[{"href":"https:\/\/templesystems.com\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=309"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}