public static bool SendBytesToPrinter(string szPrinterName, IntPtr pBytes, int dwCount)
        {
            int    num       = 0;
            int    dwWritten = 0;
            IntPtr hPrinter  = new IntPtr(0);

            RawPrinterHelper.DOCINFOA di = new RawPrinterHelper.DOCINFOA();
            bool flag = false;

            di.pDocName  = "My C#.NET RAW Document";
            di.pDataType = "RAW";
            if (RawPrinterHelper.OpenPrinter(szPrinterName.Normalize(), out hPrinter, IntPtr.Zero))
            {
                if (RawPrinterHelper.StartDocPrinter(hPrinter, 1, di))
                {
                    if (RawPrinterHelper.StartPagePrinter(hPrinter))
                    {
                        flag = RawPrinterHelper.WritePrinter(hPrinter, pBytes, dwCount, out dwWritten);
                        RawPrinterHelper.EndPagePrinter(hPrinter);
                    }
                    RawPrinterHelper.EndDocPrinter(hPrinter);
                }
                RawPrinterHelper.ClosePrinter(hPrinter);
            }
            if (!flag)
            {
                num = Marshal.GetLastWin32Error();
            }
            return(flag);
        }
 public static extern bool StartDocPrinter(IntPtr hPrinter, int level, [MarshalAs(UnmanagedType.LPStruct), In] RawPrinterHelper.DOCINFOA di);