// Open the printer.
if (RawPrinterHelper.OpenPrinter(pd.PrinterSettings.PrinterName.Normalize(), out hPrinter, IntPtr.Zero))
{
// Start a document.
if (RawPrinterHelper.StartDocPrinter(hPrinter, 1, di))
{
// Start a page.
if (RawPrinterHelper.StartPagePrinter(hPrinter))
{
// Write your bytes.
pBytes = Marshal.StringToCoTaskMemAnsi(_str);
dwCount = _str.Length;
RawPrinterHelper.WritePrinter(hPrinter, pBytes, dwCount, out dwWritten);
RawPrinterHelper.EndPagePrinter(hPrinter);
}
RawPrinterHelper.EndDocPrinter(hPrinter);
}
RawPrinterHelper.ClosePrinter(hPrinter);
}
// If you did not succeed, GetLastError may give more information
// about why not.
if (bSuccess == false)
{
dwError = Marshal.GetLastWin32Error();
}