PTConvertDevModeToPrintTicket function

Converts a DEVMODE structure to a print ticket inside an IStream.


HRESULT PTConvertDevModeToPrintTicket(
  HPTPROVIDER       hProvider,
  ULONG             cbDevmode,
  PDEVMODE          pDevmode,
  EPrintTicketScope scope,
  IStream           *pPrintTicket



A handle to an open print ticket provider. This handle is returned by the PTOpenProvider or the PTOpenProviderEx function.


The size of the DEVMODE in bytes.


A pointer to the DEVMODE.


A value that specifies the scope of pPrintTicket. This value can specify a single page, an entire document, or all documents in the print job. Settings in pDevmode that are outside the specified scope will not be included in pPrintTicket. See Remarks.


A pointer to an IStream with its seek position at the beginning of the print ticket.

Return Value

If the operation succeeds, the return value is S_OK, otherwise the HRESULT contains an error code.

If hProvider was opened in a different thread, the HRESULT is E_INVALIDARG.

For more information about COM error codes, see Error Handling.


Note  This is a blocking or synchronous function and might not return immediately. How quickly this function returns depends on run-time factors such as network status, print server configuration, and printer driver implementation—factors that are difficult to predict when writing an application. Calling this function from a thread that manages interaction with the user interface could make the application appear to be unresponsive.
hProvider must be a handle that was opened in the same thread as the thread in which it is used for this function.

If the pDevmode points to a different printer, its settings may be lost and replaced with defaults.

Settings in pDevmode that are outside the scope are not included in pPrintTicket. For example, if the scope is a single page, then job-wide settings and document-wide settings are not included. A job scope includes document scope and page scope. A document scope includes page scope.

PTConvertDevModeToPrintTicket writes the print ticket to the IStream referenced by pPrintTicket starting at the stream's current seek point. After PTConvertDevModeToPrintTicket returns, the caller must reset the seek point to the initial seek point to read the print ticket returned by the function.


Minimum supported client Windows XP [desktop apps only]
Minimum supported server Windows Server 2003 [desktop apps only]
Target Platform Windows
Header prntvpt.h
Library Prntvpt.lib
DLL Prntvpt.dll

See Also

Print Schema

Print Spooler API Functions