ReactOS 0.4.16-dev-297-gc569aee
winstation.c File Reference
#include <windef.h>
#include <winbase.h>
#include <wincon.h>
#include <winuser.h>
#include <strsafe.h>
#include "resource.h"
Include dependency graph for winstation.c:

Go to the source code of this file.

Classes

struct  _LOG_FILE
 

Typedefs

typedef struct _LOG_FILE LOG_FILE
 
typedef struct _LOG_FILEPLOG_FILE
 

Functions

BOOL InitLog (OUT PLOG_FILE LogFile, IN LPCWSTR LogFileName, IN PWCHAR pBuffer, IN size_t cbBufferSize)
 
VOID CloseLog (IN PLOG_FILE LogFile)
 
BOOL WriteToLog (IN PLOG_FILE LogFile, IN LPCVOID Buffer, IN DWORD dwBufferSize)
 
BOOL WriteToLogPuts (IN PLOG_FILE LogFile, IN LPCWSTR String)
 
BOOL WriteToLogPrintfV (IN PLOG_FILE LogFile, IN LPCWSTR Format, IN va_list args)
 
BOOL WriteToLogPrintf (IN PLOG_FILE LogFile, IN LPCWSTR Format,...)
 
BOOL CALLBACK EnumDesktopProc (IN LPWSTR lpszDesktop, IN LPARAM lParam)
 
VOID DoTest (HWND hWnd)
 
INT_PTR CALLBACK About (HWND hDlg, UINT message, WPARAM wParam, LPARAM lParam)
 
int APIENTRY wWinMain (HINSTANCE hInstance, HINSTANCE hPrevInstance, LPWSTR lpCmdLine, int nCmdShow)
 

Typedef Documentation

◆ LOG_FILE

◆ PLOG_FILE

Function Documentation

◆ About()

INT_PTR CALLBACK About ( HWND  hDlg,
UINT  message,
WPARAM  wParam,
LPARAM  lParam 
)

Definition at line 204 of file winstation.c.

205{
207 switch (message)
208 {
209 case WM_INITDIALOG:
210 return (INT_PTR)TRUE;
211
212 case WM_COMMAND:
213 switch (LOWORD(wParam))
214 {
215 case IDOK:
216 DoTest(hDlg);
217 EndDialog(hDlg, LOWORD(wParam));
218 break;
219
220 case IDCANCEL:
221 default:
222 EndDialog(hDlg, LOWORD(wParam));
223 break;
224 }
225 return (INT_PTR)TRUE;
226 }
227 return (INT_PTR)FALSE;
228}
WPARAM wParam
Definition: combotst.c:138
LPARAM lParam
Definition: combotst.c:139
#define TRUE
Definition: types.h:120
#define FALSE
Definition: types.h:117
#define UNREFERENCED_PARAMETER(P)
Definition: ntbasedef.h:325
#define LOWORD(l)
Definition: pedump.c:82
Definition: tftpd.h:60
int32_t INT_PTR
Definition: typedefs.h:64
VOID DoTest(HWND hWnd)
Definition: winstation.c:143
#define IDCANCEL
Definition: winuser.h:834
#define WM_COMMAND
Definition: winuser.h:1743
#define WM_INITDIALOG
Definition: winuser.h:1742
#define IDOK
Definition: winuser.h:833
BOOL WINAPI EndDialog(_In_ HWND, _In_ INT_PTR)

Referenced by wWinMain().

◆ CloseLog()

VOID CloseLog ( IN PLOG_FILE  LogFile)

Definition at line 58 of file winstation.c.

60{
61 CloseHandle(LogFile->hLogFile);
62 ZeroMemory(LogFile, sizeof(*LogFile));
63}
#define CloseHandle
Definition: compat.h:739
#define ZeroMemory
Definition: winbase.h:1737

Referenced by DoTest().

◆ DoTest()

VOID DoTest ( HWND  hWnd)

Definition at line 143 of file winstation.c.

