{"id":1873,"date":"2018-09-18T23:07:29","date_gmt":"2018-09-18T21:07:29","guid":{"rendered":"https:\/\/alax.info\/blog\/?p=1873"},"modified":"2018-09-18T23:07:29","modified_gmt":"2018-09-18T21:07:29","slug":"where-is-id3d11devicechildgetprivatedatainterface","status":"publish","type":"post","link":"https:\/\/alax.info\/blog\/1873","title":{"rendered":"Where is ID3D11DeviceChild::GetPrivateDataInterface?"},"content":{"rendered":"<p><a href=\"https:\/\/docs.microsoft.com\/en-us\/windows\/desktop\/api\/d3d11\/nn-d3d11-id3d11devicechild\"><code>ID3D11DeviceChild<\/code><\/a> similarly to a few other related interfaces offers methods including:<\/p>\n<ul>\n<li><a href=\"https:\/\/docs.microsoft.com\/en-us\/windows\/desktop\/api\/d3d11\/nf-d3d11-id3d11devicechild-getprivatedata\">ID3D11DeviceChild::GetPrivateData<\/a> &#8211; Get application-defined data from a device child.<\/li>\n<li><a href=\"https:\/\/docs.microsoft.com\/en-us\/windows\/desktop\/api\/d3d11\/nf-d3d11-id3d11devicechild-setprivatedata\">ID3D11DeviceChild::SetPrivateData<\/a> &#8211; Set application-defined data to a device child and associate that data with an application-defined GUID.<\/li>\n<li><a href=\"https:\/\/docs.microsoft.com\/en-us\/windows\/desktop\/api\/d3d11\/nf-d3d11-id3d11devicechild-setprivatedatainterface\">ID3D11DeviceChild::SetPrivateDataInterface<\/a> &#8211; Associate an <code>IUnknown<\/code>-derived interface with this device child and associate that interface with an application-defined GUID.<\/li>\n<\/ul>\n<p><code>SetPrivateDataInterface<\/code> option extends <code>SetPrivateData<\/code> by adding COM reference management to application defined data. However there is no <code>GetPrivateDataInterface<\/code>\u00e2\u20ac\u00a6 A reasonable assumption is that it is a single collection of keyed application defined data so it is possible to read interface values using <code>GetPrivateData<\/code> method. The behavior should have been documented to avoid confusion.<\/p>\n<p>I would perhaps not have posted this if there was no additional aspect. If I could read my interface values attached by <code>SetPrivateDataInterface<\/code> using <code>GetPrivateData<\/code> method, should I expect the returned values to be <code>IUnknown::AddRef<\/code>&#8216;ed or not?<\/p>\n<pre><code>ID3D11DeviceChild* p = \u00e2\u20ac\u00a6\r\nIUnknown* pUnknownA = \u00e2\u20ac\u00a6\r\np-&gt;SetPrivateDataInterface(__uuidof(MyKey), pUnknownA);\r\n\u00e2\u20ac\u00a6\r\nIUnknown* pUnknownB;\r\nUINT nDataSize = sizeof pUnknownB;\r\np-&gt;GetPrivateData(__uuidof(MyKey), &amp;nDataSize, &amp;pUnknownB);\r\n\/\/ QUES: pUnknownB is AddRef'ed or not?\r\n<\/code><\/pre>\n<p>It is indeed possible to retrieve the interface data. With no documented behavior I would expect no <code>IUnknown::AddRef<\/code> to be done. Rationale: after all I am using the method from the pair which is not supposed to deal with interface pointers. An argument against is that even though taking a raw copy of pointer is not a big deal, in multi-thread environment it might so happen that the returned unreferenced pointer is gone and invalidated if a concurrent thread replaces the collection value and internal <code>IUnknown::Release<\/code> on the pointer results in object disposal.<\/p>\n<p>My guess on the behavior in part of COM referencing was incorrect: the API <strong>does<\/strong> do <code>IUnknown::AddRef<\/code>. Also this behavior is documented in the DXGI section for <a href=\"https:\/\/docs.microsoft.com\/en-us\/windows\/desktop\/api\/dxgi\/nf-dxgi-idxgiobject-getprivatedata\"><code>IDXGIObject::GetPrivateData<\/code><\/a> method:<\/p>\n<blockquote><p>If the data returned is a pointer to an <a href=\"https:\/\/msdn.microsoft.com\/33f1d79a-33fc-4ce5-a372-e08bda378332\">IUnknown<\/a>, or one of its derivative classes, previously set by <a href=\"https:\/\/msdn.microsoft.com\/en-us\/library\/Bb174545(v=VS.85).aspx\">IDXGIObject::SetPrivateDataInterface<\/a>, you must call <a href=\"https:\/\/msdn.microsoft.com\/4b494c6f-f0ee-4c35-ae45-ed956f40dc7a\">::Release()<\/a> on the pointer before the pointer is freed to decrement the reference count.<\/p><\/blockquote>\n<p>Presumably the same behavior applies to APIs having no explicitly mentioned documented behavior, including <a href=\"https:\/\/docs.microsoft.com\/en-us\/windows\/desktop\/api\/d3d11\/nf-d3d11-id3d11device-getprivatedata\"><code>ID3D11Device::GetPrivateData<\/code><\/a> method, <a href=\"https:\/\/msdn.microsoft.com\/en-us\/windows\/desktop\/dn788700\"><code>ID3D12Object::GetPrivateData<\/code><\/a> method and other.<\/p>\n","protected":false},"excerpt":{"rendered":"<p>ID3D11DeviceChild similarly to a few other related interfaces offers methods including: ID3D11DeviceChild::GetPrivateData &#8211; Get application-defined data from a device child. ID3D11DeviceChild::SetPrivateData &#8211; Set application-defined data to a device child and associate that data with an application-defined GUID. ID3D11DeviceChild::SetPrivateDataInterface &#8211; Associate an IUnknown-derived interface with this device child and associate that interface with an application-defined GUID.&hellip; <\/p>\n<p><a class=\"moretag\" href=\"https:\/\/alax.info\/blog\/1873\">Read the full article<\/a><\/p>\n","protected":false},"author":2,"featured_media":0,"comment_status":"open","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[1],"tags":[95,408,541,329],"class_list":["post-1873","post","type-post","status-publish","format-standard","hentry","category-uncategorized","tag-com","tag-direct3d","tag-documentation","tag-msdn"],"_links":{"self":[{"href":"https:\/\/alax.info\/blog\/wp-json\/wp\/v2\/posts\/1873","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/alax.info\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/alax.info\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/alax.info\/blog\/wp-json\/wp\/v2\/users\/2"}],"replies":[{"embeddable":true,"href":"https:\/\/alax.info\/blog\/wp-json\/wp\/v2\/comments?post=1873"}],"version-history":[{"count":0,"href":"https:\/\/alax.info\/blog\/wp-json\/wp\/v2\/posts\/1873\/revisions"}],"wp:attachment":[{"href":"https:\/\/alax.info\/blog\/wp-json\/wp\/v2\/media?parent=1873"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/alax.info\/blog\/wp-json\/wp\/v2\/categories?post=1873"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/alax.info\/blog\/wp-json\/wp\/v2\/tags?post=1873"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}