οκ, μετά απο λίγο ψάξιμο στο PInvoke.net, κατέληξα στις παρακάτω 2 definitions:
[DllImport("winspool.Drv", EntryPoint = "GetPrinterA", SetLastError = true, CharSet = CharSet.Ansi,
ExactSpelling = true, CallingConvention = CallingConvention.StdCall)]
private static extern bool GetPrinter(IntPtr hPrinter, Int32 dwLevel,
IntPtr pPrinter, Int32 dwBuf, out Int32 dwNeeded);
[DllImport("winspool.Drv", EntryPoint = "OpenPrinterA", SetLastError = true, CharSet = CharSet.Ansi,
ExactSpelling = true, CallingConvention = CallingConvention.StdCall)]
static extern bool OpenPrinter([MarshalAs(UnmanagedType.LPStr)] string szPrinter,
out IntPtr hPrinter, IntPtr printerDefaults);
... οι οποίες παίζουν μια χαρά στον παρακάτω κώδικα, αλλά μόνο αν περάσω "level" param στην GetPrinter την τιμή 2 ... αλλά εγώ ο δυστυχής χρειάζομαι την τιμή 6
κατα τα λεγόμενα του MSDN. Στον κώδικα παρακάτω, το πρώτο call στην GetPrinter παίζει μια χαρούλα, μου επιστρέφει τα required bytes. Αν το 2 το αλλάξω σε 6 ... τότε εκτελείται πάλι, τα required bytes είναι πάντα 0 και το Marshal.GetLastError() μου επιστρέφει success τιμή (124) ...
public static void GetPrinterStatus(string printerName)
{
IntPtr printerHandle;
// ok, let's try to open the printer first ...
if (OpenPrinter(printerName, out printerHandle, IntPtr.Zero))
{
// ok, now ... I'm doin' this 2 times. The first i do just to fail & get back the required bytes for my
// buffer length
int bytesRequired;
int intJunk;
GetPrinter(printerHandle, 2, IntPtr.Zero, 0, out bytesRequired); if (bytesRequired <= 0) {
int lastError = Marshal.GetLastWin32Error();
Marshal.ThrowExceptionForHR(lastError);
throw new ApplicationException(string.Format("Invalid error code: {0}", lastError));
}
// ok, bytes required is NOT 0 ... proceed then
IntPtr ptrPrinterInfo = Marshal.AllocCoTaskMem(bytesRequired);
if (
GetPrinter(printerHandle, 6, ptrPrinterInfo, bytesRequired, out intJunk)) {
// Get a var ready ...
PRINTER_INFO_6 pInfo = (PRINTER_INFO_6)Marshal.PtrToStructure(ptrPrinterInfo, typeof(PRINTER_INFO_6));
// and deserialize off the memory buffer, innit ???
Console.WriteLine("Fetched DWORD: {0}", pInfo.dwStatus);
}
// Close the printer ...
ClosePrinter(printerHandle);
}
}
... ε, ρε που μπλέξαμε πάλι στην κωδικο-χώρα, επειδή κάποιος δε θέλει να πατήσει ένα button όταν πάρει στα χέρια του την εκτύπωση απο τον εκτυπωτή που έχει δίπλα του

Νεότερα ... όταν έχω
Angel
O:]