144{
145 HWINSTA hWinSta;
146 LPCWSTR lpszWinSta = L"Test-WinSta";
147 BOOL bIsItOk;
148 LOG_FILE LogFile;
149 WCHAR szBuffer[2048];
150
151 bIsItOk = InitLog(&LogFile, L"test_winsta.log", szBuffer, sizeof(szBuffer));
152 if (!bIsItOk)
153 {
154 MessageBoxW(hWnd, L"Could not create the log file, stopping test now...", L"Error", MB_ICONERROR | MB_OK);
155 return;
156 }
157
158 /* Switch output to UTF-16 (little endian) */
159 WriteToLog(&LogFile, "\xFF\xFE", 2);
160
161 WriteToLogPrintf(&LogFile, L"Creating Window Station '%s'\r\n", lpszWinSta);
162 hWinSta = CreateWindowStationW(lpszWinSta, 0, WINSTA_ALL_ACCESS, NULL);
163 WriteToLogPrintf(&LogFile, L"--> Returned handle 0x%p ; last error: %lu\r\n", hWinSta, GetLastError());
164
165 if (!hWinSta)
166 {
167 WriteToLogPuts(&LogFile, L"\r\nHandle is NULL, cannot proceed further, stopping the test!\r\n\r\n");
168 return;
169 }
170
171 WriteToLogPrintf(&LogFile, L"Enumerate desktops on Window Station '%s' (0x%p) (before process attach)\r\n", lpszWinSta, hWinSta);
172 bIsItOk = EnumDesktopsW(hWinSta, EnumDesktopProc, (LPARAM)&LogFile);
173 WriteToLogPrintf(&LogFile, L"--> Returned %s ; last error: %lu\r\n",
174 (bIsItOk ? L"success" : L"failure"), GetLastError());
175
176 WriteToLogPrintf(&LogFile, L"Setting current process to Window Station '%s' (0x%p)\r\n", lpszWinSta, hWinSta);
177 bIsItOk = SetProcessWindowStation(hWinSta);
178 WriteToLogPrintf(&LogFile, L"--> Returned %s ; last error: %lu\r\n",
179 (bIsItOk ? L"success" : L"failure"), GetLastError());
180
181 WriteToLogPrintf(&LogFile, L"Enumerate desktops on Window Station '%s' (0x%p) (after process attach, before allocating console)\r\n", lpszWinSta, hWinSta);
182 bIsItOk = EnumDesktopsW(hWinSta, EnumDesktopProc, (LPARAM)&LogFile);
183 WriteToLogPrintf(&LogFile, L"--> Returned %s ; last error: %lu\r\n",
184 (bIsItOk ? L"success" : L"failure"), GetLastError());
185
186 WriteToLogPrintf(&LogFile, L"Allocating a new console on Window Station '%s' (0x%p)\r\n", lpszWinSta, hWinSta);
187 bIsItOk = AllocConsole();
188 WriteToLogPrintf(&LogFile, L"--> Returned %s ; last error: %lu\r\n",
189 (bIsItOk ? L"success" : L"failure"), GetLastError());
190
191 WriteToLogPrintf(&LogFile, L"Enumerate desktops on Window Station '%s' (0x%p) (after allocating console)\r\n", lpszWinSta, hWinSta);
192 bIsItOk = EnumDesktopsW(hWinSta, EnumDesktopProc, (LPARAM)&LogFile);
193 WriteToLogPrintf(&LogFile, L"--> Returned %s ; last error: %lu\r\n",
194 (bIsItOk ? L"success" : L"failure"), GetLastError());
195
196 WriteToLogPrintf(&LogFile, L"Now closing Window Station '%s' (0x%p)\r\n", lpszWinSta, hWinSta);
197 bIsItOk = CloseWindowStation(hWinSta);
198 WriteToLogPrintf(&LogFile, L"--> Returned %s ; last error: %lu\r\n\r\n",
199 (bIsItOk ? L"success" : L"failure"), GetLastError());
200
201 CloseLog(&LogFile);
202}
HWND hWnd
Definition: settings.c:17
BOOL WINAPI AllocConsole(VOID)
Definition: console.c:74
#define NULL
Definition: types.h:112
unsigned int BOOL
Definition: ntddk_ex.h:94
void InitLog(void)
Definition: log.c:20
#define L(x)
Definition: ntvdm.h:50
BOOL CALLBACK EnumDesktopProc(IN LPWSTR lpszDesktop, IN LPARAM lParam)
Definition: winstation.c:125
BOOL WriteToLogPrintf(IN PLOG_FILE LogFile, IN LPCWSTR Format,...)
Definition: winstation.c:103
BOOL WriteToLogPuts(IN PLOG_FILE LogFile, IN LPCWSTR String)
Definition: winstation.c:78
BOOL WriteToLog(IN PLOG_FILE LogFile, IN LPCVOID Buffer, IN DWORD dwBufferSize)
Definition: winstation.c:66
VOID CloseLog(IN PLOG_FILE LogFile)
Definition: winstation.c:58
DWORD WINAPI GetLastError(void)
Definition: except.c:1042
LONG_PTR LPARAM
Definition: windef.h:208
HWINSTA WINAPI CreateWindowStationW(_In_opt_ LPCWSTR lpwinsta, _In_ DWORD dwFlags, _In_ ACCESS_MASK dwDesiredAccess, _In_opt_ LPSECURITY_ATTRIBUTES lpsa)
BOOL WINAPI CloseWindowStation(_In_ HWINSTA)
BOOL WINAPI SetProcessWindowStation(_In_ HWINSTA)
int WINAPI MessageBoxW(_In_opt_ HWND hWnd, _In_opt_ LPCWSTR lpText, _In_opt_ LPCWSTR lpCaption, _In_ UINT uType)
#define MB_ICONERROR
Definition: winuser.h:790
BOOL WINAPI EnumDesktopsW(_In_opt_ HWINSTA, _In_ DESKTOPENUMPROCW, _In_ LPARAM)
#define WINSTA_ALL_ACCESS
Definition: winuser.h:417
#define MB_OK
Definition: winuser.h:793
__wchar_t WCHAR
Definition: xmlstorage.h:180
const WCHAR * LPCWSTR
Definition: xmlstorage.h:185

