c# - Access Printer Status using Winspool -


hello i've used example on how access printer status using winspool.

//code written mark middlemist - @delradie  //made available @ http://delradiesdev.blogspot.com //interop details http://pinvoke.net/ using system; using system.runtime.interopservices;  namespace delradiesdev.printerstatus {   public class winspoolprinterinfo   {     [dllimport("winspool.drv", charset = charset.auto, setlasterror = true)]     public static extern int openprinter(string pprintername, out intptr phprinter, ref printer_defaults pdefault);      [dllimport("winspool.drv", setlasterror = true, charset = charset.auto)]     public static extern bool getprinter(intptr hprinter, int32 dwlevel, intptr pprinter, int32 dwbuf, out int32 dwneeded);      [dllimport("winspool.drv", setlasterror = true)]     public static extern int closeprinter(intptr hprinter);      [structlayout(layoutkind.sequential)]     public struct printer_defaults     {       public intptr pdatatype;       public intptr pdevmode;       public int desiredaccess;     }      [structlayout(layoutkind.sequential, charset = charset.auto)]     public struct printer_info_2     {       [marshalas(unmanagedtype.lptstr)]       public string pservername;              [marshalas(unmanagedtype.lptstr)]       public string pprintername;        [marshalas(unmanagedtype.lptstr)]       public string psharename;        [marshalas(unmanagedtype.lptstr)]       public string pportname;        [marshalas(unmanagedtype.lptstr)]       public string pdrivername;        [marshalas(unmanagedtype.lptstr)]       public string pcomment;        [marshalas(unmanagedtype.lptstr)]       public string plocation;        public intptr pdevmode;        [marshalas(unmanagedtype.lptstr)]             public string psepfile;        [marshalas(unmanagedtype.lptstr)]             public string pprintprocessor;        [marshalas(unmanagedtype.lptstr)]       public string pdatatype;        [marshalas(unmanagedtype.lptstr)]       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;     }      public printer_info_2? getprinterinfo(string printername)     {       intptr phandle;             printer_defaults defaults = new printer_defaults();             printer_info_2? info2 = null;        openprinter(printername, out phandle, ref defaults);        int32 cbneeded = 0;        bool bret = getprinter(phandle, 2, intptr.zero, 0, out cbneeded);        if (cbneeded > 0)       {         intptr paddr = marshal.allochglobal((int)cbneeded);          bret = getprinter(phandle, 2, paddr, cbneeded, out cbneeded);          if (bret)                 {           info2 = (printer_info_2)marshal.ptrtostructure(paddr, typeof(printer_info_2));         }          marshal.freehglobal(paddr);       }        closeprinter(phandle);        return info2;     }   } }  

however, when call function, not know kind of data pass except printername. can me?

openprinter(string pprintername, out intptr phprinter, ref printer_defaults pdefault)  getprinter(intptr hprinter, int32 dwlevel, intptr pprinter, int32 dwbuf, out int32 dwneeded)  closeprinter(intptr hprinter) 

what data pass on functions?

i'm not sure understand question. have call getprinterinfo-method , in turn use functions winspool.drv generating managed printer_info_2 struct you.


Comments

Popular posts from this blog

Perl - how to grep a block of text from a file -

delphi - How to remove all the grips on a coolbar if I have several coolbands? -

javascript - Animating array of divs; only the final element is modified -