How to Add printer port without showing dialog?

How to Add printer port without showing dialog?

Post by ryan » Wed, 27 Aug 2003 17:13:29


Hi,
I want to write a small tool which will add a standard tcp/ip printer
port without any user configuration dialogs. I searched the MSDN and use
XcvData to complete this job. But it didn't work. Could you teach me how to
do it? My developing evironment is Windows2000,VS6.0,MFC project. Here is
part of my code. Is there anything wrong or some miss steps? Hope you could
help me. Thanks.

Best Regards.
Ryan

void Dialog::OnOk()
{
HANDLE hPrinter=INVALID_HANDLE_VALUE;
PRINTER_DEFAULTS pdt;
pdt.DesiredAccess = PRINTER_ALL_ACCESS;
pdt.pDatatype = NULL;
pdt.pDevMode = NULL;
OpenPrinter("HP LaserJet 5100 PCL 6",&hPrinter,&pdt);
PORT_DATA_1 pd;
//Setting PORT_DATA_1
wcscpy(pd.sztPortName,L"TestPort");
wcscpy(pd.sztHostAddress,L"192.192.41.214");
wcscpy(pd.sztSNMPCommunity,L"public");
wcscpy(pd.sztIPAddress,L"192.192.41.214");
wcscpy(pd.sztQueue,L"\0");
//wcscpy(pd.Reserved,);
pd.dwVersion = 1;
pd.dwProtocol = PROTOCOL_RAWTCP_TYPE;
pd.dwReserved = 0;
pd.dwDoubleSpool = TRUE;
pd.dwPortNumber = 9100;
pd.dwSNMPEnabled = TRUE;
pd.dwSNMPDevIndex = 1;
pd.cbSize = sizeof(pd);
if
(!XcvData(hPrinter,L"GetConfigInfo",(BYTE*)&cid,sizeof(&cid),NULL,0,NULL,&pw
Status))
{
char m[1024];
sprintf(m,"GetLastError:%d",GetLastError());
MessageBox(m,"ABC",MB_OK);
}
ClosePrinter(hPrinter);
}
 
 
 

How to Add printer port without showing dialog?

Post by Raymond Pa » Fri, 05 Sep 2003 03:26:18

I'm not a printing expert, but I think you'll need to use the AddPrinter
API.

--
This posting is provided "AS IS" with no warranties, and confers no rights.
Please do not respond to the e-mail address provided. It is for newsgroup
use only.


to
could
(!XcvData(hPrinter,L"GetConfigInfo",(BYTE*)&cid,sizeof(&cid),NULL,0,NULL,&pw