Пример #1
0
        public PMStatusCode CreatePrinterList(out string [] printerList, out int index, out PMPrinter printer)
        {
            IntPtr array, printerHandle;
            var    code = PMSessionCreatePrinterList(handle, out array, out index, out printerHandle);

            if (code != PMStatusCode.Ok)
            {
                printerList = null;
                printer     = null;
                return(code);
            }

            printerList = NSArray.StringArrayFromHandle(array);
            CFObject.CFRelease(array);
            if (printerHandle != IntPtr.Zero)
            {
                // Now get the printer, we do not own it, so retain.
                printer = new PMPrinter(printerHandle, owns: false);
            }
            else
            {
                printer = null;
            }

            return(PMStatusCode.Ok);
        }
Пример #2
0
        public static PMStatusCode TryCreate(out PMPrinter?printer)
        {
            IntPtr value;
            var    code = PMCreateGenericPrinter(out value);

            if (code == PMStatusCode.Ok)
            {
                printer = new PMPrinter(value, owns: true);
                return(PMStatusCode.Ok);
            }
            printer = null;
            return(code);
        }
Пример #3
0
        public string?GetLocalizedName(PMPrinter printer)
        {
            if (printer is null)
            {
                throw new ArgumentNullException(nameof(printer));
            }
            var code = PMPaperCreateLocalizedName(Handle, printer.Handle, out var name);

            if (code != PMStatusCode.Ok)
            {
                return(null);
            }
            return(CFString.FromHandle(name, true));
        }
Пример #4
0
        public string GetLocalizedName(PMPrinter printer)
        {
            if (printer == null)
            {
                throw new ArgumentNullException(nameof(printer));
            }
            IntPtr name;
            var    code = PMPaperCreateLocalizedName(handle, printer.handle, out name);

            if (code != PMStatusCode.Ok)
            {
                return(null);
            }
            var str = CFString.FetchString(name);

            CFObject.CFRelease(name);
            return(str);
        }
Пример #5
0
        public static PMStatusCode CreatePrinterList(out PMPrinter [] printerList)
        {
            IntPtr arr;
            var    code = PMServerCreatePrinterList(IntPtr.Zero /* ServerLocal */, out arr);

            if (code != PMStatusCode.Ok)
            {
                printerList = null;
                return(code);
            }
            int c = (int)CFArray.GetCount(arr);

            printerList = new PMPrinter [c];
            for (int i = 0; i < c; i++)
            {
                printerList [i] = new PMPrinter(CFArray.CFArrayGetValueAtIndex(arr, i), owns: false);
            }

            CFObject.CFRelease(arr);
            return(PMStatusCode.Ok);
        }
Пример #6
0
        public PMStatusCode CreatePrinterList(out string? []?printerList, out int index, out PMPrinter?printer)
        {
            var code = PMSessionCreatePrinterList(Handle, out var array, out index, out var printerHandle);

            if (code != PMStatusCode.Ok)
            {
                printerList = null;
                printer     = null;
                return(code);
            }

            printerList = CFArray.StringArrayFromHandle(array, true);
            if (printerHandle != IntPtr.Zero)
            {
                // Now get the printer, we do not own it, so retain.
                printer = new PMPrinter(printerHandle, owns: false);
            }
            else
            {
                printer = null;
            }

            return(PMStatusCode.Ok);
        }