46 DWORD cchPortNameWithoutColon;
48 cchPortNameWithoutColon =
wcslen(pwszPortNameWithoutColon);
51 if (!*ppwszNonspooledPortName)
81 const DWORD cchPortType = 3;
85 if (
_wcsnicmp(
p, pwszPortType, cchPortType) != 0)
91 while (*
p >=
L'0' && *
p <=
L'9')
100 return (*
p ==
L'\0');
115 PWSTR pwszNonspooledPortName;
116 PWSTR pwszPortNameWithoutColon;
164 const WCHAR wszLocalSlashes[] =
L"\\\\.\\";
167 const WCHAR wszSpoolerNamedPipe[] =
L"\\Device\\NamedPipe\\Spooler\\";
168 const DWORD cchSpoolerNamedPipe =
_countof(wszSpoolerNamedPipe) - 1;
171 DWORD cchPortNameWithoutColon;
195 cchPortNameWithoutColon =
wcslen(pwszPortNameWithoutColon);
199 pwszPipeName =
DllAllocSplMem((cchSpoolerNamedPipe + cchPortNameWithoutColon + 1) *
sizeof(
WCHAR));
207 CopyMemory(pwszPipeName, wszSpoolerNamedPipe, cchSpoolerNamedPipe *
sizeof(
WCHAR));
208 CopyMemory(&pwszPipeName[cchSpoolerNamedPipe], pwszPortNameWithoutColon, (cchPortNameWithoutColon + 1) *
sizeof(
WCHAR));
213 if (!pwszDeviceMappings)
226 ERR(
"RevertToPrinterSelf failed with error %lu!\n", dwErrorCode);
262 p = pwszDeviceMappings;
269 ERR(
"Can't find a suitable mapping for the port \"%S\"!\n", pPort->
pwszPortName);
291 ERR(
"DefineDosDeviceW failed with error %lu!\n", dwErrorCode);
301 if (!pwszNonspooledFileName)
308 CopyMemory(pwszNonspooledFileName, wszLocalSlashes, cchLocalSlashes *
sizeof(
WCHAR));
317 ERR(
"CreateFileW failed with error %lu!\n", dwErrorCode);
336 if (pwszDeviceMappings)
339 if (pwszNonspooledFileName)
342 if (pwszNonspooledPortName)
348 if (pwszPortNameWithoutColon)
412 (*ppPortInfo)->Reserved = 0;
460 TRACE(
"LocalmonClosePort(%p)\n", hPort);
480 if (pPort->
PortType == PortType_FILE)
497 TRACE(
"LocalmonEndDocPort(%p)\n", hPort);
511 if (pPort->
PortType != PortType_PhysicalLPT)
538 TRACE(
"LocalmonEnumPorts(%p, %S, %lu, %p, %lu, %p, %p)\n", hMonitor,
pName,
Level, pPorts, cbBuf,
pcbNeeded, pcReturned);
636 TRACE(
"LocalmonGetPrinterDataFromPort(%p, %lu, %p, %p, %lu, %p, %lu, %p)\n", hPort, ControlID, pValueName, lpInBuffer, cbInBuffer, lpOutBuffer, cbOutBuffer, lpcbReturned);
639 if (!pPort || !ControlID || !lpcbReturned)
646 if (pPort->
PortType == PortType_PhysicalCOM)
666 if (!
DeviceIoControl(pPort->
hFile, ControlID, lpInBuffer, cbInBuffer, lpOutBuffer, cbOutBuffer, lpcbReturned,
NULL))
669 ERR(
"DeviceIoControl failed with error %lu!\n", dwErrorCode);
690 TRACE(
"LocalmonOpenPort(%p, %S, %p)\n", hMonitor,
pName, pHandle);
693 if (!pLocalmon || !
pName || !pHandle)
737 pPort->
PortType = PortType_PhysicalLPT;
755 pPort->
PortType = PortType_PhysicalCOM;
795 TRACE(
"LocalmonSetPortTimeOuts(%p, %p, %lu)\n", hPort, lpCTO,
Reserved);
798 if (!pPort || !lpCTO)
805 if (pPort->
PortType == PortType_PhysicalCOM)
828 ERR(
"SetCommTimeouts failed with error %lu!\n", dwErrorCode);
849 TRACE(
"LocalmonReadPort(%p, %p, %lu, %p)\n", hPort,
pBuffer, cbBuffer, pcbRead);
852 if (!pPort || (cbBuffer && !
pBuffer) || !pcbRead)
859 if (pPort->
PortType != PortType_PhysicalCOM && pPort->
PortType != PortType_PhysicalLPT)
866 if (pPort->
PortType == PortType_PhysicalCOM)
883 ERR(
"ReadFile failed with error %lu!\n", dwErrorCode);
902 TRACE(
"LocalmonStartDocPort(%p, %S, %lu, %lu, %p)\n", hPort, pPrinterName, JobId,
Level, pDocInfo);
928 ERR(
"OpenPrinterW failed with error %lu!\n", dwErrorCode);
936 if (pPort->
PortType == PortType_PhysicalLPT)
948 else if(pPort->
PortType == PortType_FILE)
1002 TRACE(
"LocalmonWritePort(%p, %p, %lu, %p)\n", hPort,
pBuffer, cbBuf, pcbWritten);
1005 if (!pPort || (cbBuf && !
pBuffer) || !pcbWritten)
1012 if (pPort->
PortType == PortType_PhysicalCOM)
1035 ERR(
"WriteFile failed with error %lu!\n", dwErrorCode);
1059 DWORD dwErrorCode, cbPortName;
1071 if ( ( lpMonitorName ==
NULL ) ||
1072 (
lstrcmpiW( lpMonitorName,
L"Local Port" ) != 0 ) ||
1075 (
pi->pName[0] ==
'\0' ) )
1077 ERR(
"Fail Monitor Port Name\n");
1213 pPort =
_FindPort( pLocalmon, pPortName );
static UNICODE_STRING PortName
#define RegCloseKey(hKey)
static TAGREF LPCWSTR LPDWORD LPVOID lpBuffer
#define ERROR_NOT_ENOUGH_MEMORY
#define ERROR_INSUFFICIENT_BUFFER
BOOL WINAPI DeviceIoControl(IN HANDLE hDevice, IN DWORD dwIoControlCode, IN LPVOID lpInBuffer OPTIONAL, IN DWORD nInBufferSize OPTIONAL, OUT LPVOID lpOutBuffer OPTIONAL, IN DWORD nOutBufferSize OPTIONAL, OUT LPDWORD lpBytesReturned OPTIONAL, IN LPOVERLAPPED lpOverlapped OPTIONAL)
LONG WINAPI RegOpenKeyW(HKEY hKey, LPCWSTR lpSubKey, PHKEY phkResult)
LONG WINAPI RegSetValueExW(_In_ HKEY hKey, _In_ LPCWSTR lpValueName, _In_ DWORD Reserved, _In_ DWORD dwType, _In_ CONST BYTE *lpData, _In_ DWORD cbData)
LONG WINAPI RegDeleteValueW(HKEY hKey, LPCWSTR lpValueName)
#define ERROR_INVALID_PARAMETER
#define ReadFile(a, b, c, d, e)
#define INVALID_HANDLE_VALUE
#define ERROR_INVALID_HANDLE
BOOL WINAPI DefineDosDeviceW(DWORD dwFlags, LPCWSTR lpDeviceName, LPCWSTR lpTargetPath)
DWORD WINAPI QueryDosDeviceW(LPCWSTR lpDeviceName, LPWSTR lpTargetPath, DWORD ucchMax)
BOOL WINAPI WriteFile(IN HANDLE hFile, IN LPCVOID lpBuffer, IN DWORD nNumberOfBytesToWrite OPTIONAL, OUT LPDWORD lpNumberOfBytesWritten, IN LPOVERLAPPED lpOverlapped OPTIONAL)
BOOL WINAPI SetCommTimeouts(HANDLE hComm, LPCOMMTIMEOUTS lptimeouts)
BOOL WINAPI GetCommTimeouts(HANDLE hComm, LPCOMMTIMEOUTS lptimeouts)
int WINAPI lstrcmpiW(LPCWSTR str1, LPCWSTR str2)
static const WCHAR Cleanup[]
#define RemoveEntryList(Entry)
#define InsertTailList(ListHead, Entry)
_CRTIMP size_t __cdecl wcslen(_In_z_ const wchar_t *_Str)
#define ERROR_ALREADY_EXISTS
HANDLE WINAPI RevertToPrinterSelf(VOID)
BOOL WINAPI ImpersonatePrinterClient(_In_ HANDLE hToken)
_Check_return_ _CRTIMP int __cdecl _wcsicmp(_In_z_ const wchar_t *_Str1, _In_z_ const wchar_t *_Str2)
_CRTIMP wchar_t *__cdecl wcscpy(_Out_writes_z_(_String_length_(_Source)+1) wchar_t *_Dest, _In_z_ const wchar_t *_Source)
_Check_return_ _CRTIMP int __cdecl wcscmp(_In_z_ const wchar_t *_Str1, _In_z_ const wchar_t *_Str2)
_Check_return_ _CRTIMP int __cdecl _wcsnicmp(_In_reads_or_z_(_MaxCount) const wchar_t *_Str1, _In_reads_or_z_(_MaxCount) const wchar_t *_Str2, _In_ size_t _MaxCount)
base of all file and directory entries
DWORD WriteTotalTimeoutConstant
struct _LIST_ENTRY * Flink
PLOCALMON_HANDLE pLocalmon
enum _LOCALMON_PORT::@5118 PortType
#define FIELD_OFFSET(t, f)
#define CONTAINING_RECORD(address, type, field)
BOOL WINAPI DllFreeSplMem(PVOID pMem)
PVOID WINAPI DllAllocSplMem(DWORD dwBytes)
BOOL WINAPI DllFreeSplStr(PWSTR pwszString)
PWSTR WINAPI AllocSplStr(PCWSTR pwszInput)
BOOL WINAPI LocalmonStartDocPort(HANDLE hPort, PWSTR pPrinterName, DWORD JobId, DWORD Level, PBYTE pDocInfo)
static __inline DWORD _GetNonspooledPortName(PCWSTR pwszPortNameWithoutColon, PWSTR *ppwszNonspooledPortName)
static DWORD dwPortInfo1Offsets[]
BOOL WINAPI LocalmonDeletePort(HANDLE hMonitor, LPWSTR pName, HWND hWnd, LPWSTR pPortName)
static void _ClosePortHandles(PLOCALMON_PORT pPort)
BOOL WINAPI LocalmonAddPortEx(HANDLE hMonitor, LPWSTR pName, DWORD Level, LPBYTE lpBuffer, LPWSTR lpMonitorName)
static PLOCALMON_PORT _FindPort(PLOCALMON_HANDLE pLocalmon, PCWSTR pwszPortName)
BOOL WINAPI LocalmonOpenPort(HANDLE hMonitor, PWSTR pName, PHANDLE pHandle)
static void _LocalmonGetPortLevel2(PLOCALMON_PORT pPort, PPORT_INFO_2W *ppPortInfo, PBYTE *ppPortInfoEnd, PDWORD pcbNeeded)
BOOL WINAPI LocalmonAddPort(HANDLE hMonitor, LPWSTR pName, HWND hWnd, LPWSTR pMonitorName)
BOOL WINAPI LocalmonWritePort(HANDLE hPort, PBYTE pBuffer, DWORD cbBuf, PDWORD pcbWritten)
BOOL WINAPI LocalmonEnumPorts(HANDLE hMonitor, PWSTR pName, DWORD Level, PBYTE pPorts, DWORD cbBuf, PDWORD pcbNeeded, PDWORD pcReturned)
BOOL WINAPI LocalmonReadPort(HANDLE hPort, PBYTE pBuffer, DWORD cbBuffer, PDWORD pcbRead)
static BOOL _CreateNonspooledPort(PLOCALMON_PORT pPort)
static void _LocalmonGetPortLevel1(PLOCALMON_PORT pPort, PPORT_INFO_1W *ppPortInfo, PBYTE *ppPortInfoEnd, PDWORD pcbNeeded)
static const DWORD cchNonspooledPrefix
static BOOL _SetTransmissionRetryTimeout(PLOCALMON_PORT pPort)
BOOL WINAPI LocalmonGetPrinterDataFromPort(HANDLE hPort, DWORD ControlID, PWSTR pValueName, PWSTR lpInBuffer, DWORD cbInBuffer, PWSTR lpOutBuffer, DWORD cbOutBuffer, PDWORD lpcbReturned)
static DWORD dwPortInfo2Offsets[]
BOOL WINAPI LocalmonEndDocPort(HANDLE hPort)
BOOL WINAPI LocalmonConfigurePort(HANDLE hMonitor, LPWSTR pName, HWND hWnd, LPWSTR pPortName)
static const WCHAR wszNonspooledPrefix[]
static __inline BOOL _IsLegacyPort(PCWSTR pwszPortName, PCWSTR pwszPortType)
BOOL WINAPI LocalmonClosePort(HANDLE hPort)
BOOL WINAPI LocalmonSetPortTimeOuts(HANDLE hPort, LPCOMMTIMEOUTS lpCTO, DWORD Reserved)
struct _LOCALMON_PORT * PLOCALMON_PORT
DWORD GetPortNameWithoutColon(PCWSTR pwszPortName, PWSTR *ppwszPortNameWithoutColon)
struct _LOCALMON_HANDLE * PLOCALMON_HANDLE
DWORD GetLPTTransmissionRetryTimeout(VOID)
BOOL DoesPortExist(PCWSTR pwszPortName)
DWORD WINAPI GetLastError(void)
#define DDD_RAW_TARGET_PATH
void WINAPI LeaveCriticalSection(LPCRITICAL_SECTION)
#define DDD_REMOVE_DEFINITION
void WINAPI EnterCriticalSection(LPCRITICAL_SECTION)
_In_ DWORD _Out_ PDWORD pcbNeeded
_Reserved_ PVOID Reserved
#define ERROR_INVALID_LEVEL
#define ERROR_UNKNOWN_PORT
#define HKEY_LOCAL_MACHINE
WINBOOL WINAPI SetJobW(HANDLE hPrinter, DWORD JobId, DWORD Level, LPBYTE pJob, DWORD Command)
WINBOOL WINAPI OpenPrinterW(LPWSTR pPrinterName, LPHANDLE phPrinter, LPPRINTER_DEFAULTSW pDefault)
WINBOOL WINAPI ClosePrinter(HANDLE hPrinter)
struct _PORT_INFO_1W PORT_INFO_1W
struct _DOC_INFO_1W * PDOC_INFO_1W
struct _PORT_INFO_2W PORT_INFO_2W
#define JOB_CONTROL_SENT_TO_PRINTER
_IRQL_requires_same_ typedef _In_ ULONG _In_ UCHAR Level