我尝试使用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))
{
[...]
}
[...]
}
答案 0 :(得分:0)
`//////////////////////////////////////////////// ///////////////////
DWORD code = 0;
PRINTER_DEFAULTS Defaults1 = { NULL, NULL, SERVER_ACCESS_ADMINISTER };
HANDLE hXcv = NULL;
CString strPortName;
strPortName = _T(",XcvPort 168.118.18.156");//L",XcvMonitor Standard TCP/IP Port"
if (OpenPrinter((LPTSTR)(LPCTSTR)strPortName, &hXcv, &Defaults1))
{
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;
// getconfiginfo
if (XcvData(hXcv, L"GetConfigInfo", (PBYTE)&configInfoData1,
sizeof(configInfoData1), (PBYTE)&portData1, sizeof(portData1), &dwNeeded, &dwStatus))
{
}
_tcscpy(portData1.sztHostAddress,_T("168.118.18.148"));
// setconfiginfo
if (XcvData(hXcv, L"ConfigPort", (PBYTE)&portData1, sizeof(portData1),
NULL, 0, &dwNeeded, &dwStatus))
{
}
ClosePrinter(hXcv);
}
///////////////////////////
`OpenPrinter(L“,XcvPort 168.118.18.156”,hPrinter,&defaults);
使用特定的端口名,然后GetConfigInfo确定。端口名称:168.118.18.156