2 * Window stations and desktops
4 * Copyright 2002 Alexandre Julliard
6 * This library is free software; you can redistribute it and/or
7 * modify it under the terms of the GNU Lesser General Public
8 * License as published by the Free Software Foundation; either
9 * version 2.1 of the License, or (at your option) any later version.
11 * This library is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14 * Lesser General Public License for more details.
16 * You should have received a copy of the GNU Lesser General Public
17 * License along with this library; if not, write to the Free Software
18 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA
22 #define WIN32_NO_STATUS
31 #include "wine/server.h"
32 #include "wine/unicode.h"
33 #include "wine/debug.h"
34 #include "user_private.h"
36 WINE_DEFAULT_DEBUG_CHANNEL(winstation);
39 /* callback for enumeration functions */
40 struct enum_proc_lparam
46 static BOOL CALLBACK enum_names_WtoA( LPWSTR name, LPARAM lparam )
48 struct enum_proc_lparam *data = (struct enum_proc_lparam *)lparam;
49 char buffer[MAX_PATH];
51 if (!WideCharToMultiByte( CP_ACP, 0, name, -1, buffer, sizeof(buffer), NULL, NULL ))
53 return data->func( buffer, data->lparam );
57 /***********************************************************************
58 * CreateWindowStationA (USER32.@)
60 HWINSTA WINAPI CreateWindowStationA( LPCSTR name, DWORD reserved, ACCESS_MASK access,
61 LPSECURITY_ATTRIBUTES sa )
63 WCHAR buffer[MAX_PATH];
65 if (!name) return CreateWindowStationW( NULL, reserved, access, sa );
67 if (!MultiByteToWideChar( CP_ACP, 0, name, -1, buffer, MAX_PATH ))
69 SetLastError( ERROR_FILENAME_EXCED_RANGE );
72 return CreateWindowStationW( buffer, reserved, access, sa );
76 /***********************************************************************
77 * CreateWindowStationW (USER32.@)
79 HWINSTA WINAPI CreateWindowStationW( LPCWSTR name, DWORD reserved, ACCESS_MASK access,
80 LPSECURITY_ATTRIBUTES sa )
83 DWORD len = name ? strlenW(name) : 0;
87 SetLastError( ERROR_FILENAME_EXCED_RANGE );
90 SERVER_START_REQ( create_winstation )
94 req->attributes = OBJ_CASE_INSENSITIVE | OBJ_OPENIF |
95 ((sa && sa->bInheritHandle) ? OBJ_INHERIT : 0);
96 wine_server_add_data( req, name, len * sizeof(WCHAR) );
97 /* it doesn't seem to set last error */
98 wine_server_call( req );
106 /******************************************************************************
107 * OpenWindowStationA (USER32.@)
109 HWINSTA WINAPI OpenWindowStationA( LPCSTR name, BOOL inherit, ACCESS_MASK access )
111 WCHAR buffer[MAX_PATH];
113 if (!name) return OpenWindowStationW( NULL, inherit, access );
115 if (!MultiByteToWideChar( CP_ACP, 0, name, -1, buffer, MAX_PATH ))
117 SetLastError( ERROR_FILENAME_EXCED_RANGE );
120 return OpenWindowStationW( buffer, inherit, access );
124 /******************************************************************************
125 * OpenWindowStationW (USER32.@)
127 HWINSTA WINAPI OpenWindowStationW( LPCWSTR name, BOOL inherit, ACCESS_MASK access )
130 DWORD len = name ? strlenW(name) : 0;
133 SetLastError( ERROR_FILENAME_EXCED_RANGE );
136 SERVER_START_REQ( open_winstation )
138 req->access = access;
139 req->attributes = OBJ_CASE_INSENSITIVE | (inherit ? OBJ_INHERIT : 0);
140 wine_server_add_data( req, name, len * sizeof(WCHAR) );
141 if (!wine_server_call_err( req )) ret = reply->handle;
148 /***********************************************************************
149 * CloseWindowStation (USER32.@)
151 BOOL WINAPI CloseWindowStation( HWINSTA handle )
154 SERVER_START_REQ( close_winstation )
156 req->handle = handle;
157 ret = !wine_server_call_err( req );
164 /******************************************************************************
165 * GetProcessWindowStation (USER32.@)
167 HWINSTA WINAPI GetProcessWindowStation(void)
171 SERVER_START_REQ( get_process_winstation )
173 if (!wine_server_call_err( req )) ret = reply->handle;
180 /***********************************************************************
181 * SetProcessWindowStation (USER32.@)
183 BOOL WINAPI SetProcessWindowStation( HWINSTA handle )
187 SERVER_START_REQ( set_process_winstation )
189 req->handle = handle;
190 ret = !wine_server_call_err( req );
197 /******************************************************************************
198 * EnumWindowStationsA (USER32.@)
200 BOOL WINAPI EnumWindowStationsA( WINSTAENUMPROCA func, LPARAM lparam )
202 struct enum_proc_lparam data;
204 data.lparam = lparam;
205 return EnumWindowStationsW( enum_names_WtoA, (LPARAM)&data );
209 /******************************************************************************
210 * EnumWindowStationsW (USER32.@)
212 BOOL WINAPI EnumWindowStationsW( WINSTAENUMPROCW func, LPARAM lparam )
214 unsigned int index = 0;
215 WCHAR name[MAX_PATH];
221 SERVER_START_REQ( enum_winstation )
224 wine_server_set_reply( req, name, sizeof(name) - sizeof(WCHAR) );
225 status = wine_server_call( req );
226 name[wine_server_reply_size(reply)/sizeof(WCHAR)] = 0;
230 if (status == STATUS_NO_MORE_ENTRIES)
234 SetLastError( RtlNtStatusToDosError( status ) );
237 ret = func( name, lparam );
243 /***********************************************************************
244 * CreateDesktopA (USER32.@)
246 HDESK WINAPI CreateDesktopA( LPCSTR name, LPCSTR device, LPDEVMODEA devmode,
247 DWORD flags, ACCESS_MASK access, LPSECURITY_ATTRIBUTES sa )
249 WCHAR buffer[MAX_PATH];
251 if (device || devmode)
253 SetLastError( ERROR_INVALID_PARAMETER );
256 if (!name) return CreateDesktopW( NULL, NULL, NULL, flags, access, sa );
258 if (!MultiByteToWideChar( CP_ACP, 0, name, -1, buffer, MAX_PATH ))
260 SetLastError( ERROR_FILENAME_EXCED_RANGE );
263 return CreateDesktopW( buffer, NULL, NULL, flags, access, sa );
267 /***********************************************************************
268 * CreateDesktopW (USER32.@)
270 HDESK WINAPI CreateDesktopW( LPCWSTR name, LPCWSTR device, LPDEVMODEW devmode,
271 DWORD flags, ACCESS_MASK access, LPSECURITY_ATTRIBUTES sa )
274 DWORD len = name ? strlenW(name) : 0;
276 if (device || devmode)
278 SetLastError( ERROR_INVALID_PARAMETER );
283 SetLastError( ERROR_FILENAME_EXCED_RANGE );
286 SERVER_START_REQ( create_desktop )
289 req->access = access;
290 req->attributes = OBJ_CASE_INSENSITIVE | OBJ_OPENIF |
291 ((sa && sa->bInheritHandle) ? OBJ_INHERIT : 0);
292 wine_server_add_data( req, name, len * sizeof(WCHAR) );
293 /* it doesn't seem to set last error */
294 wine_server_call( req );
302 /******************************************************************************
303 * OpenDesktopA (USER32.@)
305 HDESK WINAPI OpenDesktopA( LPCSTR name, DWORD flags, BOOL inherit, ACCESS_MASK access )
307 WCHAR buffer[MAX_PATH];
309 if (!name) return OpenDesktopW( NULL, flags, inherit, access );
311 if (!MultiByteToWideChar( CP_ACP, 0, name, -1, buffer, MAX_PATH ))
313 SetLastError( ERROR_FILENAME_EXCED_RANGE );
316 return OpenDesktopW( buffer, flags, inherit, access );
320 /******************************************************************************
321 * OpenDesktopW (USER32.@)
323 HDESK WINAPI OpenDesktopW( LPCWSTR name, DWORD flags, BOOL inherit, ACCESS_MASK access )
326 DWORD len = name ? strlenW(name) : 0;
329 SetLastError( ERROR_FILENAME_EXCED_RANGE );
332 SERVER_START_REQ( open_desktop )
335 req->access = access;
336 req->attributes = OBJ_CASE_INSENSITIVE | (inherit ? OBJ_INHERIT : 0);
337 wine_server_add_data( req, name, len * sizeof(WCHAR) );
338 if (!wine_server_call( req )) ret = reply->handle;
345 /***********************************************************************
346 * CloseDesktop (USER32.@)
348 BOOL WINAPI CloseDesktop( HDESK handle )
351 SERVER_START_REQ( close_desktop )
353 req->handle = handle;
354 ret = !wine_server_call_err( req );
361 /******************************************************************************
362 * GetThreadDesktop (USER32.@)
364 HDESK WINAPI GetThreadDesktop( DWORD thread )
368 SERVER_START_REQ( get_thread_desktop )
371 if (!wine_server_call_err( req )) ret = reply->handle;
378 /******************************************************************************
379 * SetThreadDesktop (USER32.@)
381 BOOL WINAPI SetThreadDesktop( HDESK handle )
385 SERVER_START_REQ( set_thread_desktop )
387 req->handle = handle;
388 ret = !wine_server_call_err( req );
391 if (ret) get_user_thread_info()->desktop = 0; /* reset the desktop window */
396 /******************************************************************************
397 * EnumDesktopsA (USER32.@)
399 BOOL WINAPI EnumDesktopsA( HWINSTA winsta, DESKTOPENUMPROCA func, LPARAM lparam )
401 struct enum_proc_lparam data;
403 data.lparam = lparam;
404 return EnumDesktopsW( winsta, enum_names_WtoA, (LPARAM)&data );
408 /******************************************************************************
409 * EnumDesktopsW (USER32.@)
411 BOOL WINAPI EnumDesktopsW( HWINSTA winsta, DESKTOPENUMPROCW func, LPARAM lparam )
413 unsigned int index = 0;
414 WCHAR name[MAX_PATH];
419 winsta = GetProcessWindowStation();
423 SERVER_START_REQ( enum_desktop )
425 req->winstation = winsta;
427 wine_server_set_reply( req, name, sizeof(name) - sizeof(WCHAR) );
428 status = wine_server_call( req );
429 name[wine_server_reply_size(reply)/sizeof(WCHAR)] = 0;
433 if (status == STATUS_NO_MORE_ENTRIES)
437 SetLastError( RtlNtStatusToDosError( status ) );
440 ret = func(name, lparam);
446 /******************************************************************************
447 * OpenInputDesktop (USER32.@)
449 HDESK WINAPI OpenInputDesktop( DWORD flags, BOOL inherit, ACCESS_MASK access )
451 FIXME( "(%x,%i,%x): stub\n", flags, inherit, access );
452 SetLastError( ERROR_CALL_NOT_IMPLEMENTED );
457 /***********************************************************************
458 * GetUserObjectInformationA (USER32.@)
460 BOOL WINAPI GetUserObjectInformationA( HANDLE handle, INT index, LPVOID info, DWORD len, LPDWORD needed )
462 /* check for information types returning strings */
463 if (index == UOI_TYPE || index == UOI_NAME)
465 WCHAR buffer[MAX_PATH];
468 if (!GetUserObjectInformationW( handle, index, buffer, sizeof(buffer), NULL )) return FALSE;
469 lenA = WideCharToMultiByte( CP_ACP, 0, buffer, -1, NULL, 0, NULL, NULL );
470 if (needed) *needed = lenA;
473 SetLastError( ERROR_MORE_DATA );
476 if (info) WideCharToMultiByte( CP_ACP, 0, buffer, -1, info, len, NULL, NULL );
479 return GetUserObjectInformationW( handle, index, info, len, needed );
483 /***********************************************************************
484 * GetUserObjectInformationW (USER32.@)
486 BOOL WINAPI GetUserObjectInformationW( HANDLE handle, INT index, LPVOID info, DWORD len, LPDWORD needed )
488 static const WCHAR desktopW[] = { 'D','e','s','k','t','o','p',0 };
489 static const WCHAR winstationW[] = { 'W','i','n','d','o','w','S','t','a','t','i','o','n',0 };
496 USEROBJECTFLAGS *obj_flags = info;
497 if (needed) *needed = sizeof(*obj_flags);
498 if (len < sizeof(*obj_flags))
500 SetLastError( ERROR_BUFFER_OVERFLOW );
503 SERVER_START_REQ( set_user_object_info )
505 req->handle = handle;
507 ret = !wine_server_call_err( req );
510 /* FIXME: inherit flag */
511 obj_flags->dwFlags = reply->old_obj_flags;
519 SERVER_START_REQ( set_user_object_info )
521 req->handle = handle;
523 ret = !wine_server_call_err( req );
526 size_t size = reply->is_desktop ? sizeof(desktopW) : sizeof(winstationW);
527 if (needed) *needed = size;
530 SetLastError( ERROR_MORE_DATA );
533 else memcpy( info, reply->is_desktop ? desktopW : winstationW, size );
541 WCHAR buffer[MAX_PATH];
542 SERVER_START_REQ( set_user_object_info )
544 req->handle = handle;
546 wine_server_set_reply( req, buffer, sizeof(buffer) - sizeof(WCHAR) );
547 ret = !wine_server_call_err( req );
550 size_t size = wine_server_reply_size( reply );
551 buffer[size / sizeof(WCHAR)] = 0;
552 size += sizeof(WCHAR);
553 if (needed) *needed = size;
556 SetLastError( ERROR_MORE_DATA );
559 else memcpy( info, buffer, size );
567 FIXME( "not supported index %d\n", index );
570 SetLastError( ERROR_INVALID_PARAMETER );
576 /******************************************************************************
577 * SetUserObjectInformationA (USER32.@)
579 BOOL WINAPI SetUserObjectInformationA( HANDLE handle, INT index, LPVOID info, DWORD len )
581 return SetUserObjectInformationW( handle, index, info, len );
585 /******************************************************************************
586 * SetUserObjectInformationW (USER32.@)
588 BOOL WINAPI SetUserObjectInformationW( HANDLE handle, INT index, LPVOID info, DWORD len )
591 const USEROBJECTFLAGS *obj_flags = info;
593 if (index != UOI_FLAGS || !info || len < sizeof(*obj_flags))
595 SetLastError( ERROR_INVALID_PARAMETER );
598 /* FIXME: inherit flag */
599 SERVER_START_REQ( set_user_object_info )
601 req->handle = handle;
602 req->flags = SET_USER_OBJECT_FLAGS;
603 req->obj_flags = obj_flags->dwFlags;
604 ret = !wine_server_call_err( req );
611 /***********************************************************************
612 * GetUserObjectSecurity (USER32.@)
614 BOOL WINAPI GetUserObjectSecurity( HANDLE handle, PSECURITY_INFORMATION info,
615 PSECURITY_DESCRIPTOR sid, DWORD len, LPDWORD needed )
617 FIXME( "(%p %p %p len=%d %p),stub!\n", handle, info, sid, len, needed );
621 /***********************************************************************
622 * SetUserObjectSecurity (USER32.@)
624 BOOL WINAPI SetUserObjectSecurity( HANDLE handle, PSECURITY_INFORMATION info,
625 PSECURITY_DESCRIPTOR sid )
627 FIXME( "(%p,%p,%p),stub!\n", handle, info, sid );