TCPMON Xcv 接口

本部分介绍标准 TCP/IP 端口监视器(TCPMON)的转译 (Xcv) 接口。 This interface, which is implemented using XcvData and XcvDataPort function calls, enables those using it to configure a TCP/IP printer port or to obtain information about a TCP/IP printer port configuration. 本节中所述的 Xcv 接口特定于 TCP/IP 端口。 其他 Xcv 接口可能可用于其他端口类型。

To obtain a handle to an Xcv interface for either a local machine or a remote machine, call the OpenPrinter function. 下面的代码示例演示如何获取端口的 Xcv 句柄:

HANDLE hXcv = INVALID_HANDLE_VALUE;
PRINTER_DEFAULTS Defaults = { NULL, NULL, <Required Access> };

// Handle to a local machine
if (OpenPrinter(",XcvPort <PortName>", &hXcv, &Defaults )
{
 // hXvc contains an Xcv data handle to a local TCPMON port
}

// Handle to a remote machine
if (OpenPrinter("<ServerName>\\,XcvPort <PortName>", &hXcv, &Defaults )
{
 // hXvc contains an Xcv data handle to a TCPMON port on <ServerName>
}

In the code example, ServerName and PortName represent server and port name strings. 获取句柄后,可以查询特定于 TCPMON 端口监视器的信息,也可以更改端口配置。 Note that the access you require for the port monitor must be specified in the DesiredAccess member of the PRINTER_DEFAULTS structure or pass NULL if no special security is required. For certain calls to the XcvData function, such as when the AddPort and DeletePort commands are specified (see TCPMON Xcv Commands), SERVER_ACCESS_ADMINISTER privilege is required. For details about the OpenPrinter function and the access rights that may be requested in the PRINTER_DEFAULTS structure, see the OpenPrinter function documentation.

如果端口尚不存在,可以通过指定监视器名称从服务器获取 Xcv 句柄。 (对于标准 TCP/IP 端口监视器端口,这是“标准 TCP/IP 端口”。下面的代码示例演示如何获取端口监视器的 Xcv 数据句柄:

HANDLE hXcv = INVALID_HANDLE_VALUE;
PRINTER_DEFAULTS Defaults = { NULL, NULL, <Required Access> };

// Handle to a local machine
if (OpenPrinter(",XcvMonitor <MonitorName>", &hXcv, &Defaults )
{
 // hXcv contains an Xcv data handle to the monitor <MonitorName>
}

// Handle to a remote machine
if (OpenPrinter("<ServerName>\\,XcvMonitor <MonitorName>", &hXcv, &Defaults )
{
 // hXcv contains an Xcv data handle to the monitor 
 // <MonitorName> on the server <ServerName>
}

In the code example, ServerName and PortName represent server and port name strings. Once you have obtained the Xcv data handle, you can issue instructions and requests to the monitor by calling the XcvData function.

Note that the return value from the XcvData function indicates only whether the data was correctly sent to the port monitor. A return value of TRUE does not indicate that the operation was successful. To determine whether the operation was successful, inspect the value in *pdwStatus. 下表汇总了这些状态值:

Status value Meaning
NO_ERROR 此操作成功。
ERROR_ACCESS_DENIED 用户没有足够的权限。 该命令需要SERVER_ACCESS_ADMINISTER特权。
ERROR_INSUFFICIENT_BUFFER 输出缓冲区是必需的,但小于必需。
ERROR_INVALID_DATA An input buffer is required, but the pointer to it is NULL, or the size of the input buffer is smaller than required.
ERROR_INVALID_HANDLE Xcv 数据句柄无效。
ERROR_INVALID_LEVEL 输入或输出数据结构不是正确的版本。
ERROR_INVALID_PARAMETER An output buffer is required, but it is NULL, or the output required parameter is NULL and the output buffer is too small, or the standard TCP/IP port monitor does not understand the command being issued.