public NotifyInfo FindNextPrinterChangeNotification(bool refresh)
        {
            var ppPrinterNotifyInfo = IntPtr.Zero;
            var pOptions            = IntPtr.Zero;
            var pPrinterNotifyInfo  = IntPtr.Zero;

            try
            {
                ppPrinterNotifyInfo = Marshal.AllocHGlobal(Marshal.SizeOf <IntPtr>());

                PRINTER_NOTIFY_OPTIONS options = default;
                options.Flags = refresh ? PRINTER_NOTIFY_OPTIONS_REFRESH : 0x00;

                pOptions = Marshal.AllocHGlobal(Marshal.SizeOf <PRINTER_NOTIFY_OPTIONS>());
                Marshal.StructureToPtr(options, pOptions, false);

                if (!NativeMethods.FindNextPrinterChangeNotification(_changeHandle, out var change, pOptions, ppPrinterNotifyInfo))
                {
                    throw new Win32Exception();
                }

                pPrinterNotifyInfo = Marshal.ReadIntPtr(ppPrinterNotifyInfo);

                return(CreatePrinterNotifyInfo(change, pPrinterNotifyInfo));
            }
            finally
            {
                Marshal.FreeHGlobal(pOptions);
                Marshal.FreeHGlobal(ppPrinterNotifyInfo);

                if (pPrinterNotifyInfo != IntPtr.Zero)
                {
                    NativeMethods.FreePrinterNotifyInfo(pPrinterNotifyInfo);
                }
            }
        }
Example #2
0
 internal static extern bool FindNextPrinterChangeNotification
     ([In] IntPtr hChangeObject,
     [Out] out int pdwChange,
     [In, MarshalAs(UnmanagedType.LPStruct)] PRINTER_NOTIFY_OPTIONS pPrinterNotifyOptions,
     [Out] out IntPtr lppPrinterNotifyInfo
     );
Example #3
0
 internal static extern IntPtr FindFirstPrinterChangeNotification
     ([In] IntPtr hPrinter,
     [In] int fwFlags,
     [In] int fwOptions,
     [In, MarshalAs(UnmanagedType.LPStruct)] PRINTER_NOTIFY_OPTIONS pPrinterNotifyOptions);
Example #4
0
 public static extern bool FindNextPrinterChangeNotification
     ([InAttribute()] IntPtr hChangeObject,
     [OutAttribute()] out Int32 pdwChange,
     [InAttribute(), MarshalAs(UnmanagedType.LPStruct)] PRINTER_NOTIFY_OPTIONS pPrinterNotifyOptions,
     [OutAttribute()] out IntPtr lppPrinterNotifyInfo
     );
Example #5
0
 public static extern IntPtr FindFirstPrinterChangeNotification
     ([InAttribute()] IntPtr hPrinter,
     [InAttribute()] Int32 fwFlags,
     [InAttribute()] Int32 fwOptions,
     [InAttribute(), MarshalAs(UnmanagedType.LPStruct)] PRINTER_NOTIFY_OPTIONS pPrinterNotifyOptions);
 public static extern bool FindNextPrinterChangeNotification([In] IntPtr hChange,
                                                             [Out] out int pdwChange,
                                                             [In] PRINTER_NOTIFY_OPTIONS
                                                             pPrinterNotifyOptions,
                                                             ref IntPtr ppPrinterNotifyInfo);