Discussion:
Adding printer "Local Port"
(too old to reply)
Farid
2009-10-25 02:03:01 UTC
Permalink
Raw Message
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
2009-10-29 19:26:01 UTC
Permalink
Raw Message
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.
Post by Farid
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
{
%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);
}
k***@gmail.com
2012-07-05 17:49:08 UTC
Permalink
Raw Message
this might be a bit irrelevant but how did you managed to capture the EMF ?
Loading...