com_obj: Add CoCreateInstance constructor

When using winstd::com_obj<> as a member of another class and we want
to create an instance of the object in another class' constructor, this
comes convenient.

Signed-off-by: Simon Rozman <simon@rozman.si>
This commit is contained in:
Simon Rozman 2023-03-08 08:21:49 +01:00
parent fc0060d3bd
commit 1d206602e6

View File

@ -84,6 +84,21 @@ namespace winstd
WINSTD_DPLHANDLE_IMPL(com_obj, NULL)
public:
///
/// Creates a new instance of a class
///
/// \sa [CoCreateInstance function](https://msdn.microsoft.com/en-us/library/windows/desktop/ms686615.aspx)
///
com_obj(
_In_ REFCLSID rclsid,
_In_opt_ LPUNKNOWN pUnkOuter,
_In_ DWORD dwClsContext)
{
HRESULT hr = CoCreateInstance(rclsid, pUnkOuter, dwClsContext, __uuidof(T), (LPVOID*)&m_h);
if (FAILED(hr))
throw com_runtime_error(hr, "CoCreateInstance failed");
}
///
/// Queries the object for another interface and creates new class with it
///