Allow the user to move managed windows by dragging on HTCAPTION
[wine] / dlls / advapi32 / advapi.c
1 /*
2  * Win32 advapi functions
3  *
4  * Copyright 1995 Sven Verdoolaege
5  *
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.
10  *
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.
15  *
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., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
19  */
20
21 #include "config.h"
22 #include "wine/port.h"
23
24 #include <errno.h>
25 #include <stdio.h>
26 #include <string.h>
27 #include <stdarg.h>
28
29 #include "windef.h"
30 #include "winbase.h"
31 #include "winnls.h"
32 #include "winreg.h"
33 #include "winerror.h"
34
35 #include "wine/library.h"
36 #include "wine/debug.h"
37
38 WINE_DEFAULT_DEBUG_CHANNEL(advapi);
39
40 /******************************************************************************
41  * GetUserNameA [ADVAPI32.@]
42  *
43  * Get the current user name.
44  *
45  * PARAMS
46  *  lpszName [O]   Destination for the user name.
47  *  lpSize   [I/O] Size of lpszName.
48  *
49  * RETURNS
50  *  Success: The length of the user name, including terminating NUL.
51  *  Failure: ERROR_MORE_DATA if *lpSize is too small.
52  */
53 BOOL WINAPI
54 GetUserNameA( LPSTR lpszName, LPDWORD lpSize )
55 {
56     WCHAR *buffer;
57     BOOL ret;
58     DWORD sizeW = *lpSize * 2;
59
60     if (!(buffer = HeapAlloc( GetProcessHeap(), 0, sizeW * sizeof(WCHAR) )))
61     {
62         SetLastError( ERROR_NOT_ENOUGH_MEMORY );
63         return FALSE;
64     }
65     ret = GetUserNameW( buffer, &sizeW );
66     if (ret)
67     {
68         if (!(*lpSize = WideCharToMultiByte( CP_ACP, 0, buffer, -1, lpszName, *lpSize, NULL, NULL )))
69         {
70             *lpSize = WideCharToMultiByte( CP_ACP, 0, buffer, -1, NULL, 0, NULL, NULL );
71             SetLastError( ERROR_MORE_DATA );
72             ret = FALSE;
73         }
74     }
75     else *lpSize = sizeW * 2;
76     HeapFree( GetProcessHeap(), 0, buffer );
77     return ret;
78 }
79
80 /******************************************************************************
81  * GetUserNameW [ADVAPI32.@]
82  *
83  * See GetUserNameA.
84  */
85 BOOL WINAPI
86 GetUserNameW( LPWSTR lpszName, LPDWORD lpSize )
87 {
88     const char *name = wine_get_user_name();
89     DWORD len = MultiByteToWideChar( CP_UNIXCP, 0, name, -1, NULL, 0 );
90
91     if (len > *lpSize)
92     {
93         SetLastError(ERROR_MORE_DATA);
94         *lpSize = len;
95         return FALSE;
96     }
97
98     *lpSize = len;
99     MultiByteToWideChar( CP_UNIXCP, 0, name, -1, lpszName, len );
100     return TRUE;
101 }
102
103 /******************************************************************************
104  * GetCurrentHwProfileA [ADVAPI32.@]
105  *
106  * Get the current hardware profile.
107  *
108  * PARAMS
109  *  pInfo [O] Destination for hardware profile information.
110  *
111  * RETURNS
112  *  Success: TRUE. pInfo is updated with the hardware profile details.
113  *  Failure: FALSE.
114  */
115 BOOL WINAPI GetCurrentHwProfileA(LPHW_PROFILE_INFOA pInfo)
116 {
117         FIXME("(%p) semi-stub\n", pInfo);
118         pInfo->dwDockInfo = DOCKINFO_DOCKED;
119         strcpy(pInfo->szHwProfileGuid,"{12340001-1234-1234-1234-1233456789012}");
120         strcpy(pInfo->szHwProfileName,"Wine Profile");
121         return 1;
122 }
123
124 /******************************************************************************
125  * AbortSystemShutdownA [ADVAPI32.@]
126  *
127  * Stop a system shutdown if one is in progress.
128  *
129  * PARAMS
130  *  lpMachineName [I] Name of machine to not shutdown.
131  *
132  * RETURNS
133  *  Success: TRUE.
134  *  Failure: FALSE.
135  *
136  * NOTES
137  *  The Wine implementation of this function is a harmless stub.
138  */
139 BOOL WINAPI AbortSystemShutdownA( LPSTR lpMachineName )
140 {
141     TRACE("stub %s (harmless)\n", lpMachineName);
142     return TRUE;
143 }
144
145 /******************************************************************************
146  * AbortSystemShutdownW [ADVAPI32.@]
147  *
148  * See AbortSystemShutdownA.
149  */
150 BOOL WINAPI AbortSystemShutdownW( LPWSTR lpMachineName )
151 {
152     TRACE("stub %s (harmless)\n", debugstr_w(lpMachineName));
153     return TRUE;
154 }
155
156 /******************************************************************************
157  * InitiateSystemShutdownExA [ADVAPI32.@]
158  *
159  * Initiate a shutdown or optionally restart the computer.
160  *
161  * PARAMS
162  *  lpMachineName    [I] Network name of machine to shutdown.
163  *  lpMessage        [I] Message displayed in shutdown dialog box.
164  *  dwTimeout        [I] Number of seconds dialog is displayed before shutdown.
165  *  bForceAppsClosed [I] If TRUE, apps close without saving, else dialog is
166  *                       displayed requesting user to close apps.
167  *  bRebootAfterShutdown [I] If TRUE, system reboots after restart, else the
168  *                           system flushes all caches to disk and clears
169  *                           the screen
170  *  dwReason [I] Reason for shutting down.  Must be a system shutdown reason
171  *               code.
172  *
173  *  RETURNS
174  *   Success: TRUE
175  *   Failure: FALSE
176  *
177  *  NOTES
178  *   if lpMachineName is NULL, the local computer is shutdown.
179  */
180 BOOL WINAPI InitiateSystemShutdownExA( LPSTR lpMachineName, LPSTR lpMessage,
181          DWORD dwTimeout, BOOL bForceAppsClosed, BOOL bRebootAfterShutdown,
182          DWORD dwReason)
183 {
184      FIXME("%s %s %ld %d %d %ld\n", debugstr_a(lpMachineName),
185             debugstr_a(lpMessage), dwTimeout, bForceAppsClosed,
186             bRebootAfterShutdown, dwReason);
187      return TRUE;
188
189
190 /******************************************************************************
191  * InitiateSystemShutdownExW [ADVAPI32.@]
192  *
193  * see InitiateSystemShutdownExA
194  */
195 BOOL WINAPI InitiateSystemShutdownExW( LPWSTR lpMachineName, LPWSTR lpMessage,
196          DWORD dwTimeout, BOOL bForceAppsClosed, BOOL bRebootAfterShutdown,
197          DWORD dwReason)
198 {
199      FIXME("%s %s %ld %d %d %ld\n", debugstr_w(lpMachineName),
200             debugstr_w(lpMessage), dwTimeout, bForceAppsClosed,
201             bRebootAfterShutdown, dwReason);
202      return TRUE;
203
204
205 DWORD WINAPI CommandLineFromMsiDescriptor(WCHAR *Descriptor, WCHAR *CommandLine,
206  DWORD *CommandLineLength)
207 {
208     FIXME("stub (%s)\n", debugstr_w(Descriptor));
209     return ERROR_CALL_NOT_IMPLEMENTED;
210 }