#pragma once template struct ComPtr { T *p{}; ~ComPtr() { if (p != nullptr) p->Release(); } T &operator*() const { return *p; } T **operator&() const { return &p; } T **operator&() { return &p; } T *operator->() const { return p; } template HRESULT As( U **const pp ) const { return p->QueryInterface(pp); } };