3 * COPYRIGHT: See COPYING in the top level directory
4 * PROJECT: ReactOS user32.dll
5 * FILE: lib/user32/misc/winsta.c
6 * PURPOSE: Window stations
7 * PROGRAMMER: Casper S. Hornstrup (chorns@users.sourceforge.net)
9 * 04-06-2001 CSH Created
14 #include <wine/debug.h>
20 CloseWindowStation(HWINSTA hWinSta
)
22 return(NtUserCloseWindowStation(hWinSta
));
30 CreateWindowStationA(LPSTR lpwinsta
,
32 ACCESS_MASK dwDesiredAccess
,
33 LPSECURITY_ATTRIBUTES lpsa
)
35 UNICODE_STRING WindowStationNameU
;
40 /* After conversion, the buffer is zero-terminated */
41 RtlCreateUnicodeStringFromAsciiz(&WindowStationNameU
, lpwinsta
);
45 RtlInitUnicodeString(&WindowStationNameU
, NULL
);
48 hWinSta
= CreateWindowStationW(WindowStationNameU
.Buffer
,
53 /* Free the string, if it was allocated */
54 if (lpwinsta
) RtlFreeUnicodeString(&WindowStationNameU
);
64 CreateWindowStationW(LPWSTR lpwinsta
,
66 ACCESS_MASK dwDesiredAccess
,
67 LPSECURITY_ATTRIBUTES lpsa
)
69 UNICODE_STRING WindowStationName
;
71 RtlInitUnicodeString(&WindowStationName
, lpwinsta
);
73 return NtUserCreateWindowStation(&WindowStationName
,
79 * Common code for EnumDesktopsA/W and EnumWindowStationsA/W
82 EnumNamesW(HWINSTA WindowStation
,
83 NAMEENUMPROCW EnumFunc
,
92 ULONG CurrentEntry
, EntryCount
;
98 if (NULL
== WindowStation
&& Desktops
)
100 SetLastError(ERROR_INVALID_HANDLE
);
105 * Try with fixed-size buffer
107 Status
= NtUserBuildNameList(WindowStation
, sizeof(Buffer
), Buffer
, &RequiredSize
);
108 if (NT_SUCCESS(Status
))
110 /* Fixed-size buffer is large enough */
111 NameList
= (PWCHAR
) Buffer
;
113 else if (Status
== STATUS_BUFFER_TOO_SMALL
)
115 /* Allocate a larger buffer */
116 NameList
= HeapAlloc(GetProcessHeap(), 0, RequiredSize
);
117 if (NULL
== NameList
)
122 Status
= NtUserBuildNameList(WindowStation
, RequiredSize
, NameList
, NULL
);
123 if (! NT_SUCCESS(Status
))
125 HeapFree(GetProcessHeap(), 0, NameList
);
126 SetLastError(RtlNtStatusToDosError(Status
));
132 /* Some unrecognized error occured */
133 SetLastError(RtlNtStatusToDosError(Status
));
138 * Enum the names one by one
140 EntryCount
= *((DWORD
*) NameList
);
141 Name
= (PWCHAR
) ((PCHAR
) NameList
+ sizeof(DWORD
));
143 for (CurrentEntry
= 0; CurrentEntry
< EntryCount
&& Ret
; ++CurrentEntry
)
145 Ret
= (*EnumFunc
)(Name
, Context
);
146 Name
+= wcslen(Name
) + 1;
152 if (NameList
!= Buffer
)
154 HeapFree(GetProcessHeap(), 0, NameList
);
161 /* For W->A conversion */
162 typedef struct tagENUMNAMESASCIICONTEXT
164 NAMEENUMPROCA UserEnumFunc
;
166 } ENUMNAMESASCIICONTEXT
, *PENUMNAMESASCIICONTEXT
;
169 * Callback used by Ascii versions. Converts the Unicode name to
170 * Ascii and then calls the user callback
173 EnumNamesCallback(LPWSTR Name
, LPARAM Param
)
175 PENUMNAMESASCIICONTEXT Context
= (PENUMNAMESASCIICONTEXT
) Param
;
182 * Determine required size of Ascii string and see if we can use
185 Len
= WideCharToMultiByte(CP_ACP
, 0, Name
, -1, NULL
, 0, NULL
, NULL
);
188 /* Some strange error occured */
191 else if (Len
<= sizeof(FixedNameA
))
193 /* Fixed-size buffer is large enough */
198 /* Allocate a larger buffer */
199 NameA
= HeapAlloc(GetProcessHeap(), 0, Len
);
202 SetLastError(ERROR_NOT_ENOUGH_MEMORY
);
208 * Do the Unicode ->Ascii conversion
210 if (0 == WideCharToMultiByte(CP_ACP
, 0, Name
, -1, NameA
, Len
, NULL
, NULL
))
212 /* Something went wrong, clean up */
213 if (NameA
!= FixedNameA
)
215 HeapFree(GetProcessHeap(), 0, NameA
);
223 Ret
= Context
->UserEnumFunc(NameA
, Context
->UserContext
);
228 if (NameA
!= FixedNameA
)
230 HeapFree(GetProcessHeap(), 0, NameA
);
237 * Common code for EnumDesktopsA and EnumWindowStationsA
240 EnumNamesA(HWINSTA WindowStation
,
241 NAMEENUMPROCA EnumFunc
,
245 ENUMNAMESASCIICONTEXT PrivateContext
;
247 PrivateContext
.UserEnumFunc
= EnumFunc
;
248 PrivateContext
.UserContext
= Context
;
250 return EnumNamesW(WindowStation
, EnumNamesCallback
, (LPARAM
) &PrivateContext
, Desktops
);
257 EnumWindowStationsA(WINSTAENUMPROCA EnumFunc
,
260 return EnumNamesA(NULL
, EnumFunc
, Context
, FALSE
);
268 EnumWindowStationsW(WINSTAENUMPROCW EnumFunc
,
271 return EnumNamesW(NULL
, EnumFunc
, Context
, FALSE
);
279 GetProcessWindowStation(VOID
)
281 return NtUserGetProcessWindowStation();
289 OpenWindowStationA(LPSTR lpszWinSta
,
291 ACCESS_MASK dwDesiredAccess
)
293 UNICODE_STRING WindowStationNameU
;
298 /* After conversion, the buffer is zero-terminated */
299 RtlCreateUnicodeStringFromAsciiz(&WindowStationNameU
, lpszWinSta
);
303 RtlInitUnicodeString(&WindowStationNameU
, NULL
);
306 hWinSta
= OpenWindowStationW(WindowStationNameU
.Buffer
,
310 /* Free the string, if it was allocated */
311 if (lpszWinSta
) RtlFreeUnicodeString(&WindowStationNameU
);
321 OpenWindowStationW(LPWSTR lpszWinSta
,
323 ACCESS_MASK dwDesiredAccess
)
325 UNICODE_STRING WindowStationName
;
327 RtlInitUnicodeString(&WindowStationName
, lpszWinSta
);
329 return NtUserOpenWindowStation(&WindowStationName
, dwDesiredAccess
);
337 SetProcessWindowStation(HWINSTA hWinSta
)
339 return NtUserSetProcessWindowStation(hWinSta
);
348 SetWindowStationUser(
355 return NtUserSetWindowStationUser(Unknown1
, Unknown2
, Unknown3
, Unknown4
);
364 LockWindowStation(HWINSTA hWinSta
)
366 return NtUserLockWindowStation(hWinSta
);
375 UnlockWindowStation(HWINSTA hWinSta
)
377 return NtUserUnlockWindowStation(hWinSta
);