How to create a new port and assign it to a printer

后端 未结 2 1937
名媛妹妹
名媛妹妹 2021-01-14 16:56

We have a virtual printer (provided by a 3rd party) that is getting assigned to an invalid local printer port. The printer is always local (we aren\'t dealing with a remote

2条回答
  •  甜味超标
    2021-01-14 17:27

    I guess your code merely worked by chance. According to https://docs.microsoft.com/en-us/windows-hardware/drivers/print/tcpmon-xcv-commands (and to my own experience) the real solution is:

    PORT_DATA_1 pdPortData;  
    wcscpy_s(pdPortData.sztPortName, MAX_PORTNAME_LEN, lpPortName);  
    [...]
    if (!XcvData(hXcv, L"AddPort", (BYTE*) &pdPortData, sizeof(PORT_DATA_1), NULL, 0, &dwNeeded, &dwStatus))
    [...]
    

    By chance sztPortName is the first element in PORT_DATA_1 structure. Maybe that's why your code did not fail, although it is wrong.

提交回复
热议问题