Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

Adding printer "Local Port"

56 views
Skip to first unread message

Farid

unread,
Oct 24, 2009, 10:03:01 PM10/24/09
to
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

unread,
Oct 29, 2009, 3:26:01 PM10/29/09
to
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.

kad...@gmail.com

unread,
Jul 5, 2012, 1:49:08 PM7/5/12
to
this might be a bit irrelevant but how did you managed to capture the EMF ?
0 new messages