K
ken
Hello Everyone,
I am trying (for the pass 4 days) to try and add a server printer to my
computer. Below is the code I used to add the printer, the problem is that
nothing seems to happen!! I followed the code and it has no problem,
however, when I go to start-- settings--printers there is no new printer. I
need to know what I am doing wrong. Do I have to (declare/or declare and
populate) a DevMode structure? Do I have to also create a printerconnection
using the printer pointer? I have found very little on the net or microsoft
about what is required. Some of what is below was sent to me through this
news group, but there are some inconsistancies. I found a scrap of code that
actual has an entry point for addprinter "AddPrinterA" , should I use that?
It amazes me that microsoft has spent so little time on knowledge base and
support issues about this subject.
Any help and direction on this problem would be greatly appreciated. I have
found myself going over the same ground and no change in the results.
Thank You in Advance for any Help,
Ken
[DllImport("winspool.drv",CharSet=CharSet.Auto)]
private static extern IntPtr AddPrinter(string myserver,
uint dwLevel, ref PRINTER_INFO_2 pi );
private void menuItem4_Click(object sender,
System.EventArgs e)
{
string mynull;
mynull = null;
IntPtr mystrptr = new IntPtr(0);
bool mysend;
IntPtr mysend2;
PRINTER_INFO_2 pi = new
PRINTER_INFO_2();
string myservername;
myservername = "blahblah"
pi.pServerName = "\\\\" + myservername ;
pi.pPrinterName = "\\\\" + myservername + "\\" + "CN-3-NCA" ;
pi.pShareName = "CN-3-NCA";
pi.pPortName = "123.123.123.27
rint";
pi.pDriverName = "Cannon iR2200-3300 PCL6";
pi.pComment = "No Comment";
pi.pLocation = "3rd Floor North
Alcove Copy Center";
pi.pDevMode = mystrptr;
pi.pSepFile = "";
pi.pPrintProcessor = "WinPrint";
pi.pDatatype = "RAW";
pi.pParameters = "";
pi.pSecurityDescriptor = mystrptr;
//pi.Attributes = mystrptr;
//pi.Priority = mystrptr;
//pi.DefaultPriority = mystrptr;
//pi.StartTime = mystrptr;
//pi.UntilTime = mystrptr;
//pi.Status = mystrptr;
//pi.cJobs = mystrptr;
//pi.AveragePPM = mystrptr;
mysend2 = AddPrinter(mynull,2, ref
pi);
}
[StructLayout(LayoutKind.Sequential,
CharSet=CharSet.Auto)]
private class PRINTER_INFO_2
{
public string pServerName;
public string
pPrinterName;
public string pShareName;
public string pPortName;
public string pDriverName;
public string pComment;
public string pLocation;
public IntPtr pDevMode;
public string pSepFile;
public string
pPrintProcessor;
public string pDatatype;
public string pParameters;
public IntPtr
pSecurityDescriptor;
public uint Attributes;
public uint Priority;
public uint
DefaultPriority;
public uint StartTime;
public uint UntilTime;
public uint Status;
public uint cJobs;
public uint AveragePPM;
}
I am trying (for the pass 4 days) to try and add a server printer to my
computer. Below is the code I used to add the printer, the problem is that
nothing seems to happen!! I followed the code and it has no problem,
however, when I go to start-- settings--printers there is no new printer. I
need to know what I am doing wrong. Do I have to (declare/or declare and
populate) a DevMode structure? Do I have to also create a printerconnection
using the printer pointer? I have found very little on the net or microsoft
about what is required. Some of what is below was sent to me through this
news group, but there are some inconsistancies. I found a scrap of code that
actual has an entry point for addprinter "AddPrinterA" , should I use that?
It amazes me that microsoft has spent so little time on knowledge base and
support issues about this subject.
Any help and direction on this problem would be greatly appreciated. I have
found myself going over the same ground and no change in the results.
Thank You in Advance for any Help,
Ken
[DllImport("winspool.drv",CharSet=CharSet.Auto)]
private static extern IntPtr AddPrinter(string myserver,
uint dwLevel, ref PRINTER_INFO_2 pi );
private void menuItem4_Click(object sender,
System.EventArgs e)
{
string mynull;
mynull = null;
IntPtr mystrptr = new IntPtr(0);
bool mysend;
IntPtr mysend2;
PRINTER_INFO_2 pi = new
PRINTER_INFO_2();
string myservername;
myservername = "blahblah"
pi.pServerName = "\\\\" + myservername ;
pi.pPrinterName = "\\\\" + myservername + "\\" + "CN-3-NCA" ;
pi.pShareName = "CN-3-NCA";
pi.pPortName = "123.123.123.27

pi.pDriverName = "Cannon iR2200-3300 PCL6";
pi.pComment = "No Comment";
pi.pLocation = "3rd Floor North
Alcove Copy Center";
pi.pDevMode = mystrptr;
pi.pSepFile = "";
pi.pPrintProcessor = "WinPrint";
pi.pDatatype = "RAW";
pi.pParameters = "";
pi.pSecurityDescriptor = mystrptr;
//pi.Attributes = mystrptr;
//pi.Priority = mystrptr;
//pi.DefaultPriority = mystrptr;
//pi.StartTime = mystrptr;
//pi.UntilTime = mystrptr;
//pi.Status = mystrptr;
//pi.cJobs = mystrptr;
//pi.AveragePPM = mystrptr;
mysend2 = AddPrinter(mynull,2, ref
pi);
}
[StructLayout(LayoutKind.Sequential,
CharSet=CharSet.Auto)]
private class PRINTER_INFO_2
{
public string pServerName;
public string
pPrinterName;
public string pShareName;
public string pPortName;
public string pDriverName;
public string pComment;
public string pLocation;
public IntPtr pDevMode;
public string pSepFile;
public string
pPrintProcessor;
public string pDatatype;
public string pParameters;
public IntPtr
pSecurityDescriptor;
public uint Attributes;
public uint Priority;
public uint
DefaultPriority;
public uint StartTime;
public uint UntilTime;
public uint Status;
public uint cJobs;
public uint AveragePPM;
}