Having an issue with the 'FindNextPrinterChangeNotification' method within the "WinSpool". The 4th parameter, out SafePRINTER_NOTIFY_INFO pointer to a buffer that receives the printer information for the change notification, isn't set as it should be and keeps being invalid.
Below is the result of FindNextPrinterChangeNotification(hChange, out chg, default, out ppi) on the ppi:
Name
SafeHPRINTER hprnt;
var printerName = "MyPrinterName";
if (!OpenPrinter(printerName, out hprnt))
{
Console.WriteLine($"Failed to open printer {printerName}. Error: {GetLastError()}");
return;
}
using var hChange = FindFirstPrinterChangeNotification(hprnt, PRINTER_CHANGE.PRINTER_CHANGE_ALL, PRINTER_NOTIFY_CATEGORY.PRINTER_NOTIFY_CATEGORY_2D);
while (true)
{
var kernalStatus = Kernel32.WaitForSingleObject(hChange, 200);
if (kernalStatus == Kernel32.WAIT_STATUS.WAIT_OBJECT_0)
{
SafePRINTER_NOTIFY_INFO ppi;
PRINTER_CHANGE chg;
bool foundPrinterNotification = FindNextPrinterChangeNotification(hChange, out chg, default, out ppi);
if (foundPrinterNotification && !ppi.IsInvalid)
{
PRINTER_NOTIFY_INFO pi = ppi;
Console.WriteLine($"{chg}: {string.Join(",", pi.aData?.Select(d => d.Field))}");
}
}
}
When running this program, I just request the printer to print a test page. Everything goes as expected until it hits the FindNextPrinterChangeNotification method and checks if the PPI is valid, which it is not.
Expected behavior
I expected that within the 'FindNextPrinterChangeNotification' the ppi 'SafePRINTER_NOTIFY_INFO ' should receive the printer information for the change notification.
Describe the bug and how to reproduce
Having an issue with the 'FindNextPrinterChangeNotification' method within the "WinSpool". The 4th parameter, out SafePRINTER_NOTIFY_INFO pointer to a buffer that receives the printer information for the change notification, isn't set as it should be and keeps being invalid.
What code is involved
This behavior is happening within the test StartWriteEndDocPagePrinterTest. Below is my own implementation:
When running this program, I just request the printer to print a test page. Everything goes as expected until it hits the FindNextPrinterChangeNotification method and checks if the PPI is valid, which it is not.
Expected behavior
I expected that within the 'FindNextPrinterChangeNotification' the ppi 'SafePRINTER_NOTIFY_INFO ' should receive the printer information for the change notification.