My app have to windows. Depending on which the print is called from we getting the actual hWnd.
My issue is how to to get an instance of printManager or is there another way to print from winui 3?
// file: MainWindow.xaml.cpp
...
#include <Printmanagerinterop.h>
...
// Manually define CLSID_PrintManager
DEFINE_GUID(CLSID_PrintManager, 0x92788047, 0x3b5e, 0x41c7, 0x86, 0x2e, 0x4c, 0xd3, 0x0d, 0x45, 0xa3, 0x10);
...
void MainWindow::printFrameworkElement(FrameworkElement const& element)
{
using namespace winrt::Windows::Graphics::Printing;
using namespace Windows::Graphics::Printing;
using namespace winrt::Microsoft::UI::Xaml::Printing;
// Retrieve the window handle (HWND) of the current WinUI 3 window.
// @see https://learn.microsoft.com/en-us/windows/apps/develop/ui-input/retrieve-hwnd
auto windowNative{ this->m_inner.as<::IWindowNative>() };
HWND hWnd{ nullptr };
windowNative->get_WindowHandle(&hWnd);
if (!hWnd)
{
OutputDebugStringW(L"Failed to retrieve the window handle of the current WinUI 3 window.");
return;
}
// Initialize COM library
HRESULT hr = CoInitializeEx(nullptr, COINIT_APARTMENTTHREADED);
if (FAILED(hr))
{
OutputDebugString(L"Failed to initialize COM library.\n");
return;
}
// Create an instance of IPrintManagerInterop
com_ptr<IPrintManagerInterop> printManagerInterop;
hr = CoCreateInstance(CLSID_PrintManager, nullptr, CLSCTX_INPROC_SERVER, IID_PPV_ARGS(printManagerInterop.put()));
if (FAILED(hr))
{
OutputDebugString(L"Failed to create instance of IPrintManagerInterop.\n");
return;
}
Its failing to create an instance of IPirntManagerInterop