locked
Error when adding a feature in convertDevModeToPrintTicket

    Question

  • Hello!

    I am investigating the possibility of augmenting PrintCapabilities in JavaScript constraints for v4 print driver to add features which are not generated by GPD or PPD file. I implemented completePrintCapabilities where I add new feature (say, ns0000:PageTestFeature) to printCapabilites object.

    Then I use custom desktop Printer Extension to edit PrintTicket object and add this new feature to printTicket since the new feature doesn't appear in PrintTicket by default.

    However the new feature is not persisted when I close and reopen default Printing preferences (I open the dialog from "Devices and Printers"), so I decided to persist the new feature into private part of DevMode by using DEVMODE Property Bag and convertPrintTicketToDevMode/convertDevModeToPrintTicket functions.

    But when I implemented convertDevModeToPrintTicket to read from DevMode and add the new feature to PrintTicket I began to experience problems. In my custom desktop Printer Extension I am getting the OLE_E_ADVISENOTSUPPORTED error when accessing XmlNode property from IPrintSchemaCapabilities object. And also when printing from Metro-style application the standard Metro-style printing preferences dialog shows the following error:

    "There was a problem connecting to your printer. Make sure it's connected and try again."

    Is that a bug in Windows 8 Consumer Preview or adding features in convertDevModeToPrintTicket is not supported?


    Thursday, March 29, 2012 6:52 AM

Answers

  • Hi Eric,

    I found a workaround for the problem.

    The problem seems to be caused by the way I declared the namespace for the new Feature element in PrintTicket:

    <?xml version="1.0"?>
    <psf:PrintTicket xmlns:psf="http://schemas.microsoft.com/windows/2003/08/printing/printschemaframework"
        xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
        xmlns:xsd="http://www.w3.org/2001/XMLSchema"
        xmlns:ns0000="..."
        xmlns:psk="http://schemas.microsoft.com/windows/2003/08/printing/printschemakeywords" version="1">
    ...
      <Feature xmlns="http://schemas.microsoft.com/windows/2003/08/printing/printschemaframework" name="ns0000:PageTestFeature">
        <Option name="ns0000:TestValu1"/>
      </Feature>
    </psf:PrintTicket>
    
    Note that there is no namespace prefix for Feature and Option, but rather a declaration of default namespace for the scope of the added Feature element. Even though this is a valid PrintTicket XML it seems to cause problems somewhere in the print subsystem.

    After I changed to use namespace prefixes for Feature and Option elements, the problem disappeared.

    Friday, March 30, 2012 6:03 AM
  • Kondakovdmitry,

    Did you run this PrintTicket through PTConform? How did it come out?

    Regardless of whether this is sound XML, I'd recommend you follow the pattern that most PrintTicket and PRintCapabilities documents follow because many there may be application incompatibilities when working with certain apps.

    I'd also like to note that we recommend that you only use the JavaScript constraint functionality to add features which cannot be created using GPD or PPD only configuration. Nested Features and ParameterDefs tend to be the primary scenarios where this is necessary. Otherwise, you're incurring unnecessary performance degradation for something that can be handled on your behalf.

    Thanks

    Justin


    Friday, March 30, 2012 4:56 PM

All replies

  • kondakovdmitry,

    I will look in to this for you.

    Best Wishes - Eric

    Thursday, March 29, 2012 5:47 PM
    Moderator
  • kondakovdmitry,

    Could you send me a stack trace from the point you get the OLE_E_ADVISENOTSUPPORTED error?

    Best Wishes - Eric

    Friday, March 30, 2012 4:33 AM
    Moderator
  • Here is the exception with the stack trace:

    System.Runtime.InteropServices.COMException (0x80040003): This implementation doesn't take advises (Exception from HRESULT: 0x80040003 (OLE_E_ADVISENOTSUPPORTED))

       at PrinterExtensionLib.IPrintSchemaCapabilities.get_XmlNode()
       at Microsoft.Samples.Printing.PrinterExtension.PrintSchemaCapabilities.get_XmlNode() in c:\Users\d.kondakov\Documents\Visual Studio 11\Samples\Printer extension sample1\PrinterExtensionLibrary\PrinterExtensionAdapters.cs:line 1256

    Friday, March 30, 2012 5:05 AM
  • Hi Eric,

    I found a workaround for the problem.

    The problem seems to be caused by the way I declared the namespace for the new Feature element in PrintTicket:

    <?xml version="1.0"?>
    <psf:PrintTicket xmlns:psf="http://schemas.microsoft.com/windows/2003/08/printing/printschemaframework"
        xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
        xmlns:xsd="http://www.w3.org/2001/XMLSchema"
        xmlns:ns0000="..."
        xmlns:psk="http://schemas.microsoft.com/windows/2003/08/printing/printschemakeywords" version="1">
    ...
      <Feature xmlns="http://schemas.microsoft.com/windows/2003/08/printing/printschemaframework" name="ns0000:PageTestFeature">
        <Option name="ns0000:TestValu1"/>
      </Feature>
    </psf:PrintTicket>
    
    Note that there is no namespace prefix for Feature and Option, but rather a declaration of default namespace for the scope of the added Feature element. Even though this is a valid PrintTicket XML it seems to cause problems somewhere in the print subsystem.

    After I changed to use namespace prefixes for Feature and Option elements, the problem disappeared.

    Friday, March 30, 2012 6:03 AM
  • kondakovdmitry,

    Excellent news!  Great job.  I have marked your response as the correct answer. 

    Best Wishes - Eric

    Friday, March 30, 2012 6:40 AM
    Moderator
  • Thank you, Eric!

    But note, that it's just a workaround and it seems to be a bug in Windows 8 Consumer Preview - it should not restrict the way XML namespaces are declared, provided that the XML is a valid PrintTicket.

    Best regards,

      Dmitry.

    Friday, March 30, 2012 7:15 AM
  • Kondakovdmitry,

    Did you run this PrintTicket through PTConform? How did it come out?

    Regardless of whether this is sound XML, I'd recommend you follow the pattern that most PrintTicket and PRintCapabilities documents follow because many there may be application incompatibilities when working with certain apps.

    I'd also like to note that we recommend that you only use the JavaScript constraint functionality to add features which cannot be created using GPD or PPD only configuration. Nested Features and ParameterDefs tend to be the primary scenarios where this is necessary. Otherwise, you're incurring unnecessary performance degradation for something that can be handled on your behalf.

    Thanks

    Justin


    Friday, March 30, 2012 4:56 PM