2015-07-07 17:06:48 +00:00
|
|
|
/*
|
|
|
|
* PROJECT: ReactOS Local Spooler
|
2017-09-29 17:18:19 +00:00
|
|
|
* LICENSE: GPL-2.0+ (https://spdx.org/licenses/GPL-2.0+)
|
2015-07-07 17:06:48 +00:00
|
|
|
* PURPOSE: Functions related to Print Monitors
|
2017-09-29 17:18:19 +00:00
|
|
|
* COPYRIGHT: Copyright 2015-2017 Colin Finck (colin@reactos.org)
|
2015-07-07 17:06:48 +00:00
|
|
|
*/
|
|
|
|
|
|
|
|
#include "precomp.h"
|
|
|
|
|
2015-07-13 10:18:07 +00:00
|
|
|
// Global Variables
|
2015-07-07 17:06:48 +00:00
|
|
|
LIST_ENTRY PrintMonitorList;
|
|
|
|
|
2017-07-05 15:29:13 +00:00
|
|
|
// Local Constants
|
|
|
|
static DWORD dwMonitorInfo1Offsets[] = {
|
|
|
|
FIELD_OFFSET(MONITOR_INFO_1W, pName),
|
|
|
|
MAXDWORD
|
|
|
|
};
|
|
|
|
|
|
|
|
static DWORD dwMonitorInfo2Offsets[] = {
|
|
|
|
FIELD_OFFSET(MONITOR_INFO_2W, pName),
|
|
|
|
FIELD_OFFSET(MONITOR_INFO_2W, pEnvironment),
|
|
|
|
FIELD_OFFSET(MONITOR_INFO_2W, pDLLName),
|
|
|
|
MAXDWORD
|
|
|
|
};
|
|
|
|
|
2015-07-13 10:18:07 +00:00
|
|
|
|
|
|
|
PLOCAL_PRINT_MONITOR
|
|
|
|
FindPrintMonitor(PCWSTR pwszName)
|
|
|
|
{
|
|
|
|
PLIST_ENTRY pEntry;
|
|
|
|
PLOCAL_PRINT_MONITOR pPrintMonitor;
|
|
|
|
|
2017-07-05 15:29:13 +00:00
|
|
|
TRACE("FindPrintMonitor(%S)\n", pwszName);
|
|
|
|
|
2015-07-20 15:21:03 +00:00
|
|
|
if (!pwszName)
|
|
|
|
return NULL;
|
|
|
|
|
2015-07-13 10:18:07 +00:00
|
|
|
for (pEntry = PrintMonitorList.Flink; pEntry != &PrintMonitorList; pEntry = pEntry->Flink)
|
|
|
|
{
|
|
|
|
pPrintMonitor = CONTAINING_RECORD(pEntry, LOCAL_PRINT_MONITOR, Entry);
|
|
|
|
|
|
|
|
if (_wcsicmp(pPrintMonitor->pwszName, pwszName) == 0)
|
|
|
|
return pPrintMonitor;
|
|
|
|
}
|
|
|
|
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
2015-07-07 17:06:48 +00:00
|
|
|
BOOL
|
2017-07-05 15:29:13 +00:00
|
|
|
InitializePrintMonitorList(void)
|
2015-07-07 17:06:48 +00:00
|
|
|
{
|
|
|
|
const WCHAR wszMonitorsPath[] = L"SYSTEM\\CurrentControlSet\\Control\\Print\\Monitors";
|
|
|
|
const DWORD cchMonitorsPath = _countof(wszMonitorsPath) - 1;
|
|
|
|
|
|
|
|
DWORD cchMaxSubKey;
|
|
|
|
DWORD cchPrintMonitorName;
|
|
|
|
DWORD dwErrorCode;
|
|
|
|
DWORD dwSubKeys;
|
|
|
|
DWORD i;
|
|
|
|
HINSTANCE hinstPrintMonitor = NULL;
|
|
|
|
HKEY hKey = NULL;
|
|
|
|
HKEY hSubKey = NULL;
|
|
|
|
MONITORINIT MonitorInit;
|
|
|
|
PInitializePrintMonitor pfnInitializePrintMonitor;
|
|
|
|
PInitializePrintMonitor2 pfnInitializePrintMonitor2;
|
|
|
|
PLOCAL_PRINT_MONITOR pPrintMonitor = NULL;
|
|
|
|
PWSTR pwszRegistryPath = NULL;
|
|
|
|
|
2017-07-05 15:29:13 +00:00
|
|
|
TRACE("InitializePrintMonitorList()\n");
|
|
|
|
|
2015-07-07 17:06:48 +00:00
|
|
|
// Initialize an empty list for our Print Monitors.
|
|
|
|
InitializeListHead(&PrintMonitorList);
|
|
|
|
|
|
|
|
// Open the key containing Print Monitors.
|
|
|
|
dwErrorCode = (DWORD)RegOpenKeyExW(HKEY_LOCAL_MACHINE, wszMonitorsPath, 0, KEY_READ, &hKey);
|
|
|
|
if (dwErrorCode != ERROR_SUCCESS)
|
|
|
|
{
|
|
|
|
ERR("RegOpenKeyExW failed with status %lu!\n", dwErrorCode);
|
|
|
|
goto Cleanup;
|
|
|
|
}
|
|
|
|
|
|
|
|
// Get the number of Print Providers and maximum sub key length.
|
|
|
|
dwErrorCode = (DWORD)RegQueryInfoKeyW(hKey, NULL, NULL, NULL, &dwSubKeys, &cchMaxSubKey, NULL, NULL, NULL, NULL, NULL, NULL);
|
|
|
|
if (dwErrorCode != ERROR_SUCCESS)
|
|
|
|
{
|
|
|
|
ERR("RegQueryInfoKeyW failed with status %lu!\n", dwErrorCode);
|
|
|
|
goto Cleanup;
|
|
|
|
}
|
|
|
|
|
|
|
|
// Loop through all available Print Providers.
|
|
|
|
for (i = 0; i < dwSubKeys; i++)
|
|
|
|
{
|
|
|
|
// Cleanup tasks from the previous run
|
|
|
|
if (hSubKey)
|
|
|
|
{
|
|
|
|
RegCloseKey(hSubKey);
|
|
|
|
hSubKey = NULL;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (pwszRegistryPath)
|
|
|
|
{
|
|
|
|
DllFreeSplMem(pwszRegistryPath);
|
|
|
|
pwszRegistryPath = NULL;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (pPrintMonitor)
|
|
|
|
{
|
|
|
|
if (pPrintMonitor->pwszFileName)
|
|
|
|
DllFreeSplMem(pPrintMonitor->pwszFileName);
|
|
|
|
|
|
|
|
if (pPrintMonitor->pwszName)
|
|
|
|
DllFreeSplMem(pPrintMonitor->pwszName);
|
|
|
|
|
|
|
|
DllFreeSplMem(pPrintMonitor);
|
|
|
|
pPrintMonitor = NULL;
|
|
|
|
}
|
|
|
|
|
|
|
|
// Create a new LOCAL_PRINT_MONITOR structure for it.
|
|
|
|
pPrintMonitor = DllAllocSplMem(sizeof(LOCAL_PRINT_MONITOR));
|
|
|
|
if (!pPrintMonitor)
|
|
|
|
{
|
|
|
|
dwErrorCode = ERROR_NOT_ENOUGH_MEMORY;
|
[PRINTING]
- Implement GetPrinterDataA, GetPrinterDataExA, GetPrinterDataExW, GetPrinterDataW, SetPrinterDataA, SetPrinterDataExA, SetPrinterDataExW, SetPrinterDataW.
They support all features for Print Server and Printer Handles (minus security checks!)
I've also added tests for them.
- Store Printer data in SOFTWARE\Microsoft\Windows NT\CurrentVersion\Print\Printers instead of SYSTEM\CurrentControlSet\Control\Print\Printers and create a registry symlink from the former path to the new one just like Windows does.
According to https://social.technet.microsoft.com/Forums/windowsserver/en-US/a683ab54-c43c-4ebe-af8f-1f7a65af2a51, this is needed when having >900 printers to work around a size limit of the SYSTEM registry hive. And if Windows has both locations, we need both for compatibility anyway.
- Add several settings which are queried by the new Printer Data APIs when working with Print Server Handles.
- Store the job directory in the Windows-compatible "DefaultSpoolDirectory" setting and make use of it.
- Revert the ASSERTs in LocalEnumPrinters again to let us verify the NULL pointer exceptions in localspl_apitest (thanks Serge! CORE-13433)
- Translate ERROR_INVALID_NAME to ERROR_INVALID_PRINTER_NAME in all cases in OpenPrinterW (thanks Victor! CORE-13412)
- Make EnumMonitorsW and EnumPortsW in spoolss more robust against failing Print Monitors.
- Remove the wrong !phPrinter check in OpenPrinterW to make Print Server Handles work for real.
- Fix error handling when memory allocation fails: HeapAlloc doesn't set last error, so it's just wrong to query or return it.
One more item done from https://reactos.org/wiki/Printing !
This is all still a big Work-in-Progress, with many subtle bugs deep down in ReactOS, for which I need to open additional tickets. But I didn't want to make this commit even bigger..
svn path=/trunk/; revision=75125
2017-06-19 14:18:19 +00:00
|
|
|
ERR("DllAllocSplMem failed!\n");
|
2015-07-07 17:06:48 +00:00
|
|
|
goto Cleanup;
|
|
|
|
}
|
|
|
|
|
|
|
|
// Allocate memory for the Print Monitor Name.
|
|
|
|
pPrintMonitor->pwszName = DllAllocSplMem((cchMaxSubKey + 1) * sizeof(WCHAR));
|
|
|
|
if (!pPrintMonitor->pwszName)
|
|
|
|
{
|
|
|
|
dwErrorCode = ERROR_NOT_ENOUGH_MEMORY;
|
[PRINTING]
- Implement GetPrinterDataA, GetPrinterDataExA, GetPrinterDataExW, GetPrinterDataW, SetPrinterDataA, SetPrinterDataExA, SetPrinterDataExW, SetPrinterDataW.
They support all features for Print Server and Printer Handles (minus security checks!)
I've also added tests for them.
- Store Printer data in SOFTWARE\Microsoft\Windows NT\CurrentVersion\Print\Printers instead of SYSTEM\CurrentControlSet\Control\Print\Printers and create a registry symlink from the former path to the new one just like Windows does.
According to https://social.technet.microsoft.com/Forums/windowsserver/en-US/a683ab54-c43c-4ebe-af8f-1f7a65af2a51, this is needed when having >900 printers to work around a size limit of the SYSTEM registry hive. And if Windows has both locations, we need both for compatibility anyway.
- Add several settings which are queried by the new Printer Data APIs when working with Print Server Handles.
- Store the job directory in the Windows-compatible "DefaultSpoolDirectory" setting and make use of it.
- Revert the ASSERTs in LocalEnumPrinters again to let us verify the NULL pointer exceptions in localspl_apitest (thanks Serge! CORE-13433)
- Translate ERROR_INVALID_NAME to ERROR_INVALID_PRINTER_NAME in all cases in OpenPrinterW (thanks Victor! CORE-13412)
- Make EnumMonitorsW and EnumPortsW in spoolss more robust against failing Print Monitors.
- Remove the wrong !phPrinter check in OpenPrinterW to make Print Server Handles work for real.
- Fix error handling when memory allocation fails: HeapAlloc doesn't set last error, so it's just wrong to query or return it.
One more item done from https://reactos.org/wiki/Printing !
This is all still a big Work-in-Progress, with many subtle bugs deep down in ReactOS, for which I need to open additional tickets. But I didn't want to make this commit even bigger..
svn path=/trunk/; revision=75125
2017-06-19 14:18:19 +00:00
|
|
|
ERR("DllAllocSplMem failed!\n");
|
2015-07-07 17:06:48 +00:00
|
|
|
goto Cleanup;
|
|
|
|
}
|
|
|
|
|
|
|
|
// Get the name of this Print Monitor.
|
|
|
|
cchPrintMonitorName = cchMaxSubKey + 1;
|
|
|
|
dwErrorCode = (DWORD)RegEnumKeyExW(hKey, i, pPrintMonitor->pwszName, &cchPrintMonitorName, NULL, NULL, NULL, NULL);
|
|
|
|
if (dwErrorCode != ERROR_SUCCESS)
|
|
|
|
{
|
|
|
|
ERR("RegEnumKeyExW failed for iteration %lu with status %lu!\n", i, dwErrorCode);
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
|
|
|
|
// Open this Print Monitor's registry key.
|
|
|
|
dwErrorCode = (DWORD)RegOpenKeyExW(hKey, pPrintMonitor->pwszName, 0, KEY_READ, &hSubKey);
|
|
|
|
if (dwErrorCode != ERROR_SUCCESS)
|
|
|
|
{
|
|
|
|
ERR("RegOpenKeyExW failed for Print Provider \"%S\" with status %lu!\n", pPrintMonitor->pwszName, dwErrorCode);
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
|
|
|
|
// Get the file name of the Print Monitor.
|
|
|
|
pPrintMonitor->pwszFileName = AllocAndRegQueryWSZ(hSubKey, L"Driver");
|
|
|
|
if (!pPrintMonitor->pwszFileName)
|
|
|
|
continue;
|
|
|
|
|
|
|
|
// Try to load it.
|
|
|
|
hinstPrintMonitor = LoadLibraryW(pPrintMonitor->pwszFileName);
|
|
|
|
if (!hinstPrintMonitor)
|
|
|
|
{
|
|
|
|
ERR("LoadLibraryW failed for \"%S\" with error %lu!\n", pPrintMonitor->pwszFileName, GetLastError());
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
|
|
|
|
// Try to find a Level 2 initialization routine first.
|
|
|
|
pfnInitializePrintMonitor2 = (PInitializePrintMonitor2)GetProcAddress(hinstPrintMonitor, "InitializePrintMonitor2");
|
|
|
|
if (pfnInitializePrintMonitor2)
|
|
|
|
{
|
|
|
|
// Prepare a MONITORINIT structure.
|
|
|
|
MonitorInit.cbSize = sizeof(MONITORINIT);
|
|
|
|
MonitorInit.bLocal = TRUE;
|
|
|
|
|
|
|
|
// TODO: Fill the other fields.
|
|
|
|
|
|
|
|
// Call the Level 2 initialization routine.
|
|
|
|
pPrintMonitor->pMonitor = (PMONITOR2)pfnInitializePrintMonitor2(&MonitorInit, &pPrintMonitor->hMonitor);
|
|
|
|
if (!pPrintMonitor->pMonitor)
|
|
|
|
{
|
|
|
|
ERR("InitializePrintMonitor2 failed for \"%S\" with error %lu!\n", pPrintMonitor->pwszFileName, GetLastError());
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
|
|
|
|
pPrintMonitor->bIsLevel2 = TRUE;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
// Try to find a Level 1 initialization routine then.
|
|
|
|
pfnInitializePrintMonitor = (PInitializePrintMonitor)GetProcAddress(hinstPrintMonitor, "InitializePrintMonitor");
|
|
|
|
if (pfnInitializePrintMonitor)
|
|
|
|
{
|
|
|
|
// Construct the registry path.
|
|
|
|
pwszRegistryPath = DllAllocSplMem((cchMonitorsPath + 1 + cchPrintMonitorName + 1) * sizeof(WCHAR));
|
|
|
|
if (!pwszRegistryPath)
|
|
|
|
{
|
|
|
|
dwErrorCode = ERROR_NOT_ENOUGH_MEMORY;
|
[PRINTING]
- Implement GetPrinterDataA, GetPrinterDataExA, GetPrinterDataExW, GetPrinterDataW, SetPrinterDataA, SetPrinterDataExA, SetPrinterDataExW, SetPrinterDataW.
They support all features for Print Server and Printer Handles (minus security checks!)
I've also added tests for them.
- Store Printer data in SOFTWARE\Microsoft\Windows NT\CurrentVersion\Print\Printers instead of SYSTEM\CurrentControlSet\Control\Print\Printers and create a registry symlink from the former path to the new one just like Windows does.
According to https://social.technet.microsoft.com/Forums/windowsserver/en-US/a683ab54-c43c-4ebe-af8f-1f7a65af2a51, this is needed when having >900 printers to work around a size limit of the SYSTEM registry hive. And if Windows has both locations, we need both for compatibility anyway.
- Add several settings which are queried by the new Printer Data APIs when working with Print Server Handles.
- Store the job directory in the Windows-compatible "DefaultSpoolDirectory" setting and make use of it.
- Revert the ASSERTs in LocalEnumPrinters again to let us verify the NULL pointer exceptions in localspl_apitest (thanks Serge! CORE-13433)
- Translate ERROR_INVALID_NAME to ERROR_INVALID_PRINTER_NAME in all cases in OpenPrinterW (thanks Victor! CORE-13412)
- Make EnumMonitorsW and EnumPortsW in spoolss more robust against failing Print Monitors.
- Remove the wrong !phPrinter check in OpenPrinterW to make Print Server Handles work for real.
- Fix error handling when memory allocation fails: HeapAlloc doesn't set last error, so it's just wrong to query or return it.
One more item done from https://reactos.org/wiki/Printing !
This is all still a big Work-in-Progress, with many subtle bugs deep down in ReactOS, for which I need to open additional tickets. But I didn't want to make this commit even bigger..
svn path=/trunk/; revision=75125
2017-06-19 14:18:19 +00:00
|
|
|
ERR("DllAllocSplMem failed!\n");
|
2015-07-07 17:06:48 +00:00
|
|
|
goto Cleanup;
|
|
|
|
}
|
|
|
|
|
|
|
|
CopyMemory(pwszRegistryPath, wszMonitorsPath, cchMonitorsPath * sizeof(WCHAR));
|
|
|
|
pwszRegistryPath[cchMonitorsPath] = L'\\';
|
|
|
|
CopyMemory(&pwszRegistryPath[cchMonitorsPath + 1], pPrintMonitor->pwszName, (cchPrintMonitorName + 1) * sizeof(WCHAR));
|
|
|
|
|
|
|
|
// Call the Level 1 initialization routine.
|
|
|
|
pPrintMonitor->pMonitor = (LPMONITOREX)pfnInitializePrintMonitor(pwszRegistryPath);
|
|
|
|
if (!pPrintMonitor->pMonitor)
|
|
|
|
{
|
|
|
|
ERR("InitializePrintMonitor failed for \"%S\" with error %lu!\n", pPrintMonitor->pwszFileName, GetLastError());
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
ERR("No initialization routine found for \"%S\"!\n", pPrintMonitor->pwszFileName);
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// Add this Print Monitor to the list.
|
|
|
|
InsertTailList(&PrintMonitorList, &pPrintMonitor->Entry);
|
|
|
|
|
|
|
|
// Don't let the cleanup routine free this.
|
|
|
|
pPrintMonitor = NULL;
|
|
|
|
}
|
|
|
|
|
|
|
|
dwErrorCode = ERROR_SUCCESS;
|
|
|
|
|
|
|
|
Cleanup:
|
|
|
|
// Inside the loop
|
|
|
|
if (hSubKey)
|
|
|
|
RegCloseKey(hSubKey);
|
|
|
|
|
|
|
|
if (pwszRegistryPath)
|
|
|
|
DllFreeSplMem(pwszRegistryPath);
|
|
|
|
|
|
|
|
if (pPrintMonitor)
|
|
|
|
{
|
|
|
|
if (pPrintMonitor->pwszFileName)
|
|
|
|
DllFreeSplMem(pPrintMonitor->pwszFileName);
|
|
|
|
|
|
|
|
if (pPrintMonitor->pwszName)
|
|
|
|
DllFreeSplMem(pPrintMonitor->pwszName);
|
|
|
|
|
|
|
|
DllFreeSplMem(pPrintMonitor);
|
|
|
|
}
|
|
|
|
|
|
|
|
// Outside the loop
|
|
|
|
if (hKey)
|
|
|
|
RegCloseKey(hKey);
|
|
|
|
|
|
|
|
SetLastError(dwErrorCode);
|
|
|
|
return (dwErrorCode == ERROR_SUCCESS);
|
|
|
|
}
|
|
|
|
|
2017-07-05 15:29:13 +00:00
|
|
|
static void
|
|
|
|
_LocalGetMonitorLevel1(PLOCAL_PRINT_MONITOR pPrintMonitor, PMONITOR_INFO_1W* ppMonitorInfo, PBYTE* ppMonitorInfoEnd, PDWORD pcbNeeded)
|
|
|
|
{
|
|
|
|
DWORD cbMonitorName;
|
2019-01-06 11:18:40 +00:00
|
|
|
PCWSTR pwszStrings[1];
|
2017-07-05 15:29:13 +00:00
|
|
|
|
|
|
|
// Calculate the string lengths.
|
|
|
|
if (!ppMonitorInfo)
|
|
|
|
{
|
|
|
|
cbMonitorName = (wcslen(pPrintMonitor->pwszName) + 1) * sizeof(WCHAR);
|
|
|
|
|
|
|
|
*pcbNeeded += sizeof(MONITOR_INFO_1W) + cbMonitorName;
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
// Set the pName field.
|
|
|
|
pwszStrings[0] = pPrintMonitor->pwszName;
|
|
|
|
|
|
|
|
// Copy the structure and advance to the next one in the output buffer.
|
|
|
|
*ppMonitorInfoEnd = PackStrings(pwszStrings, (PBYTE)(*ppMonitorInfo), dwMonitorInfo1Offsets, *ppMonitorInfoEnd);
|
|
|
|
(*ppMonitorInfo)++;
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
_LocalGetMonitorLevel2(PLOCAL_PRINT_MONITOR pPrintMonitor, PMONITOR_INFO_2W* ppMonitorInfo, PBYTE* ppMonitorInfoEnd, PDWORD pcbNeeded)
|
2015-07-07 17:06:48 +00:00
|
|
|
{
|
|
|
|
DWORD cbFileName;
|
|
|
|
DWORD cbMonitorName;
|
2019-01-06 11:18:40 +00:00
|
|
|
PCWSTR pwszStrings[3];
|
2017-07-05 15:29:13 +00:00
|
|
|
|
|
|
|
// Calculate the string lengths.
|
|
|
|
if (!ppMonitorInfo)
|
|
|
|
{
|
|
|
|
cbMonitorName = (wcslen(pPrintMonitor->pwszName) + 1) * sizeof(WCHAR);
|
|
|
|
cbFileName = (wcslen(pPrintMonitor->pwszFileName) + 1) * sizeof(WCHAR);
|
|
|
|
|
|
|
|
*pcbNeeded += sizeof(MONITOR_INFO_2W) + cbMonitorName + cbCurrentEnvironment + cbFileName;
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
// Set the pName field.
|
|
|
|
pwszStrings[0] = pPrintMonitor->pwszName;
|
|
|
|
|
|
|
|
// Set the pEnvironment field.
|
|
|
|
pwszStrings[1] = (PWSTR)wszCurrentEnvironment;
|
|
|
|
|
|
|
|
// Set the pDLLName field.
|
|
|
|
pwszStrings[2] = pPrintMonitor->pwszFileName;
|
|
|
|
|
|
|
|
// Copy the structure and advance to the next one in the output buffer.
|
|
|
|
*ppMonitorInfoEnd = PackStrings(pwszStrings, (PBYTE)(*ppMonitorInfo), dwMonitorInfo2Offsets, *ppMonitorInfoEnd);
|
|
|
|
(*ppMonitorInfo)++;
|
|
|
|
}
|
|
|
|
|
|
|
|
BOOL WINAPI
|
|
|
|
LocalEnumMonitors(PWSTR pName, DWORD Level, PBYTE pMonitors, DWORD cbBuf, PDWORD pcbNeeded, PDWORD pcReturned)
|
|
|
|
{
|
2015-07-07 17:06:48 +00:00
|
|
|
DWORD dwErrorCode;
|
2017-07-05 15:29:13 +00:00
|
|
|
PBYTE pMonitorInfoEnd;
|
2015-07-07 17:06:48 +00:00
|
|
|
PLIST_ENTRY pEntry;
|
|
|
|
PLOCAL_PRINT_MONITOR pPrintMonitor;
|
2017-07-05 15:29:13 +00:00
|
|
|
|
|
|
|
TRACE("LocalEnumMonitors(%S, %lu, %p, %lu, %p, %p)\n", pName, Level, pMonitors, cbBuf, pcbNeeded, pcReturned);
|
2015-07-07 17:06:48 +00:00
|
|
|
|
|
|
|
// Sanity checks.
|
|
|
|
if (Level > 2)
|
|
|
|
{
|
|
|
|
dwErrorCode = ERROR_INVALID_LEVEL;
|
|
|
|
goto Cleanup;
|
|
|
|
}
|
|
|
|
|
|
|
|
// Begin counting.
|
|
|
|
*pcbNeeded = 0;
|
|
|
|
*pcReturned = 0;
|
|
|
|
|
|
|
|
// Count the required buffer size and the number of monitors.
|
|
|
|
for (pEntry = PrintMonitorList.Flink; pEntry != &PrintMonitorList; pEntry = pEntry->Flink)
|
|
|
|
{
|
|
|
|
pPrintMonitor = CONTAINING_RECORD(pEntry, LOCAL_PRINT_MONITOR, Entry);
|
|
|
|
|
|
|
|
if (Level == 1)
|
2017-07-05 15:29:13 +00:00
|
|
|
_LocalGetMonitorLevel1(pPrintMonitor, NULL, NULL, pcbNeeded);
|
|
|
|
else if (Level == 2)
|
|
|
|
_LocalGetMonitorLevel2(pPrintMonitor, NULL, NULL, pcbNeeded);
|
2015-07-07 17:06:48 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
// Check if the supplied buffer is large enough.
|
|
|
|
if (cbBuf < *pcbNeeded)
|
|
|
|
{
|
|
|
|
dwErrorCode = ERROR_INSUFFICIENT_BUFFER;
|
|
|
|
goto Cleanup;
|
|
|
|
}
|
|
|
|
|
2017-07-05 15:29:13 +00:00
|
|
|
// Copy over the Monitor information.
|
|
|
|
pMonitorInfoEnd = &pMonitors[*pcbNeeded];
|
2015-07-07 17:06:48 +00:00
|
|
|
|
|
|
|
for (pEntry = PrintMonitorList.Flink; pEntry != &PrintMonitorList; pEntry = pEntry->Flink)
|
|
|
|
{
|
|
|
|
pPrintMonitor = CONTAINING_RECORD(pEntry, LOCAL_PRINT_MONITOR, Entry);
|
|
|
|
|
|
|
|
if (Level == 1)
|
2017-07-05 15:29:13 +00:00
|
|
|
_LocalGetMonitorLevel1(pPrintMonitor, (PMONITOR_INFO_1W*)&pMonitors, &pMonitorInfoEnd, NULL);
|
|
|
|
else if (Level == 2)
|
|
|
|
_LocalGetMonitorLevel2(pPrintMonitor, (PMONITOR_INFO_2W*)&pMonitors, &pMonitorInfoEnd, NULL);
|
2015-07-07 17:06:48 +00:00
|
|
|
|
|
|
|
(*pcReturned)++;
|
|
|
|
}
|
|
|
|
|
|
|
|
dwErrorCode = ERROR_SUCCESS;
|
|
|
|
|
|
|
|
Cleanup:
|
|
|
|
SetLastError(dwErrorCode);
|
|
|
|
return (dwErrorCode == ERROR_SUCCESS);
|
|
|
|
}
|