取得したPRINTER_NOTIFY_INFOは、FreePrinterNotifyInfoで解放する必要があるらしい。
FreePrinterNotifyInfo 関数 (Winspool.h) - Win32 apps | Microsoft Docs
FreePrinterNotifyInfo.cppで、
FreePrinterNotifyInfoにpPNIを渡して解放する。
Microsoft Windows [Version 10.0.19043.1415] (c) Microsoft Corporation. All rights reserved. C:\Users\bg1>cd C:\Users\bg1\Documents\test C:\Users\bg1\Documents\test>FreePrinterNotifyInfo.exe thread begin before. thread wait before. threadproc begin before. Default Printer: EPSON PX-S06 Series hPrinter: 0x006f4bec pTI->m_hHandles[0]: 0x00000160 pTI->m_hHandles[1]: 0x00000164 notify! PRINTER_CHANGE_SET_PRINTER_DRIVER notify! PRINTER_CHANGE_SET_PRINTER PRINTER_CHANGE_ADD_JOB pPNI->Version = 2 pPNI->Flags = 131072 pPNI->Count = 25 pPNI->aData[i].Id = 00000000 pPNI->aData[i].Type = 00000000 pPNI->aData[i].Id = 00000003 pPNI->aData[i].Type = 00000001 pPNI->aData[i].Id = 00000003 pPNI->aData[i].Type = 00000001 pPNI->aData[i].Id = 00000003 pPNI->aData[i].Type = 00000001 pPNI->aData[i].Id = 00000003 pPNI->aData[i].Type = 00000001 pPNI->aData[i].Id = 00000003 pPNI->aData[i].Type = 00000001 pPNI->aData[i].Id = 00000003 pPNI->aData[i].Type = 00000001 pPNI->aData[i].Id = 00000003 pPNI->aData[i].Type = 00000001 pPNI->aData[i].Id = 00000003 pPNI->aData[i].Type = 00000001 pPNI->aData[i].Id = 00000003 pPNI->aData[i].Type = 00000001 pPNI->aData[i].Id = 00000003 pPNI->aData[i].Type = 00000001 pPNI->aData[i].Id = 00000003 pPNI->aData[i].Type = 00000001 pPNI->aData[i].Id = 00000003 pPNI->aData[i].Type = 00000001 pPNI->aData[i].Id = 00000003 pPNI->aData[i].Type = 00000001 pPNI->aData[i].Id = 00000003 pPNI->aData[i].Type = 00000001 pPNI->aData[i].Id = 00000003 pPNI->aData[i].Type = 00000001 pPNI->aData[i].Id = 00000003 pPNI->aData[i].Type = 00000001 pPNI->aData[i].Id = 00000003 pPNI->aData[i].Type = 00000001 pPNI->aData[i].Id = 00000003 pPNI->aData[i].Type = 00000001 pPNI->aData[i].Id = 00000003 pPNI->aData[i].Type = 00000001 pPNI->aData[i].Id = 00000003 pPNI->aData[i].Type = 00000001 pPNI->aData[i].Id = 00000003 pPNI->aData[i].Type = 00000001 pPNI->aData[i].Id = 00000003 pPNI->aData[i].Type = 00000001 pPNI->aData[i].Id = 00000003 pPNI->aData[i].Type = 00000001 pPNI->aData[i].Id = 00000003 pPNI->aData[i].Type = 00000001 notify! PRINTER_CHANGE_WRITE_JOB pPNI->Version = 2 pPNI->Flags = 131072 pPNI->Count = 2 pPNI->aData[i].Id = 00000003 pPNI->aData[i].Type = 00000001 pPNI->aData[i].Id = 00000003 pPNI->aData[i].Type = 00000001 notify! PRINTER_CHANGE_SET_JOB pPNI->Version = 2 pPNI->Flags = 131072 pPNI->Count = 7 pPNI->aData[i].Id = 00000003 pPNI->aData[i].Type = 00000001 pPNI->aData[i].Id = 00000003 pPNI->aData[i].Type = 00000001 pPNI->aData[i].Id = 00000003 pPNI->aData[i].Type = 00000001 pPNI->aData[i].Id = 00000003 pPNI->aData[i].Type = 00000001 pPNI->aData[i].Id = 00000003 pPNI->aData[i].Type = 00000001 pPNI->aData[i].Id = 00000003 pPNI->aData[i].Type = 00000001 pPNI->aData[i].Id = 00000003 pPNI->aData[i].Type = 00000001 notify! PRINTER_CHANGE_WRITE_JOB pPNI->Version = 2 pPNI->Flags = 131072 pPNI->Count = 2 pPNI->aData[i].Id = 00000003 pPNI->aData[i].Type = 00000001 pPNI->aData[i].Id = 00000003 pPNI->aData[i].Type = 00000001 notify! PRINTER_CHANGE_WRITE_JOB pPNI->Version = 2 pPNI->Flags = 131072 pPNI->Count = 2 pPNI->aData[i].Id = 00000003 pPNI->aData[i].Type = 00000001 pPNI->aData[i].Id = 00000003 pPNI->aData[i].Type = 00000001 notify! PRINTER_CHANGE_WRITE_JOB pPNI->Version = 2 pPNI->Flags = 131072 pPNI->Count = 2 pPNI->aData[i].Id = 00000003 pPNI->aData[i].Type = 00000001 pPNI->aData[i].Id = 00000003 pPNI->aData[i].Type = 00000001 notify! PRINTER_CHANGE_SET_JOB pPNI->Version = 2 pPNI->Flags = 131072 pPNI->Count = 1 pPNI->aData[i].Id = 00000003 pPNI->aData[i].Type = 00000001 notify! PRINTER_CHANGE_SET_PRINTER PRINTER_CHANGE_SET_JOB PRINTER_CHANGE_DELETE_JOB pPNI->Version = 2 pPNI->Flags = 131072 pPNI->Count = 12 pPNI->aData[i].Id = 00000003 pPNI->aData[i].Type = 00000001 pPNI->aData[i].Id = 00000003 pPNI->aData[i].Type = 00000001 pPNI->aData[i].Id = 00000003 pPNI->aData[i].Type = 00000001 pPNI->aData[i].Id = 00000003 pPNI->aData[i].Type = 00000001 pPNI->aData[i].Id = 00000003 pPNI->aData[i].Type = 00000001 pPNI->aData[i].Id = 00000003 pPNI->aData[i].Type = 00000001 pPNI->aData[i].Id = 00000003 pPNI->aData[i].Type = 00000001 pPNI->aData[i].Id = 00000003 pPNI->aData[i].Type = 00000001 pPNI->aData[i].Id = 00000003 pPNI->aData[i].Type = 00000001 pPNI->aData[i].Id = 00000003 pPNI->aData[i].Type = 00000001 pPNI->aData[i].Id = 00000000 pPNI->aData[i].Type = 00000000 pPNI->aData[i].Id = 00000003 pPNI->aData[i].Type = 00000001 threadproc after before. thread close before. C:\Users\bg1\Documents\test>
あとは、特に変わらない。