i understand what the QueryInterface method actually does- it only returns a pointer to a specific interface. But my question is, why would i want to use this method?
I mean, what is the difference between
QueryInterface(__uuidof(IDXGIResource), (void**)&Resource)
and
IDXGIResource * Resource
aren't these pretty much the same? if so, why would i even need to use the method? For what reasons should i use it?
device->CreateTexture2D(&SharedTextureDesc, NULL, &SharedTexture); SharedTexture->QueryInterface(__uuidof(IDXGIResource), (void**)&SharedResource);
this would mean that, first of all, theSharedResource
pointer will now point to the texture thatSharedTexture
points to right? – EffaceQueryInterface
as COMs equivalent ofdynamic_cast
, and remember that it can fail so be sure to check the HRESULT for failure. Rather than usingQueryInterface
directly, consider making use of the Microsoft::WRL::ComPtr smart-pointer and thenAs
method which wraps this up in a more natural C++ syntax. – Gunshy