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 HDESK open_winstation_desktop( HWINSTA hwinsta, LPCWSTR name, DWORD flags, BOOL inherit, ACCESS_MASK access )
323 DWORD len = name ? strlenW(name) : 0;
326 SetLastError( ERROR_FILENAME_EXCED_RANGE );
329 SERVER_START_REQ( open_desktop )
331 req->winsta = hwinsta;
333 req->access = access;
334 req->attributes = OBJ_CASE_INSENSITIVE | (inherit ? OBJ_INHERIT : 0);
335 wine_server_add_data( req, name, len * sizeof(WCHAR) );
336 if (!wine_server_call( req )) ret = reply->handle;
343 /******************************************************************************
344 * OpenDesktopW (USER32.@)
346 HDESK WINAPI OpenDesktopW( LPCWSTR name, DWORD flags, BOOL inherit, ACCESS_MASK access )
348 return open_winstation_desktop( NULL, name, flags, inherit, access );
352 /***********************************************************************
353 * CloseDesktop (USER32.@)
355 BOOL WINAPI CloseDesktop( HDESK handle )
358 SERVER_START_REQ( close_desktop )
360 req->handle = handle;
361 ret = !wine_server_call_err( req );
368 /******************************************************************************
369 * GetThreadDesktop (USER32.@)
371 HDESK WINAPI GetThreadDesktop( DWORD thread )
375 SERVER_START_REQ( get_thread_desktop )
378 if (!wine_server_call_err( req )) ret = reply->handle;
385 /******************************************************************************
386 * SetThreadDesktop (USER32.@)
388 BOOL WINAPI SetThreadDesktop( HDESK handle )
392 SERVER_START_REQ( set_thread_desktop )
394 req->handle = handle;
395 ret = !wine_server_call_err( req );
398 if (ret) /* reset the desktop windows */
400 struct user_thread_info *thread_info = get_user_thread_info();
401 thread_info->top_window = 0;
402 thread_info->msg_window = 0;
408 /******************************************************************************
409 * EnumDesktopsA (USER32.@)
411 BOOL WINAPI EnumDesktopsA( HWINSTA winsta, DESKTOPENUMPROCA func, LPARAM lparam )
413 struct enum_proc_lparam data;
415 data.lparam = lparam;
416 return EnumDesktopsW( winsta, enum_names_WtoA, (LPARAM)&data );
420 /******************************************************************************
421 * EnumDesktopsW (USER32.@)
423 BOOL WINAPI EnumDesktopsW( HWINSTA winsta, DESKTOPENUMPROCW func, LPARAM lparam )
425 unsigned int index = 0;
426 WCHAR name[MAX_PATH];
431 winsta = GetProcessWindowStation();
435 SERVER_START_REQ( enum_desktop )
437 req->winstation = winsta;
439 wine_server_set_reply( req, name, sizeof(name) - sizeof(WCHAR) );
440 status = wine_server_call( req );
441 name[wine_server_reply_size(reply)/sizeof(WCHAR)] = 0;
445 if (status == STATUS_NO_MORE_ENTRIES)
449 SetLastError( RtlNtStatusToDosError( status ) );
452 ret = func(name, lparam);
458 /******************************************************************************
459 * OpenInputDesktop (USER32.@)
461 HDESK WINAPI OpenInputDesktop( DWORD flags, BOOL inherit, ACCESS_MASK access )
463 FIXME( "(%x,%i,%x): stub\n", flags, inherit, access );
464 SetLastError( ERROR_CALL_NOT_IMPLEMENTED );
469 /***********************************************************************
470 * GetUserObjectInformationA (USER32.@)
472 BOOL WINAPI GetUserObjectInformationA( HANDLE handle, INT index, LPVOID info, DWORD len, LPDWORD needed )
474 /* check for information types returning strings */
475 if (index == UOI_TYPE || index == UOI_NAME)
477 WCHAR buffer[MAX_PATH];
480 if (!GetUserObjectInformationW( handle, index, buffer, sizeof(buffer), NULL )) return FALSE;
481 lenA = WideCharToMultiByte( CP_ACP, 0, buffer, -1, NULL, 0, NULL, NULL );
482 if (needed) *needed = lenA;
485 SetLastError( ERROR_MORE_DATA );
488 if (info) WideCharToMultiByte( CP_ACP, 0, buffer, -1, info, len, NULL, NULL );
491 return GetUserObjectInformationW( handle, index, info, len, needed );
495 /***********************************************************************
496 * GetUserObjectInformationW (USER32.@)
498 BOOL WINAPI GetUserObjectInformationW( HANDLE handle, INT index, LPVOID info, DWORD len, LPDWORD needed )
500 static const WCHAR desktopW[] = { 'D','e','s','k','t','o','p',0 };
501 static const WCHAR winstationW[] = { 'W','i','n','d','o','w','S','t','a','t','i','o','n',0 };
508 USEROBJECTFLAGS *obj_flags = info;
509 if (needed) *needed = sizeof(*obj_flags);
510 if (len < sizeof(*obj_flags))
512 SetLastError( ERROR_BUFFER_OVERFLOW );
515 SERVER_START_REQ( set_user_object_info )
517 req->handle = handle;
519 ret = !wine_server_call_err( req );
522 /* FIXME: inherit flag */
523 obj_flags->dwFlags = reply->old_obj_flags;
531 SERVER_START_REQ( set_user_object_info )
533 req->handle = handle;
535 ret = !wine_server_call_err( req );
538 size_t size = reply->is_desktop ? sizeof(desktopW) : sizeof(winstationW);
539 if (needed) *needed = size;
542 SetLastError( ERROR_MORE_DATA );
545 else memcpy( info, reply->is_desktop ? desktopW : winstationW, size );
553 WCHAR buffer[MAX_PATH];
554 SERVER_START_REQ( set_user_object_info )
556 req->handle = handle;
558 wine_server_set_reply( req, buffer, sizeof(buffer) - sizeof(WCHAR) );
559 ret = !wine_server_call_err( req );
562 size_t size = wine_server_reply_size( reply );
563 buffer[size / sizeof(WCHAR)] = 0;
564 size += sizeof(WCHAR);
565 if (needed) *needed = size;
568 SetLastError( ERROR_MORE_DATA );
571 else memcpy( info, buffer, size );
579 FIXME( "not supported index %d\n", index );
582 SetLastError( ERROR_INVALID_PARAMETER );
588 /******************************************************************************
589 * SetUserObjectInformationA (USER32.@)
591 BOOL WINAPI SetUserObjectInformationA( HANDLE handle, INT index, LPVOID info, DWORD len )
593 return SetUserObjectInformationW( handle, index, info, len );
597 /******************************************************************************
598 * SetUserObjectInformationW (USER32.@)
600 BOOL WINAPI SetUserObjectInformationW( HANDLE handle, INT index, LPVOID info, DWORD len )
603 const USEROBJECTFLAGS *obj_flags = info;
605 if (index != UOI_FLAGS || !info || len < sizeof(*obj_flags))
607 SetLastError( ERROR_INVALID_PARAMETER );
610 /* FIXME: inherit flag */
611 SERVER_START_REQ( set_user_object_info )
613 req->handle = handle;
614 req->flags = SET_USER_OBJECT_FLAGS;
615 req->obj_flags = obj_flags->dwFlags;
616 ret = !wine_server_call_err( req );
623 /***********************************************************************
624 * GetUserObjectSecurity (USER32.@)
626 BOOL WINAPI GetUserObjectSecurity( HANDLE handle, PSECURITY_INFORMATION info,
627 PSECURITY_DESCRIPTOR sid, DWORD len, LPDWORD needed )
629 FIXME( "(%p %p %p len=%d %p),stub!\n", handle, info, sid, len, needed );
633 /***********************************************************************
634 * SetUserObjectSecurity (USER32.@)
636 BOOL WINAPI SetUserObjectSecurity( HANDLE handle, PSECURITY_INFORMATION info,
637 PSECURITY_DESCRIPTOR sid )
639 FIXME( "(%p,%p,%p),stub!\n", handle, info, sid );