ReactOS  0.4.14-dev-384-g5b37caa
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 }
Definition: tftpd.h:59
#define TRUE
Definition: types.h:120
#define IDOK
Definition: winuser.h:824
#define UNREFERENCED_PARAMETER(P)
Definition: ntbasedef.h:323
int32_t INT_PTR
Definition: typedefs.h:62
BOOL WINAPI EndDialog(_In_ HWND, _In_ INT_PTR)
WPARAM wParam
Definition: combotst.c:138
VOID DoTest(HWND hWnd)
Definition: winstation.c:143
#define WM_COMMAND
Definition: winuser.h:1722
#define IDCANCEL
Definition: winuser.h:825
#define WM_INITDIALOG
Definition: winuser.h:1721
LPARAM lParam
Definition: combotst.c:139
#define LOWORD(l)
Definition: pedump.c:82

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:406
#define ZeroMemory
Definition: winbase.h:1642

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 }
BOOL WINAPI AllocConsole(VOID)
Definition: console.c:48
const WCHAR * LPCWSTR
Definition: xmlstorage.h:185
BOOL WriteToLogPuts(IN PLOG_FILE LogFile, IN LPCWSTR String)
Definition: winstation.c:78
HWND hWnd
Definition: settings.c:17
DWORD WINAPI GetLastError(VOID)
Definition: except.c:1059
BOOL WINAPI SetProcessWindowStation(_In_ HWINSTA)
BOOL WriteToLog(IN PLOG_FILE LogFile, IN LPCVOID Buffer, IN DWORD dwBufferSize)
Definition: winstation.c:66
unsigned int BOOL
Definition: ntddk_ex.h:94
smooth NULL
Definition: ftsmooth.c:416
LONG_PTR LPARAM
Definition: windef.h:208
int WINAPI MessageBoxW(_In_opt_ HWND, _In_opt_ LPCWSTR, _In_opt_ LPCWSTR, _In_ UINT)
__wchar_t WCHAR
Definition: xmlstorage.h:180
BOOL WINAPI EnumDesktopsW(_In_opt_ HWINSTA, _In_ DESKTOPENUMPROCW, _In_ LPARAM)
static const WCHAR L[]
Definition: oid.c:1250
#define MB_ICONERROR
Definition: winuser.h:781
BOOL WriteToLogPrintf(IN PLOG_FILE LogFile, IN LPCWSTR Format,...)
Definition: winstation.c:103
#define WINSTA_ALL_ACCESS
Definition: winuser.h:417
BOOL CALLBACK EnumDesktopProc(IN LPWSTR lpszDesktop, IN LPARAM lParam)
Definition: winstation.c:125
VOID CloseLog(IN PLOG_FILE LogFile)
Definition: winstation.c:58
#define MB_OK
Definition: winuser.h:784
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 InitLog(OUT PLOG_FILE LogFile, IN LPCWSTR LogFileName, IN PWCHAR pBuffer, IN size_t cbBufferSize)
Definition: winstation.c:30

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 }
#define TRUE
Definition: types.h:120
struct _LOG_FILE * PLOG_FILE
static const WCHAR L[]
Definition: oid.c:1250
BOOL WriteToLogPrintf(IN PLOG_FILE LogFile, IN LPCWSTR Format,...)
Definition: winstation.c:103
LPARAM lParam
Definition: combotst.c:139

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 }
#define TRUE
Definition: types.h:120
#define INVALID_HANDLE_VALUE
Definition: compat.h:399
#define ZeroMemory
Definition: winbase.h:1642
#define FILE_SHARE_READ
Definition: compat.h:125
#define GENERIC_WRITE
Definition: nt_native.h:90
smooth NULL
Definition: ftsmooth.c:416
PVOID pBuffer
HANDLE hLogFile
Definition: logfile.c:34
#define OPEN_ALWAYS
Definition: disk.h:70
_Must_inspect_result_ _In_ ACCESS_MASK _In_opt_ POBJECT_ATTRIBUTES _In_opt_ PUNICODE_STRING LogFileName
Definition: nttmapi.h:322
#define FILE_ATTRIBUTE_NORMAL
Definition: compat.h:126
#define CreateFileW
Definition: compat.h:408

Referenced by DoTest().

◆ 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 }
BOOL WINAPI WriteFile(IN HANDLE hFile, IN LPCVOID lpBuffer, IN DWORD nNumberOfBytesToWrite OPTIONAL, OUT LPDWORD lpNumberOfBytesWritten, IN LPOVERLAPPED lpOverlapped OPTIONAL)
Definition: rw.c:24
smooth NULL
Definition: ftsmooth.c:416
Definition: bufpool.h:45

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;
109  va_list args;
110 
111  va_start(args, Format);
112  bRet = WriteToLogPrintfV(LogFile, Format, args);
113  va_end(args);
114 
115  return bRet;
116 }
BOOL WriteToLogPrintfV(IN PLOG_FILE LogFile, IN LPCWSTR Format, IN va_list args)
Definition: winstation.c:88
Definition: match.c:390
#define va_end(ap)
Definition: acmsvcex.h:90
unsigned int BOOL
Definition: ntddk_ex.h:94
char * va_list
Definition: acmsvcex.h:78
#define va_start(ap, A)
Definition: acmsvcex.h:91
#define args
Definition: format.c:66

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 }
Definition: match.c:390
STRSAFEAPI StringCbVPrintfW(STRSAFE_LPWSTR pszDest, size_t cbDest, STRSAFE_LPCWSTR pszFormat, va_list argList)
Definition: strsafe.h:507
BOOL WriteToLog(IN PLOG_FILE LogFile, IN LPCVOID Buffer, IN DWORD dwBufferSize)
Definition: winstation.c:66
__wchar_t WCHAR
Definition: xmlstorage.h:180
size_t __cdecl wcslen(_In_z_ const wchar_t *_Str)

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 }
static WCHAR String[]
Definition: stringtable.c:55
BOOL WriteToLog(IN PLOG_FILE LogFile, IN LPCVOID Buffer, IN DWORD dwBufferSize)
Definition: winstation.c:66
__wchar_t WCHAR
Definition: xmlstorage.h:180
size_t __cdecl wcslen(_In_z_ const wchar_t *_Str)

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 UNREFERENCED_PARAMETER(P)
Definition: ntbasedef.h:323
HINSTANCE hInstance
Definition: charmap.c:20
#define IDD_ABOUTBOX
Definition: resource.h:8
smooth NULL
Definition: ftsmooth.c:416
#define DialogBoxW(i, t, p, f)
Definition: winuser.h:4300
INT_PTR CALLBACK About(HWND hDlg, UINT message, WPARAM wParam, LPARAM lParam)
Definition: winstation.c:204
#define MAKEINTRESOURCEW(i)
Definition: winuser.h:582