共用方式為


3.1.4.2.9 RpcClosePrinter (Opnum 29)

RpcClosePrinter closes a handle to a printer object, server object, job object, or port object.

 DWORD RpcClosePrinter(
   [in, out] PRINTER_HANDLE* phPrinter
 );

phPrinter: A pointer to a handle to a printer object, server object, job 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).

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 object, server object, job object, or port object can be used without further access checks.

    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 object is a printer object, and RpcStartDocPrinter has been called without a matching RpcEndDocPrinter, the same processing as for RpcEndDocPrinter MUST occur.

    If there is an active notification context associated with the object, as a result of the client not calling RpcFindClosePrinterChangeNotification, the server MUST close the notification context now by calling the client's RpcReplyClosePrinter method.

  • Free any internal state that is associated with the handle that is pointed to by phPrinter.

  • Store NULL in the variable that is pointed to by phPrinter.

  • Decrement the reference count on that object.

  • If the object is a printer object marked as "Delete Pending", and the usage count is zero, the following steps MUST be performed:

    • Handle any pending jobs in an implementation-specific manner.

    • Clear references to this printer from any other data structures.

    • Delete the printer object.

  • Return the status of the operation.