Regarding Printer related notifications
CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 2 of 2

Thread: Regarding Printer related notifications

  1. #1
    Join Date
    Jun 2005
    Posts
    30

    Question Regarding Printer related notifications

    Hi!

    I have a problem in retrieving printer information using FindNextPrinterChangeNotification() function.My code executes properly without any error and exception but all the values in LPPRINTER_NOTIFY_INFO structure are NULL or zero.code as follow


    LPPRINTER_NOTIFY_INFO notification;
    LPPRINTER_NOTIFY_OPTIONS notifyoption;
    notifyoption = (LPPRINTER_NOTIFY_OPTIONS)HeapAlloc (GetProcessHeap (), HEAP_ZERO_MEMORY, sizeof(PRINTER_NOTIFY_OPTIONS) );

    notification = (LPPRINTER_NOTIFY_INFO)HeapAlloc ( GetProcessHeap (), HEAP_ZERO_MEMORY, sizeof(PRINTER_NOTIFY_INFO) );

    OpenPrinter("HP LaserJet 3200 Series PS",&hprinter,NULL);
    if(hprinter == INVALID_HANDLE_VALUE)
    MessageBox("printer not available","",MB_OK);

    hnotify = FindFirstPrinterChangeNotification(hprinter,PRINTER_CHANGE_ALL,0,notifyoption);
    notifyoption->Flags = PRINTER_NOTIFY_OPTIONS_REFRESH;
    if(hnotify == INVALID_HANDLE_VALUE)
    MessageBox("Invalid handle hnotify","",MB_OK);

    DWORD retcode = WaitForSingleObject(hnotify,INFINITE);
    if(retcode == WAIT_OBJECT_0)
    {
    BOOL ret = FindNextPrinterChangeNotification(hnotify,&changeNotify,notifyoption,(LPVOID*)notification);
    if(ret !=0)
    {
    if(notification->aData[0].Type == PRINTER_NOTIFY_TYPE)
    MessageBox("printer notification","",MB_OK);

    sprintf(msg,"Field=%d",notification->aData[0].Field);
    MessageBox(msg,"",MB_OK);
    if(notification->aData[0].Field == PRINTER_NOTIFY_FIELD_SERVER_NAME)
    {
    MessageBox("Printer Name is","",MB_OK);
    memcpy(printername,(char *)notification->aData[0].NotifyData.Data.pBuf,notification->aData[0].NotifyData.Data.cbBuf);
    MessageBox(printername,"",MB_OK);
    }
    else
    MessageBox("other than printer name","",MB_OK);

    FreePrinterNotifyInfo(notification);

    }

    else
    MessageBox("error in executing","",MB_OK);


    ivalue of Field and cBuf is NULL
    please if anyone can identify the problem..it will be very helpful for me



    Thnaks in advance

  2. #2
    Join Date
    Aug 2013
    Location
    Basingstoke,UK
    Posts
    1

    Re: Regarding Printer related notifications

    Quote Originally Posted by johny555 View Post
    Hi!

    I have a problem in retrieving printer information using FindNextPrinterChangeNotification() function.My code executes properly without any error and exception but all the values in LPPRINTER_NOTIFY_INFO structure are NULL or zero.code as follow


    LPPRINTER_NOTIFY_INFO notification;
    LPPRINTER_NOTIFY_OPTIONS notifyoption;
    notifyoption = (LPPRINTER_NOTIFY_OPTIONS)HeapAlloc (GetProcessHeap (), HEAP_ZERO_MEMORY, sizeof(PRINTER_NOTIFY_OPTIONS) );

    notification = (LPPRINTER_NOTIFY_INFO)HeapAlloc ( GetProcessHeap (), HEAP_ZERO_MEMORY, sizeof(PRINTER_NOTIFY_INFO) );

    OpenPrinter("HP LaserJet 3200 Series PS",&hprinter,NULL);
    if(hprinter == INVALID_HANDLE_VALUE)
    MessageBox("printer not available","",MB_OK);

    hnotify = FindFirstPrinterChangeNotification(hprinter,PRINTER_CHANGE_ALL,0,notifyoption);
    notifyoption->Flags = PRINTER_NOTIFY_OPTIONS_REFRESH;
    if(hnotify == INVALID_HANDLE_VALUE)
    MessageBox("Invalid handle hnotify","",MB_OK);

    DWORD retcode = WaitForSingleObject(hnotify,INFINITE);
    if(retcode == WAIT_OBJECT_0)
    {
    BOOL ret = FindNextPrinterChangeNotification(hnotify,&changeNotify,notifyoption,(LPVOID*)notification);
    if(ret !=0)
    {
    if(notification->aData[0].Type == PRINTER_NOTIFY_TYPE)
    MessageBox("printer notification","",MB_OK);

    sprintf(msg,"Field=%d",notification->aData[0].Field);
    MessageBox(msg,"",MB_OK);
    if(notification->aData[0].Field == PRINTER_NOTIFY_FIELD_SERVER_NAME)
    {
    MessageBox("Printer Name is","",MB_OK);
    memcpy(printername,(char *)notification->aData[0].NotifyData.Data.pBuf,notification->aData[0].NotifyData.Data.cbBuf);
    MessageBox(printername,"",MB_OK);
    }
    else
    MessageBox("other than printer name","",MB_OK);

    FreePrinterNotifyInfo(notification);

    }

    else
    MessageBox("error in executing","",MB_OK);


    ivalue of Field and cBuf is NULL
    please if anyone can identify the problem..it will be very helpful for me



    Thnaks in advance
    -----------------------------------------------------

    Hi,

    Did you find any solution for your problem....am facing this problem...my event is not triggering
    Appreciate your help on this...thanks!

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  


Windows Mobile Development Center


Click Here to Expand Forum to Full Width

This is a CodeGuru survey question.


Featured


HTML5 Development Center