Fix segmentation fault caused by incorrect referencing of client audio
[wine] / dlls / user / misc.c
1 /*
2  * Misc USER functions
3  *
4  * Copyright 1995 Thomas Sandford
5  * Copyright 1997 Marcus Meissner
6  *
7  * This library is free software; you can redistribute it and/or
8  * modify it under the terms of the GNU Lesser General Public
9  * License as published by the Free Software Foundation; either
10  * version 2.1 of the License, or (at your option) any later version.
11  *
12  * This library is distributed in the hope that it will be useful,
13  * but WITHOUT ANY WARRANTY; without even the implied warranty of
14  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
15  * Lesser General Public License for more details.
16  *
17  * You should have received a copy of the GNU Lesser General Public
18  * License along with this library; if not, write to the Free Software
19  * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
20  */
21
22 #include <stdarg.h>
23
24 #include "windef.h"
25 #include "winbase.h"
26 #include "wingdi.h"
27 #include "winuser.h"
28 #include "winnls.h"
29
30 #include "wine/debug.h"
31
32 WINE_DEFAULT_DEBUG_CHANNEL(win);
33
34 /* callback to allow EnumDesktopsA to use EnumDesktopsW */
35 typedef struct {
36     DESKTOPENUMPROCA lpEnumFunc;
37     LPARAM lParam;
38 } ENUMDESKTOPS_LPARAM;
39
40 /* EnumDesktopsA passes this callback function to EnumDesktopsW.
41  * It simply converts the string to ASCII and calls the callback
42  * function provided by the original caller
43  */
44 static BOOL CALLBACK EnumDesktopProcWtoA(LPWSTR lpszDesktop, LPARAM lParam)
45 {
46     LPSTR buffer;
47     INT   len;
48     BOOL  ret;
49     ENUMDESKTOPS_LPARAM *data = (ENUMDESKTOPS_LPARAM *)lParam;
50
51     len = WideCharToMultiByte(CP_ACP, 0, lpszDesktop, -1, NULL, 0, NULL, NULL);
52     if (!(buffer = HeapAlloc( GetProcessHeap(), 0, len))) return FALSE;
53     WideCharToMultiByte(CP_ACP, 0, lpszDesktop, -1, buffer, len, NULL, NULL);
54
55     ret = data->lpEnumFunc(buffer, data->lParam);
56
57     HeapFree(GetProcessHeap(), 0, buffer);
58     return ret;
59 }
60
61 /**********************************************************************
62  * SetLastErrorEx [USER32.@]
63  *
64  * Sets the last-error code.
65  *
66  * RETURNS
67  *    None.
68  */
69 void WINAPI SetLastErrorEx(
70     DWORD error, /* [in] Per-thread error code */
71     DWORD type)  /* [in] Error type */
72 {
73     TRACE("(0x%08lx, 0x%08lx)\n", error,type);
74     switch(type) {
75         case 0:
76             break;
77         case SLE_ERROR:
78         case SLE_MINORERROR:
79         case SLE_WARNING:
80             /* Fall through for now */
81         default:
82             FIXME("(error=%08lx, type=%08lx): Unhandled type\n", error,type);
83             break;
84     }
85     SetLastError( error );
86 }
87
88 /******************************************************************************
89  * GetAltTabInfoA [USER32.@]
90  */
91 BOOL WINAPI GetAltTabInfoA(HWND hwnd, int iItem, PALTTABINFO pati, LPSTR pszItemText, UINT cchItemText)
92 {
93     FIXME("(%p, 0x%08x, %p, %p, 0x%08x)\n", hwnd, iItem, pati, pszItemText, cchItemText);
94     return FALSE;
95 }
96
97 /******************************************************************************
98  * GetAltTabInfoW [USER32.@]
99  */
100 BOOL WINAPI GetAltTabInfoW(HWND hwnd, int iItem, PALTTABINFO pati, LPWSTR pszItemText, UINT cchItemText)
101 {
102     FIXME("(%p, 0x%08x, %p, %p, 0x%08x)\n", hwnd, iItem, pati, pszItemText, cchItemText);
103     return FALSE;
104 }
105
106 /******************************************************************************
107  * GetProcessWindowStation [USER32.@]
108  *
109  * Returns handle of window station
110  *
111  * NOTES
112  *    Docs say the return value is HWINSTA
113  *
114  * RETURNS
115  *    Success: Handle to window station associated with calling process
116  *    Failure: NULL
117  */
118 HWINSTA WINAPI GetProcessWindowStation(void)
119 {
120     FIXME("(void): stub\n");
121     return (HWINSTA)1;
122 }
123
124
125 /******************************************************************************
126  * GetThreadDesktop [USER32.@]
127  *
128  * Returns handle to desktop
129  *
130  * PARAMS
131  *    dwThreadId [I] Thread identifier
132  *
133  * RETURNS
134  *    Success: Handle to desktop associated with specified thread
135  *    Failure: NULL
136  */
137 HDESK WINAPI GetThreadDesktop( DWORD dwThreadId )
138 {
139     FIXME("(%lx): stub\n",dwThreadId);
140     return (HDESK)1;
141 }
142
143
144 /******************************************************************************
145  * SetDebugErrorLevel [USER32.@]
146  * Sets the minimum error level for generating debugging events
147  *
148  * PARAMS
149  *    dwLevel [I] Debugging error level
150  */
151 VOID WINAPI SetDebugErrorLevel( DWORD dwLevel )
152 {
153     FIXME("(%ld): stub\n", dwLevel);
154 }
155
156
157 /******************************************************************************
158  *                    GetProcessDefaultLayout [USER32.@]
159  *
160  * Gets the default layout for parentless windows.
161  * Right now, just returns 0 (left-to-right).
162  *
163  * RETURNS
164  *    Success: Nonzero
165  *    Failure: Zero
166  *
167  * BUGS
168  *    No RTL
169  */
170 BOOL WINAPI GetProcessDefaultLayout( DWORD *pdwDefaultLayout )
171 {
172     if ( !pdwDefaultLayout ) {
173         SetLastError( ERROR_INVALID_PARAMETER );
174         return FALSE;
175      }
176     FIXME( "( %p ): No BiDi\n", pdwDefaultLayout );
177     *pdwDefaultLayout = 0;
178     return TRUE;
179 }
180
181
182 /******************************************************************************
183  *                    SetProcessDefaultLayout [USER32.@]
184  *
185  * Sets the default layout for parentless windows.
186  * Right now, only accepts 0 (left-to-right).
187  *
188  * RETURNS
189  *    Success: Nonzero
190  *    Failure: Zero
191  *
192  * BUGS
193  *    No RTL
194  */
195 BOOL WINAPI SetProcessDefaultLayout( DWORD dwDefaultLayout )
196 {
197     if ( dwDefaultLayout == 0 )
198         return TRUE;
199     FIXME( "( %08lx ): No BiDi\n", dwDefaultLayout );
200     SetLastError( ERROR_CALL_NOT_IMPLEMENTED );
201     return FALSE;
202 }
203
204
205 /***********************************************************************
206  *              CreateDesktopA (USER32.@)
207  */
208 HDESK WINAPI CreateDesktopA( LPSTR lpszDesktop,LPSTR lpszDevice,LPDEVMODEA pDevmode,
209                              DWORD dwFlags,DWORD dwDesiredAccess,LPSECURITY_ATTRIBUTES lpsa )
210 {
211     FIXME("(%s,%s,%p,0x%08lx,0x%08lx,%p),stub!\n", lpszDesktop,lpszDevice,pDevmode,
212           dwFlags,dwDesiredAccess,lpsa );
213     return (HDESK)0xcafedead;
214 }
215
216 /***********************************************************************
217  *              CreateDesktopW (USER32.@)
218  */
219 HDESK WINAPI CreateDesktopW( LPWSTR lpszDesktop,LPWSTR lpszDevice,LPDEVMODEW pDevmode,
220                              DWORD dwFlags,DWORD dwDesiredAccess,LPSECURITY_ATTRIBUTES lpsa)
221 {
222     FIXME("(%s,%s,%p,0x%08lx,0x%08lx,%p),stub!\n",
223           debugstr_w(lpszDesktop),debugstr_w(lpszDevice),pDevmode,
224           dwFlags,dwDesiredAccess,lpsa );
225     return (HDESK)0xcafedead;
226 }
227
228 /******************************************************************************
229  * OpenDesktopA [USER32.@]
230  *
231  *    Not supported on Win9x - returns NULL and calls SetLastError.
232  */
233 HDESK WINAPI OpenDesktopA( LPCSTR lpszDesktop, DWORD dwFlags,
234                                 BOOL fInherit, DWORD dwDesiredAccess )
235 {
236     FIXME("(%s,%lx,%i,%lx): stub\n",debugstr_a(lpszDesktop),dwFlags,
237           fInherit,dwDesiredAccess);
238
239     SetLastError(ERROR_CALL_NOT_IMPLEMENTED);
240     return 0;
241 }
242
243 /******************************************************************************
244  * OpenInputDesktop [USER32.@]
245  *
246  *    Not supported on Win9x - returns NULL and calls SetLastError.
247  */
248 HDESK WINAPI OpenInputDesktop( DWORD dwFlags, BOOL fInherit, ACCESS_MASK dwDesiredAccess )
249 {
250     FIXME("(%lx,%i,%lx): stub\n",dwFlags, fInherit,dwDesiredAccess);
251     SetLastError(ERROR_CALL_NOT_IMPLEMENTED);
252     return 0;
253 }
254
255 /***********************************************************************
256  *              CloseDesktop (USER32.@)
257  */
258 BOOL WINAPI CloseDesktop(HDESK hDesk)
259 {
260     FIXME("(%p)\n", hDesk);
261     return TRUE;
262 }
263
264 /******************************************************************************
265  *              EnumDesktopsA [USER32.@]
266  */
267 BOOL WINAPI EnumDesktopsA( HWINSTA hwinsta, DESKTOPENUMPROCA lpEnumFunc,
268                     LPARAM lParam )
269 {
270     ENUMDESKTOPS_LPARAM caller_data;
271
272     caller_data.lpEnumFunc = lpEnumFunc;
273     caller_data.lParam     = lParam;
274     
275     return EnumDesktopsW(hwinsta, EnumDesktopProcWtoA, (LPARAM) &caller_data);
276 }
277
278 /******************************************************************************
279  *              EnumDesktopsW [USER32.@]
280  */
281 BOOL WINAPI EnumDesktopsW( HWINSTA hwinsta, DESKTOPENUMPROCW lpEnumFunc,
282                     LPARAM lParam )
283 {
284     FIXME("%p,%p,%lx): stub\n",hwinsta,lpEnumFunc,lParam);
285     SetLastError(ERROR_CALL_NOT_IMPLEMENTED);
286     return FALSE;
287 }
288
289 /***********************************************************************
290  *              EnumDesktopWindows (USER32.@)
291  */
292 BOOL WINAPI EnumDesktopWindows( HDESK hDesktop, WNDENUMPROC lpfn, LPARAM lParam )
293 {
294   FIXME("(%p, %p, 0x%08lx), stub!\n", hDesktop, lpfn, lParam );
295   return TRUE;
296 }
297
298 /***********************************************************************
299  *              CreateWindowStationW (USER32.@)
300  */
301 HWINSTA WINAPI CreateWindowStationW( LPWSTR winstation,DWORD res1,DWORD desiredaccess,
302                                      LPSECURITY_ATTRIBUTES lpsa )
303 {
304     FIXME("(%s,0x%08lx,0x%08lx,%p),stub!\n",debugstr_w(winstation), res1,desiredaccess,lpsa );
305     return (HWINSTA)0xdeadcafe;
306 }
307
308 /***********************************************************************
309  *              CloseWindowStation (USER32.@)
310  */
311 BOOL WINAPI CloseWindowStation(HWINSTA hWinSta)
312 {
313     FIXME("(%p)\n", hWinSta);
314     return TRUE;
315 }
316
317 /***********************************************************************
318  *              SetWindowStationUser (USER32.@)
319  */
320 DWORD WINAPI SetWindowStationUser(DWORD x1,DWORD x2)
321 {
322     FIXME("(0x%08lx,0x%08lx),stub!\n",x1,x2);
323     return 1;
324 }
325
326 /***********************************************************************
327  *              SetProcessWindowStation (USER32.@)
328  */
329 BOOL WINAPI SetProcessWindowStation(HWINSTA hWinSta)
330 {
331     FIXME("(%p),stub!\n",hWinSta);
332     return TRUE;
333 }
334
335 /******************************************************************************
336  *              EnumWindowStationsA [USER32.@]
337  */
338 BOOL WINAPI EnumWindowStationsA( WINSTAENUMPROCA lpEnumFunc, LPARAM lParam)
339 {
340     FIXME("%p,%lx): stub\n",lpEnumFunc,lParam);
341     SetLastError(ERROR_CALL_NOT_IMPLEMENTED);
342     return FALSE;
343 }
344
345 /******************************************************************************
346  *              EnumWindowStationsW [USER32.@]
347  */
348 BOOL WINAPI EnumWindowStationsW( WINSTAENUMPROCW lpEnumFunc, LPARAM lParam)
349 {
350     FIXME("%p,%lx): stub\n",lpEnumFunc,lParam);
351     SetLastError(ERROR_CALL_NOT_IMPLEMENTED);
352     return FALSE;
353 }
354
355 /***********************************************************************
356  *              GetUserObjectInformationA (USER32.@)
357  */
358 BOOL WINAPI GetUserObjectInformationA( HANDLE hObj, INT nIndex, LPVOID pvInfo, DWORD nLength, LPDWORD lpnLen )
359 {
360     FIXME("(%p %i %p %ld %p),stub!\n", hObj, nIndex, pvInfo, nLength, lpnLen );
361     return TRUE;
362 }
363
364 /***********************************************************************
365  *              GetUserObjectInformationW (USER32.@)
366  */
367 BOOL WINAPI GetUserObjectInformationW( HANDLE hObj, INT nIndex, LPVOID pvInfo, DWORD nLength, LPDWORD lpnLen )
368 {
369     FIXME("(%p %i %p %ld %p),stub!\n", hObj, nIndex, pvInfo, nLength, lpnLen );
370     return TRUE;
371 }
372
373 /******************************************************************************
374  *              SetUserObjectInformationA   (USER32.@)
375  */
376 BOOL WINAPI SetUserObjectInformationA( HANDLE hObj, INT nIndex,
377                                        LPVOID pvInfo, DWORD nLength )
378 {
379     FIXME("(%p,%d,%p,%lx): stub\n",hObj,nIndex,pvInfo,nLength);
380     return TRUE;
381 }
382
383 /***********************************************************************
384  *              GetUserObjectSecurity (USER32.@)
385  */
386 BOOL WINAPI GetUserObjectSecurity(HANDLE hObj, PSECURITY_INFORMATION pSIRequested,
387                                   PSECURITY_DESCRIPTOR pSID, DWORD nLength, LPDWORD lpnLengthNeeded)
388 {
389     FIXME("(%p %p %p len=%ld %p),stub!\n",  hObj, pSIRequested, pSID, nLength, lpnLengthNeeded);
390     return TRUE;
391 }
392
393 /***********************************************************************
394  *              SetUserObjectSecurity (USER32.@)
395  */
396 BOOL WINAPI SetUserObjectSecurity( HANDLE hObj, PSECURITY_INFORMATION pSIRequested,
397                                    PSECURITY_DESCRIPTOR pSID )
398 {
399     FIXME("(%p,%p,%p),stub!\n",hObj,pSIRequested,pSID);
400     return TRUE;
401 }
402
403 /******************************************************************************
404  *              SetThreadDesktop   (USER32.@)
405  */
406 BOOL WINAPI SetThreadDesktop( HANDLE hDesktop )
407 {
408     FIXME("(%p): stub\n",hDesktop);
409     return TRUE;
410 }
411
412 /***********************************************************************
413  *              RegisterLogonProcess (USER32.@)
414  */
415 DWORD WINAPI RegisterLogonProcess(HANDLE hprocess,BOOL x)
416 {
417     FIXME("(%p,%d),stub!\n",hprocess,x);
418     return 1;
419 }
420
421 /***********************************************************************
422  *              SetLogonNotifyWindow (USER32.@)
423  */
424 DWORD WINAPI SetLogonNotifyWindow(HWINSTA hwinsta,HWND hwnd)
425 {
426     FIXME("(%p,%p),stub!\n",hwinsta,hwnd);
427     return 1;
428 }
429
430 /***********************************************************************
431  *              RegisterSystemThread (USER32.@)
432  */
433 void WINAPI RegisterSystemThread(DWORD flags, DWORD reserved)
434 {
435     FIXME("(%08lx, %08lx)\n", flags, reserved);
436 }
437
438 /***********************************************************************
439  *           RegisterShellHookWindow                    [USER32.@]
440  */
441 BOOL WINAPI RegisterShellHookWindow ( HWND hWnd )
442 {
443     FIXME("(%p): stub\n", hWnd);
444     return 0;
445 }
446
447
448 /***********************************************************************
449  *           DeregisterShellHookWindow                  [USER32.@]
450  */
451 HRESULT WINAPI DeregisterShellHookWindow ( DWORD u )
452 {
453     FIXME("0x%08lx stub\n",u);
454     return 0;
455
456 }
457
458
459 /***********************************************************************
460  *           RegisterTasklist                           [USER32.@]
461  */
462 DWORD WINAPI RegisterTasklist (DWORD x)
463 {
464     FIXME("0x%08lx\n",x);
465     return TRUE;
466 }
467
468
469 /***********************************************************************
470  *              RegisterDeviceNotificationA (USER32.@)
471  *
472  * See RegisterDeviceNotificationW.
473  */
474 HDEVNOTIFY WINAPI RegisterDeviceNotificationA(HANDLE hnd, LPVOID notifyfilter, DWORD flags)
475 {
476     FIXME("(hwnd=%p, filter=%p,flags=0x%08lx), STUB!\n", hnd,notifyfilter,flags );
477     return 0;
478 }
479
480 /***********************************************************************
481  *              RegisterDeviceNotificationW (USER32.@)
482  *
483  * Registers a window with the system so that it will receive
484  * notifications about a device.
485  *
486  * PARAMS
487  *     hRecepient           [I] Window or service status handle that
488  *                              will receive notifications.
489  *     pNotificationFilter  [I] DEV_BROADCAST_HDR followed by some
490  *                              type-specific data.
491  *     dwFlags              [I] See notes
492  *
493  * RETURNS
494  *
495  * A handle to the device notification.
496  *
497  * NOTES
498  *
499  * The dwFlags parameter can be one of two values:
500  *| DEVICE_NOTIFY_WINDOW_HANDLE  - hRecepient is a window handle
501  *| DEVICE_NOTIFY_SERVICE_HANDLE - hRecepient is a service status handle
502  */
503 HDEVNOTIFY WINAPI RegisterDeviceNotificationW(HANDLE hRecepient, LPVOID pNotificationFilter, DWORD dwFlags)
504 {
505     FIXME("(hwnd=%p, filter=%p,flags=0x%08lx), STUB!\n", hRecepient,pNotificationFilter,dwFlags );
506     return 0;
507 }
508
509 /***********************************************************************
510  *           GetAppCompatFlags   (USER32.@)
511  */
512 DWORD WINAPI GetAppCompatFlags( HTASK hTask )
513 {
514     FIXME("stub\n");
515     return 0;
516 }
517
518
519 /***********************************************************************
520  *           AlignRects   (USER32.@)
521  */
522 BOOL WINAPI AlignRects(LPRECT rect, DWORD b, DWORD c, DWORD d)
523 {
524     FIXME("(%p, %ld, %ld, %ld): stub\n", rect, b, c, d);
525     if (rect)
526         FIXME("rect: [[%ld, %ld], [%ld, %ld]]\n", rect->left, rect->top, rect->right, rect->bottom);
527     /* Calls OffsetRect */
528     return FALSE;
529 }
530
531
532 /***********************************************************************
533  *              LoadLocalFonts (USER32.@)
534  */
535 VOID WINAPI LoadLocalFonts(VOID)
536 {
537     /* are loaded. */
538     return;
539 }
540
541
542 /***********************************************************************
543  *              USER_489 (USER.489)
544  */
545 LONG WINAPI stub_USER_489(void) { FIXME("stub\n"); return 0; }
546
547 /***********************************************************************
548  *              USER_490 (USER.490)
549  */
550 LONG WINAPI stub_USER_490(void) { FIXME("stub\n"); return 0; }
551
552 /***********************************************************************
553  *              USER_492 (USER.492)
554  */
555 LONG WINAPI stub_USER_492(void) { FIXME("stub\n"); return 0; }
556
557 /***********************************************************************
558  *              USER_496 (USER.496)
559  */
560 LONG WINAPI stub_USER_496(void) { FIXME("stub\n"); return 0; }
561
562 /***********************************************************************
563  *              User32InitializeImmEntryTable
564  */
565 BOOL WINAPI User32InitializeImmEntryTable(LPVOID ptr)
566 {
567   FIXME("(%p): stub\n", ptr);
568   return TRUE;
569 }
570
571 /**********************************************************************
572  * WINNLSGetIMEHotkey [USER32.@]
573  *
574  */
575 UINT WINAPI WINNLSGetIMEHotkey(HWND hUnknown1)
576 {
577     FIXME("hUnknown1 %p: stub!\n", hUnknown1);
578     return 0; /* unknown */
579 }
580
581 /**********************************************************************
582  * WINNLSEnableIME [USER32.@]
583  *
584  */
585 BOOL WINAPI WINNLSEnableIME(HWND hUnknown1, BOOL bUnknown2)
586 {
587     FIXME("hUnknown1 %p bUnknown2 %d: stub!\n", hUnknown1, bUnknown2);
588     return TRUE; /* success (?) */
589 }
590
591 /**********************************************************************
592  * WINNLSGetEnableStatus [USER32.@]
593  *
594  */
595 BOOL WINAPI WINNLSGetEnableStatus(HWND hUnknown1)
596 {
597     FIXME("hUnknown1 %p: stub!\n", hUnknown1);
598     return TRUE; /* success (?) */
599 }
600
601 /**********************************************************************
602  * SendIMEMessageExA [USER32.@]
603  *
604  */
605 LRESULT WINAPI SendIMEMessageExA(HWND p1, LPARAM p2)
606 {
607   FIXME("(%p,%lx): stub\n", p1, p2);
608   SetLastError(ERROR_CALL_NOT_IMPLEMENTED);
609   return 0;
610 }
611
612 /**********************************************************************
613  * SendIMEMessageExW [USER32.@]
614  *
615  */
616 LRESULT WINAPI SendIMEMessageExW(HWND p1, LPARAM p2)
617 {
618   FIXME("(%p,%lx): stub\n", p1, p2);
619   SetLastError(ERROR_CALL_NOT_IMPLEMENTED);
620   return 0;
621 }