Esempio n. 1
0
        public static bool Printer(model.Printer printer, FileInfo file)
        {
            // Open the file.
            var fs = new FileStream(file.FullName, FileMode.Open);
            var br = new BinaryReader(fs);
            // Dim an array of bytes big enough to hold the file's contents.
            var bytes    = new Byte[fs.Length];
            var bSuccess = false;
            // Your unmanaged pointer.
            var pUnmanagedBytes = new IntPtr(0);
            int nLength;

            nLength = Convert.ToInt32(fs.Length);
            // Read the contents of the file into the array.
            bytes = br.ReadBytes(nLength);
            // Allocate some unmanaged memory for those bytes.
            pUnmanagedBytes = Marshal.AllocCoTaskMem(nLength);
            // Copy the managed byte array into the unmanaged array.
            Marshal.Copy(bytes, 0, pUnmanagedBytes, nLength);
            // Send the unmanaged bytes to the printer.
            bSuccess = core.PrinterHelper.SendBytesToPrinter(printer.Name, pUnmanagedBytes, nLength);
            // Free the unmanaged memory that you allocated earlier.
            Marshal.FreeCoTaskMem(pUnmanagedBytes);
            return(bSuccess);
        }
Esempio n. 2
0
        public model.Printer Printer(bool validate = true)
        {
            var printer = new model.Printer(Value.ToString());

            if (validate && !printer.ValidPrinter())
            {
                throw new KLIBException(1, $"Printer isn't {Value.ToString()} valid");
            }

            return(printer);
        }
Esempio n. 3
0
        public static bool Printer(model.Printer printer, string value)
        {
            IntPtr pBytes;
            Int32  dwCount;
            var    bSucess = false;

            // How many characters are in the string?
            dwCount = value.Length;
            // Assume that the printer is expecting ANSI text, and then convert
            // the string to ANSI text.
            pBytes = Marshal.StringToCoTaskMemAnsi(value);
            // Send the converted ANSI string to the printer.
            bSucess = core.PrinterHelper.SendBytesToPrinter(printer.Name, pBytes, dwCount);
            Marshal.FreeCoTaskMem(pBytes);
            return(bSucess);
        }