Adding printer "Local Port"

Discussion in 'Windows Vista Drivers' started by Farid, Oct 25, 2009.

  1. Farid

    Farid Guest

    I've written a print driver that captures the EMF file and pass it to another
    app to process it.
    I have a installation for the printer and I don't want to use port "LPT1:",
    instead I want to create my own "Local Port" and the set the printer port to
    that. I can create "Local Port" with XcvData (see sample code below), but the
    issue is when I use the "Local Port" created thru my code, I get error 63 in
    my print processor calling StartDocPrinter(..).
    On the other hand when I create the port manually in Printer
    Properties->Ports->Add Port and assign this port to my printer everything
    works without any problem.

    Any idea what could be the difference with the "Local Port" that I create
    thru code and the manual one? There must be something else that I needd to
    do, when I create the port in the code.

    Thanks,
    Farid

    ======= Code to create port =========
    HANDLE hXVCPrinter = NULL ;
    LPWSTR wsPortName = L"eefPort:";
    DWORD dwNeeded, dwStatus;
    PRINTER_DEFAULTS PrinterDefaults;

    PrinterDefaults.pDatatype = NULL;
    PrinterDefaults.pDevMode = NULL;
    PrinterDefaults.DesiredAccess = SERVER_ACCESS_ADMINISTER;

    if (OpenPrinter(L",XcvMonitor Local Port", &hXVCPrinter,
    &PrinterDefaults))
    {
    dwError = ERROR_SUCCESS;
    if (!XcvData(hXVCPrinter, L"AddPort", (LPBYTE)wsPortName,
    (wcslen(wsPortName)+1)*2, NULL, 0, &dwNeeded, &dwStatus) ||
    !(dwStatus == ERROR_SUCCESS || dwStatus == ERROR_ALREADY_EXISTS))
    {
    dwError = GetLastError();

    wsprintf(sMessage, L"XcvData: Error = %d - Status = %d", dwError,
    dwStatus);
    MyMessageBox(sMessage, EEFPPROC_MSGBOX_TITLE, MB_OK);
    }
    else
    {
    wsprintf(sMessage, L"Port added successfully. - Status = %d - Port:
    %s", dwStatus, wsPortName);
    MyMessageBox(sMessage, EEFPPROC_MSGBOX_TITLE, MB_OK);
    }

    ClosePrinter(hXVCPrinter);
    }
    else
    {
    dwError = GetLastError();
    wsprintf(sMessage, L"OpenPrinter: Error = %d", dwError);
    MyMessageBox(sMessage, EEFPPROC_MSGBOX_TITLE, MB_OK);
    }
     
    Farid, Oct 25, 2009
    #1
    1. Advertisements

  2. Farid

    Farid Guest

    Never mind, everything works fine now.
    The problem was that I was adding ":" at the end of port name thru my code
    and that made the port name invalid. XcvData didn't return any error in the
    dwStatus.
    Anyway I removed the trailing ":" from the port name and it works fine.
     
    Farid, Oct 29, 2009
    #2
    1. Advertisements

  3. Farid

    Guest

    this might be a bit irrelevant but how did you managed to capture the EMF ?
     
    , Jul 5, 2012
    #3
    1. Advertisements

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments (here). After that, you can post your question and our members will help you out.