2

私は OpenPrinter 関数を使用しており、関数が取得する最初のパラメーターは「pPrinterName」と呼ばれ、それが MSDN の説明です。

[in] プリンターまたはプリント サーバー、プリンター オブジェクト、XcvMonitor、または XcvPort の名前を指定する null で終わる文字列へのポインター。プリンター オブジェクトの使用: PrinterName,Job xxxx。XcvMonitor の場合は、ServerName、XcvMonitor MonitorName を使用します。XcvPort の場合は、 ServerName,XcvPort PortName を使用します

明らかに、私は太字の部分に興味があります。XcvPort とは正確には何ですか? 怠け者の質問のように思えますが、この概念に関する情報を実際に見つけることができませんでした. ポート ABC でプリンタを開きたい場合は、「\\MySrever,XcvPort ABC」と書く必要があります。

4

1 に答える 1

2

かなり近いですが、バックスラッシュを追加するだけです:

[DllImport("winspool.drv", EntryPoint = "OpenPrinter", SetLastError = true)]
    internal static extern bool OpenPrinter(string pPrinterName, ref IntPtr phPrinter, PRINTER_DEFAULTS pDefault);

[DllImport("winspool.drv", EntryPoint = "ClosePrinter", SetLastError = true)]
    internal static extern int ClosePrinter(IntPtr hPrinter);

public struct OpenPrinterAccessCodes
{
    public const int DELETE = 0x10000; // DELETE - Allowed to delete printers
    public const int READ_CONTROL = 0x20000; // READ_CONTROL - Allowed to read printer information
    public const int WRITE_DAC = 0x40000; // WRITE_DAC - Allowed to write device access control info
    public const int WRITE_OWNER = 0x80000; // WRITE_OWNER - Allowed to change the object owner
    public const int SERVER_ACCESS_ADMINISTER = 0x1;
    public const int SERVER_ACCESS_ENUMERATE = 0x2;
    public const int PRINTER_ACCESS_ADMINISTER = 0x4;
    public const int PRINTER_ACCESS_USE = 0x8;
    public const int STANDARD_RIGHTS_REQUIRED = 0xF0000;
    public const int PRINTER_ALL_ACCESS = (STANDARD_RIGHTS_REQUIRED | PRINTER_ACCESS_ADMINISTER | PRINTER_ACCESS_USE);
    public const int SERVER_ALL_ACCESS = (STANDARD_RIGHTS_REQUIRED | SERVER_ACCESS_ADMINISTER | SERVER_ACCESS_ENUMERATE);

    public const int MAX_PORTNAME_LEN = 64;
    public const int MAX_NETWORKNAME_LEN = 49;
    public const int MAX_SNMP_COMMUNITY_STR_LEN = 33;
    public const int MAX_QUEUENAME_LEN = 33;
    public const int MAX_IPADDR_STR_LEN = 16;

    public const int ERROR_INSUFFICIENT_BUFFER = 122;
    public const int ERROR_INVALID_FLAGS = 1004;
}
var def = new PRINTER_DEFAULTS { pDatatype = null, pDevMode = IntPtr.Zero, DesiredAccess = OpenPrinterAccessCodes.SERVER_ACCESS_ADMINISTER };
var hPrinter = IntPtr.Zero;
OpenPrinter(@"\\MyServer\,XcvPort ABC", ref hPrinter, def)
ClosePrinter(hPrinter);
于 2012-12-19T00:12:40.510 に答える