3.1.4.9.3 RpcWritePrinter (Opnum 19)

RpcWritePrinter sends data to the print server.

 DWORD RpcWritePrinter(
   [in] PRINTER_HANDLE hPrinter,
   [in, size_is(cbBuf)] BYTE* pBuf,
   [in] DWORD cbBuf,
   [out] DWORD* pcWritten
 );

hPrinter: A handle to a printer object or port object that was opened by RpcAddPrinter (section 3.1.4.2.3), RpcAddPrinterEx (section 3.1.4.2.15), RpcOpenPrinter (section 3.1.4.2.2), or RpcOpenPrinterEx (section 3.1.4.2.14).

pBuf: A pointer to a buffer that contains the data to be written. This parameter can be NULL if the value of the cbBuf parameter is zero.

cbBuf: The number of bytes of data to be written.

pcWritten: A pointer to a value that receives the number of bytes of data that were written.

Return Values: This method MUST return zero (ERROR_SUCCESS) to indicate successful completion or a nonzero Windows error code to indicate failure [MS-ERREF].

Upon receiving this message, the server MUST validate parameters as follows:

  • Perform the validation steps that are specified in PRINTER_HANDLE Parameters, section 3.1.4.1.11. This method SHOULD assume that the handle to the printer or port object can be used without further access checks.

  • Verify that a job has been associated with hPrinter using RpcStartDocPrinter, and if that verification fails, return ERROR_SPL_NO_STARTDOC [MS-ERREF].

  • Verify that printing of the job has not been canceled, and if that verification fails, return ERROR_PRINT_CANCELLED [MS-ERREF].

  • If cbBuf is not zero, verify that pBuf is not NULL.

If parameter validation fails, the server MUST fail the operation immediately and return a nonzero error response to the client. Otherwise, the server MUST process the message and compose a response to the client as follows:

  • If the hPrinter parameter is a printer object handle, copy cbBuf bytes of data pointed to by pBuf to the job; depending on server policy and settings, the data is added to temporary storage of the job (for example, a spool file), or sent directly to the port.

  • If the hPrinter parameter is a port object handle, copy cbBuf bytes of data pointed to by pBuf directly to the port.

  • Write the number of bytes that were written to the variable that is pointed to by the pcWritten parameter.

  • Return the status of the operation.

  • If the operation is successful, the server MUST modify the job object to indicate the number of bytes written so far to that job.