Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
HomeAnnouncementsFree MagazinesWhite PapersSubmit Content
Discussion GroupsASP.NETWindows FormsLanguages.NET FrameworkVisual Studio.NET
Articles.NET FrameworkASP.NETToolsWindows Forms
.NET DirectoryOpen Source ProjectsUser GroupsWeb Resources
Related Topics
Visual Basic 6SQL ServerMS AccessOther DB ProductsMS Server ProductsMore Topics ...

.NET Forum / .NET Framework / Interop / June 2007

Tip: Looking for answers? Try searching our database.

Problems with FindNextPrinterChangeNotification in C#

Thread view: 
Enable EMail Alerts  Start New Thread
Thread rating: 
Michal Michalec - 26 Feb 2004 20:30 GMT
I'm writing a .NET application for monitoring print queues. I can get a
handle to a printer by OpenPrinter. I can easily run
FindFirstPrinterChangeNotification (but only with IntPtr.Zero as
pPrinterNotifyOptions argument) and wait for the printer event. Finally I
can use FindNextPrinterChangeNotification function and get pdwChange
attribute that indicates what kind of event has occured. The tricky thing
is to get to the nested structures, that describes the print job that
ocurred. The question is: how can I pass ppPrinterNotifyInfo  argument to
find these nested structures with print job details?

Michal
Mattias Sj?gren - 27 Feb 2004 21:56 GMT
Michal,

>The tricky thing
>is to get to the nested structures, that describes the print job that
>ocurred. The question is: how can I pass ppPrinterNotifyInfo  argument to
>find these nested structures with print job details?

Declare the structs something like this

struct PRINTER_NOTIFY_INFO
{
 public uint Version;
 public uint Flags;
 public uint Count;
 // Array of PRINTER_NOTIFY_INFO_DATA follows
}

struct PRINTER_NOTIFY_INFO_DATA
{
 public ushort Type;
 public ushort Field;
 public uint Reserved;
 public uint Id;
 public uint cbBuf;  // or adwData[0]
 public IntPtr pBuf; // or uint adwData[1]
}

Declare FindNextPrinterChangeNotification like this

static extern bool FindNextPrinterChangeNotification(..., out IntPtr
ppPrinterNotifyInfo);

and finally call it like this

IntPtr pNotifyInfo;
if ( FindNextPrinterChangeNotification( ..., out pNotifyInfo ) ) {
 PRINTER_NOTIFY_INFO info =
(PRINTER_NOTIFY_INFO)Marshal.PtrToStructure(
   pNotifyInfo, typeof(PRINTER_NOTIFY_INFO) );
 int pData = (int)pNotifyInfo +
   Marshal.SizeOf( typeof(PRINTER_NOTIFY_INFO) );
 PRINTER_NOTIFY_INFO_DATA[] data =
   new PRINTER_NOTIFY_INFO_DATA[info.Count];
 for ( uint i = 0; i < info.Count; i++ ) {
   data[i] = (PRINTER_NOTIFY_INFO_DATA)Marshal.PtrToStructure(
     (IntPtr)pData, typeof(PRINTER_NOTIFY_INFO_DATA) );
   pData += Marshal.SizeOf( typeof(PRINTER_NOTIFY_INFO_DATA) );
 }
 FreePrinterNotifyInfo( pNotifyInfo );
}

Mattias

Signature

Mattias Sjögren [MVP]  mattias @ mvps.org
http://www.msjogren.net/dotnet/ | http://www.dotnetinterop.com
Please reply only to the newsgroup.

Michal Michalec - 01 Mar 2004 08:56 GMT
Thank You very much Mattias.
I'v been counting on your answer ;) It looks like you know everything about
printer notifications and interoperability
Thank you once more. Your answer solves my problem.
Michal
> Michal,
>
[quoted text clipped - 48 lines]
>
> Mattias
ehabhassan - 03 Jun 2007 11:03 GMT
i have the same problem, and i tried to solve it that way, but the count of the info is always zero
int pdwChange = 0;
       IntPtr ptr = IntPtr.Zero;
       PRINTER_NOTIFY_OPTIONS  notifyOptions = new PRINTER_NOTIFY_OPTIONS();
       notifyOptions.Count = 1;
       notifyOptions.dwFlags = PRINTER_NOTIFY_OPTIONS_REFRESH;
       notifyOptions.dwVersion = 2;
       bool nxt = FindNextPrinterChangeNotification(whand, out pdwChange, notifyOptions, out ptr);
       PRINTER_NOTIFY_INFO info = (PRINTER_NOTIFY_INFO)Marshal.PtrToStructure(ptr, typeof(PRINTER_NOTIFY_INFO));
     

From http://developmentnow.com/g/21_2004_2_0_0_105339/Problems-with-FindNextPrinterCh
angeNotification-in-C.ht


Rate this thread:







Free Magazines

Get these publications absolutely FREE for up to 12 months. There are no hidden fees and no obligation. Simply choose a title, complete the application form and submit it. Read more ...

Oracle MagazineNetwork ComputingComputer WorldBio-IT WorldeWeekInformation WeekInfosecurity
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2008 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.