Referenced by About(), and ProcessCommandLine().

◆ EnumDesktopProc()

BOOL CALLBACK EnumDesktopProc ( IN LPWSTR  lpszDesktop,
IN LPARAM  lParam 
)

Definition at line 125 of file winstation.c.

128{
129 PLOG_FILE LogFile = (PLOG_FILE)lParam;
130
131 WriteToLogPrintf(LogFile, L" :: Found desktop '%s'\r\n", lpszDesktop);
132
133 /* Continue the enumeration */
134 return TRUE;
135}
struct _LOG_FILE * PLOG_FILE

Referenced by DoTest().

◆ InitLog()

BOOL InitLog ( OUT PLOG_FILE  LogFile,
IN LPCWSTR  LogFileName,
IN PWCHAR  pBuffer,
IN size_t  cbBufferSize 
)

Definition at line 30 of file winstation.c.

35{
37
38 ZeroMemory(LogFile, sizeof(*LogFile));
39
43 NULL,
46 NULL);
48 return FALSE;
49
50 LogFile->hLogFile = hLogFile;
51 LogFile->pBuffer = pBuffer;
52 LogFile->cbBufferSize = cbBufferSize;
53
54 return TRUE;
55}
static HANDLE hLogFile
Definition: log.c:16
#define INVALID_HANDLE_VALUE
Definition: compat.h:731
#define CreateFileW
Definition: compat.h:741
#define FILE_ATTRIBUTE_NORMAL
Definition: compat.h:137
#define FILE_SHARE_READ
Definition: compat.h:136
#define OPEN_ALWAYS
Definition: disk.h:70
#define GENERIC_WRITE
Definition: nt_native.h:90
_Must_inspect_result_ _In_ ACCESS_MASK _In_opt_ POBJECT_ATTRIBUTES _In_opt_ PUNICODE_STRING LogFileName
Definition: nttmapi.h:324
PVOID pBuffer

