我正在尝试使用 XcvData 读取打印机端口配置,但它失败并出现错误 87(无效参数)。添加端口或设置端口配置我没有问题。我已经看到了一些 c# 代码示例,它们完全符合我的要求,所以我不确定是什么导致了失败。任何建议将不胜感激。谢谢。
示例代码:
PRINTER_DEFAULTS defaults = { NULL, NULL, SERVER_ACCESS_ADMINISTER };
HANDLE hPrinter;
if (::OpenPrinter(L", XcvMonitor Standard TCP/IP Port", hPrinter, &defaults))
{
CONFIG_INFO_DATA_1 configInfoData1;
memset(&configInfoData1, 0, sizeof(configInfoData1));
configInfoData1.dwVersion = 1;
PORT_DATA_1 portData1;
// this initialization does not seem to help
memset(&portData1, 0, sizeof(portData1));
portData1.cbSize = sizeof(portData1);
DWORD dwStatus = 0;
DWORD dwNeeded = 0;
// this always fails with dwStatus 87 (invalid parameter)
if (XcvData(hPrinter, L"GetConfigInfo", (PBYTE)&configInfoData1,
sizeof(configInfoData1), (PBYTE)&portData1, sizeof(portData1), &dwNeeded, &dwStatus))
{
if (dwStatus != 0)
{
[...]
// throw exception
}
_ASSERTE(dwNeeded > 0);
[...]
}
// this works fine
if (XcvData(hPrinter, L"ConfigPort", (PBYTE)&m_portData1, sizeof(m_portData1),
NULL, 0, &dwNeeded, &dwStatus))
{
[...]
}
[...]
}