locked
[UWP][C++] Getting rid of Print dialog when printing fails. RRS feed

  • Question

  • I am currently having a problem printing on Phone when printing fails, users get stuck with the following view until they hit the back button manually:

    The view above shows up when the user submits a print job by clicking Print from the Print dialog after selecting their print options.

    We have a fairly complex printing system in place, to print PDF using XPS directly via COM APIs. This sometimes fails when certain things are not available on the system (like creating an instance of XpsOMObjectFactory).

    We have derived a class from IPrintDocumentPageSource and provide an implementation of MakeDocument. When something fails in MakeDocument, we can notify the user of the problem, but we don't know how to get rid of the above screen.

    Any advice?

    Thanks,
    Tomas

    Tuesday, December 20, 2016 11:29 PM

All replies

  • Hi T Hofmann,

    >>This sometimes fails when certain things are not available on the system (like creating an instance of XpsOMObjectFactory).

    We are trying to reproduce the issue you encountered, but we failed. When we reproduce that, we are confused that what you have done with creating XpsOMObjectFactory instance and some other failed things. Could you give me more information for reproducing it?

    Best regards,
    Breeze Liu



    MSDN Community Support
    Please remember to click "Mark as Answer" the responses that resolved your issue, and to click "Unmark as Answer" if not. This can be beneficial to other community members reading this thread. If you have any compliments or complaints to MSDN Support, feel free to contact MSDNFSF@microsoft.com.

    Wednesday, December 21, 2016 11:04 AM
  • Hi Breeze Liu,

    Thanks for getting back. The essence of this ticket is what to do when it fails, rather than trying to figure out why it fails (Thought that would be very valuable too).

    Either way, the code that fails is as follows:

    HRESULT hr = S_OK;
    
    ...
    
    IXpsOMObjectFactory *printableXpsFactory = NULL;
    if (SUCCEEDED(hr))         
    {
    	hr = CoCreateInstance(__uuidof(XpsOMObjectFactory), NULL, CLSCTX_INPROC_SERVER, __uuidof(IXpsOMObjectFactory), reinterpret_cast<LPVOID*>(&printableXpsFactory));
    	

    The call to CoCreateInstance returns an HRESULT of REGDB_E_CLASSNOTREG, Class not registered. This code works flawlessly on PCs.

    The other thing I am struggling with is what to do when this fails. According to documentation, IPrintDocumentPageSource::MakeDocument should return S_OK if successful, and an "appropriate" HRESULT otherwise. We have tried to make IPrintDocumentPageSource::MakeDocument return the hr from the code above, we have tried to make it return just E_FAIL, and we have tried to make it throw an exception. In either case, the view in my original message shows up.
    Even if we can make the call to CoCreateInstance work, there are other reasons the code might fail though, so we would still like to have a permanent solution for the print job failing.

    Thanks,

    Tomas Hofmann

    Wednesday, December 21, 2016 5:40 PM
  • @Tomas,

    I don't have a phone right now so I want to clarify just a simple question.

    >>This code works flawlessly on PCs.

    Do you mean that on PCs you will not get the view in your original message? Or maybe you can also reproduce it from your PC?

    The view you meet seems to be a system dialog and I didn't see any code which will create this view when I checked some exist samples from UWP official sample or from old Windows 8 3D printing sample. I will do some further research on this.

    Best regards,

    Barry 


    MSDN Community Support
    Please remember to click "Mark as Answer" the responses that resolved your issue, and to click "Unmark as Answer" if not. This can be beneficial to other community members reading this thread. If you have any compliments or complaints to MSDN Support, feel free to contact MSDNFSF@microsoft.com.

    Friday, December 23, 2016 3:56 PM
  • Hi,

    I should clarify. Sorry for being vague.

    >>This code works flawlessly on PCs.
    Means that the call to CoCreateInstance returns S_OK on a PC, and the printableXpsFactory is set and usable.
    On Phones, the call to
    CoCreateInstance returns REGDB_E_CLASSNOTREG, and printableXpsFactory remains null.

    The dialog you see on the screenshot is a system dialog that (to the best of my knowledge) shows up when MakeDocument takes a while. I have nothing to do with that dialog. When print is pressed, MakeDocument is called from the system, and that dialog shows up.

    We have a class implementing both IPrintDocumentSource and IPrintDocumentPageSource, and we set this as a source to PrintTaskRequestedEventArgs->SetSource.
    If you want to see the dialog above, I think making MakeDocument take some time is enough.

    Please let me know if you need more information. I will be away the next week though.

    Thanks for your help.

    Tomas

    Friday, December 23, 2016 6:15 PM