I am using RawPrinterHelper for printing. And it works great with Windows 7 and previous versions. When we tried it with a printer installed on a computer with Windows 8, it did not work.
After reading this post, I found out that I need to set the dataType variable to "XPS_PASS" instead of "RAW". By the way, installing it on "XPS_PASS" works fine on Windows 8.
But in my environment there are windows 8s and windows 7s and XP.
Is it possible to make this switch programmatically?
How to set the pDataType variable to "RAW" for Windows 7 and lower operating systems and "XPS_PASS" for Windows 8?
Edit: After a couple of hours of google digging, I found this article . It says here:
I am not familiar with unmanaged code, but I tried followig:
[DllImport("winspool.drv", CharSet = CharSet.Auto, SetLastError = true)] public static extern int GetPrinterDriver(IntPtr hPrinter, string pEnvironment, uint Level, IntPtr pDriverInfo, int cbBuf, out int pcbNeeded); private static void GetPrinterDataType(IntPtr hPrinter ) { IntPtr driverInfo = new IntPtr(); driverInfo = IntPtr.Zero; int buf_len = 0; int IntPtrSize = Marshal.SizeOf(typeof(IntPtr)); int a = GetPrinterDriver(hPrinter, "", 8, driverInfo, 0, out buf_len); driverInfo = Marshal.AllocHGlobal(buf_len); a = GetPrinterDriver(hPrinter, "", 8, driverInfo, buf_len, out buf_len); for (int i = 0; i <= 24; i++) { if (i == 12 || i == 15 || i == 11 || i == 14) continue; IntPtr ptr = Marshal.ReadIntPtr(driverInfo, IntPtrSize * i); Console.WriteLine("DRIVER INFO {0}: {1}", i, Marshal.PtrToStringUni(ptr)); } }
I call this method after the OpenPrinter () method of the RawPrinterHelper class. But dwPrinterDriverAttributes (number 21) is empty.
Am I doing something wrong?
