What are the definitions you are using? The PRINTER_INFO_2 structure
has a lot of information (if you include the DEVMODE structure as well), and
there could be errors in how you are accessing it.
Can you show the definitions that you have?
--
- Nicholas Paldino [.NET/C# MVP]
- nick(dot)paldin o=at=exisconsul ting<dot>com
"Gordon Truslove" <Gordon.Truslov e@QCL-Solutions.com> wrote in message
news:OSTLwNxjDH A.2424@TK2MSFTN GP10.phx.gbl...[color=blue]
> Has anybody managed to get GetPrinter and PRINER_INFO_2 to work?
> I would like to retrieve the printer status.
>
>[/color]
I've tried about 3-4 variations. Here is the biggest. I've tried avoiding
the devmode and security descriptor but it still fails.
[ DllImport("wins pool.drv" )]
public static extern bool GetPrinter(IntP tr hPrinter,long Level,ref
PRINTERINFO2 pPrinter,long cbBuf,ref long pcbNeeded);
"Nicholas Paldino [.NET/C# MVP]" <nicholas.paldi no@exisconsulti ng.com> wrote
in message news:%23pI8M2zj DHA.2424@TK2MSF TNGP10.phx.gbl. ..[color=blue]
> Gordon,
>
> What are the definitions you are using? The PRINTER_INFO_2 structure
> has a lot of information (if you include the DEVMODE structure as well),[/color]
and[color=blue]
> there could be errors in how you are accessing it.
>
> Can you show the definitions that you have?
>
>
> --
> - Nicholas Paldino [.NET/C# MVP]
> - nick(dot)paldin o=at=exisconsul ting<dot>com
>
> "Gordon Truslove" <Gordon.Truslov e@QCL-Solutions.com> wrote in message
> news:OSTLwNxjDH A.2424@TK2MSFTN GP10.phx.gbl...[color=green]
> > Has anybody managed to get GetPrinter and PRINER_INFO_2 to work?
> > I would like to retrieve the printer status.
> >
> >[/color]
>
>[/color]
The first thing is that all of the places you are using long you should
be using int. In C, a long is a 32-bit integer. In C#, a long is a 64-bit
integer, which is throwing everything off. So you should be changing the
longs to ints.
Additionally, you should set the unmanaged type to LPTStr and set the
CharSet value in the StructLayout attribute to CharSet.Auto (as well as in
the DllImport declaration as well).
Finally, the SECURITY_DESCRI PTOR and DEVMODE structures are not embedded
in the PRINTER_INFO_2 structure. Rather, they are pointers. You can
replace these fields with IntPtr and set them to zero if you are not using
them.
However, when the call is complete, you need to be aware if they were
populated and free the memory that the pointers point to if there is
something there.
Hope this helps.
--
- Nicholas Paldino [.NET/C# MVP]
- nick(dot)paldin o=at=exisconsul ting<dot>com
"Gordon Truslove" <Gordon.Truslov e@QCL-Solutions.com> wrote in message
news:uzTFV6zjDH A.2964@tk2msftn gp13.phx.gbl...[color=blue]
> I've tried about 3-4 variations. Here is the biggest. I've tried avoiding
> the devmode and security descriptor but it still fails.
> [ DllImport("wins pool.drv" )]
>
> public static extern bool GetPrinter(IntP tr hPrinter,long Level,ref
> PRINTERINFO2 pPrinter,long cbBuf,ref long pcbNeeded);
>
>
> [StructLayout( LayoutKind.Sequ ential)]
>
> public struct PRINTERINFO2
>
> {
>
> [MarshalAs(Unman agedType.LPWStr )]public string pServerName;
>
> [MarshalAs(Unman agedType.LPWStr )]public string pPrinterName;
>
> [MarshalAs(Unman agedType.LPWStr )]public string pShareName;
>
> [MarshalAs(Unman agedType.LPWStr )]public string pPortName;
>
> [MarshalAs(Unman agedType.LPWStr )]public string pDriverName;
>
> [MarshalAs(Unman agedType.LPWStr )]public string pComment;
>
> [MarshalAs(Unman agedType.LPWStr )]public string pLocation;
>
> public DEVMODE pDevMode;
>
> [MarshalAs(Unman agedType.LPWStr )]public string pSepFile;
>
> [MarshalAs(Unman agedType.LPWStr )]public string pPrintProcessor ;
>
> [MarshalAs(Unman agedType.LPWStr )]public string pDatatype;
>
> [MarshalAs(Unman agedType.LPWStr )]public string pParameters;
>
> public SECURITY_DESCRI PTOR pSecurityDescri ptor;
>
> public long Attributes;
>
> public long Priority;
>
> public long DefaultPriority ;
>
> public long StartTime;
>
> public long UntilTime;
>
> public long Status;
>
> public long cJobs;
>
> public long AveragePPM;
>
> }
>
> [StructLayout( LayoutKind.Sequ ential)]
>
> public struct SECURITY_DESCRI PTOR{
>
> public byte Revision;
>
> public byte Sbz1;
>
> public long Control;
>
> public long Owner;
>
> public long Group;
>
> public ACL sACL;
>
> public ACL Dacl;
>
> }
>
> [StructLayout( LayoutKind.Sequ ential)]
>
> public struct ACL{
>
> public byte AclRevision;
>
> public byte Sbz1;
>
> public int AclSize;
>
> public int AceCount;
>
> public int Sbz2;
>
> }
>
>
>
> [StructLayout( LayoutKind.Sequ ential)]
>
> public struct DEVMODE{
>
> public string dmDeviceName;
>
> public int dmSpecVersion;
>
> public int dmDriverVersion ;
>
> public int dmSize;
>
> public int dmDriverExtra;
>
> public long dmFields;
>
> public int dmOrientation;
>
> public int dmPaperSize;
>
> public int dmPaperLength;
>
> public int dmPaperWidth;
>
> public int dmScale;
>
> public int dmCopies;
>
> public int dmDefaultSource ;
>
> public int dmPrintQuality;
>
> public int dmColor;
>
> public int dmDuplex;
>
> public int dmYResolution;
>
> public int dmTTOption;
>
> public int dmCollate;
>
> public string dmFormName;
>
> public int dmLogPixels;
>
> public long dmBitsPerPel;
>
> public long dmPelsWidth;
>
> public long dmPelsHeight;
>
> public long dmDisplayFlags;
>
> public long dmDisplayFreque ncy;
>
> public long dmICMMethod;
>
> public long dmICMIntent;
>
> public long dmMediaType;
>
> public long dmDitherType;
>
> public long dmReserved1;
>
> public long dmReserved2;
>
> }
>
> "Nicholas Paldino [.NET/C# MVP]" <nicholas.paldi no@exisconsulti ng.com>[/color]
wrote[color=blue]
> in message news:%23pI8M2zj DHA.2424@TK2MSF TNGP10.phx.gbl. ..[color=green]
> > Gordon,
> >
> > What are the definitions you are using? The PRINTER_INFO_2[/color][/color]
structure[color=blue][color=green]
> > has a lot of information (if you include the DEVMODE structure as well),[/color]
> and[color=green]
> > there could be errors in how you are accessing it.
> >
> > Can you show the definitions that you have?
> >
> >
> > --
> > - Nicholas Paldino [.NET/C# MVP]
> > - nick(dot)paldin o=at=exisconsul ting<dot>com
> >
> > "Gordon Truslove" <Gordon.Truslov e@QCL-Solutions.com> wrote in message
> > news:OSTLwNxjDH A.2424@TK2MSFTN GP10.phx.gbl...[color=darkred]
> > > Has anybody managed to get GetPrinter and PRINER_INFO_2 to work?
> > > I would like to retrieve the printer status.
> > >
> > >[/color]
> >
> >[/color]
>
>[/color]
Comment