ComPtr vs CComPtr, As vs QueryInterface
See the question and my original answer on StackOverflowWhat's nice about those class is you have the source, in C:\Program Files (x86)\Windows Kits\10\Include\10.0.18362.0\winrt\wrl\client.h
(adapt to your context and Visual Studio version):
template <typename T>
class ComPtr
{
public:
typedef T InterfaceType;
...
// query for U interface
template<typename U>
HRESULT As(_Inout_ Details::ComPtrRef<ComPtr<U>> p) const throw()
{
return ptr_->QueryInterface(__uuidof(U), p);
}
// query for U interface
template<typename U>
HRESULT As(_Out_ ComPtr<U>* p) const throw()
{
return ptr_->QueryInterface(__uuidof(U), reinterpret_cast<void**>(p->ReleaseAndGetAddressOf()));
}
// query for riid interface and return as IUnknown
HRESULT AsIID(REFIID riid, _Out_ ComPtr<IUnknown>* p) const throw()
{
return ptr_->QueryInterface(riid, reinterpret_cast<void**>(p->ReleaseAndGetAddressOf()));
}
...
};
So, yes, As
basically calls QueryInterface
underneath.