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
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
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