◆ WriteToLog()

BOOL WriteToLog ( IN PLOG_FILE  LogFile,
IN LPCVOID  Buffer,
IN DWORD  dwBufferSize 
)

Definition at line 66 of file winstation.c.

70{
71 return WriteFile(LogFile->hLogFile,
72 Buffer,
73 dwBufferSize,
74 &dwBufferSize, NULL);
75}
Definition: bufpool.h:45
BOOL WINAPI WriteFile(IN HANDLE hFile, IN LPCVOID lpBuffer, IN DWORD nNumberOfBytesToWrite OPTIONAL, OUT LPDWORD lpNumberOfBytesWritten, IN LPOVERLAPPED lpOverlapped OPTIONAL)
Definition: rw.c:24

Referenced by DoTest(), WriteToLogPrintfV(), and WriteToLogPuts().

◆ WriteToLogPrintf()

BOOL WriteToLogPrintf ( IN PLOG_FILE  LogFile,
IN LPCWSTR  Format,
  ... 
)

Definition at line 103 of file winstation.c.

107{
108 BOOL bRet;
110
112 bRet = WriteToLogPrintfV(LogFile, Format, args);
113 va_end(args);
114
115 return bRet;
116}
char * va_list
Definition: acmsvcex.h:78
#define va_end(ap)
Definition: acmsvcex.h:90
#define va_start(ap, A)
Definition: acmsvcex.h:91
#define args
Definition: format.c:66
Definition: match.c:390
BOOL WriteToLogPrintfV(IN PLOG_FILE LogFile, IN LPCWSTR Format, IN va_list args)
Definition: winstation.c:88

Referenced by DoTest(), and EnumDesktopProc().

◆ WriteToLogPrintfV()

BOOL WriteToLogPrintfV ( IN PLOG_FILE  LogFile,
IN LPCWSTR  Format,
IN va_list  args 
)

Definition at line 88 of file winstation.c.

92{
93 StringCbVPrintfW(LogFile->pBuffer,
94 LogFile->cbBufferSize,
95 Format, args);
96
97 return WriteToLog(LogFile,
98 LogFile->pBuffer,
99 wcslen(LogFile->pBuffer) * sizeof(WCHAR));
100}
_CRTIMP size_t __cdecl wcslen(_In_z_ const wchar_t *_Str)
STRSAFEAPI StringCbVPrintfW(STRSAFE_LPWSTR pszDest, size_t cbDest, STRSAFE_LPCWSTR pszFormat, va_list argList)
Definition: strsafe.h:507

Referenced by WriteToLogPrintf().

◆ WriteToLogPuts()

BOOL WriteToLogPuts ( IN PLOG_FILE  LogFile,
IN LPCWSTR  String 
)

Definition at line 78 of file winstation.c.

81{
82 return WriteToLog(LogFile,
83 String,
84 wcslen(String) * sizeof(WCHAR));
85}
_Must_inspect_result_ _In_ WDFDEVICE _In_ WDFSTRING String
Definition: wdfdevice.h:2433

Referenced by DoTest().

◆ wWinMain()

int APIENTRY wWinMain ( HINSTANCE  hInstance,
HINSTANCE  hPrevInstance,
LPWSTR  lpCmdLine,
int  nShowCmd 
)

This file has no copyright assigned and is placed in the Public Domain. This file is part of the w64 mingw-runtime package. No warranty is given; refer to the file DISCLAIMER.PD within this package.

Definition at line 230 of file winstation.c.

234{
235 UNREFERENCED_PARAMETER(hPrevInstance);
236 UNREFERENCED_PARAMETER(lpCmdLine);
237
239}
#define IDD_ABOUTBOX
Definition: resource.h:8
HINSTANCE hInstance
Definition: charmap.c:19
INT_PTR CALLBACK About(HWND hDlg, UINT message, WPARAM wParam, LPARAM lParam)
Definition: winstation.c:204
#define DialogBoxW(i, t, p, f)
Definition: winuser.h:4402
#define MAKEINTRESOURCEW(i)
Definition: winuser.h:582