Windows Vista Tips

Windows Vista Tips > Newsgroups > Windows Vista Drivers > Adding printer "Local Port"

Reply
Thread Tools Display Modes

Adding printer "Local Port"

 
 
Farid
Guest
Posts: n/a

 
      10-25-2009
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);
}

 
Reply With Quote
 
 
 
 
Farid
Guest
Posts: n/a

 
      10-29-2009
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" wrote:

> 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);
> }
>

 
Reply With Quote
Reply

Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Need Help : Problem Adding Printer Bpras Windows Vista Installation 3 02-06-2008 11:18 PM
Adding my vista laptop to my shared printer tink123177 Windows Vista Installation 3 08-15-2007 04:22 PM
adding printer to Vista meron Windows Vista Hardware 1 06-22-2007 01:07 AM
Adding Network Printer Sam Windows Vista Administration 1 06-09-2007 03:20 AM
printer sharing from vista pc to win 98 pc --win 98 won't see shrd Bubbator Windows Vista Hardware 2 05-03-2007 02:51 PM



1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59