ddraw/tests: Use FAILED instead of !SUCCEEDED.
[wine/multimedia.git] / dlls / advapi32 / advapi.c
blob1be3a17b69099d66eaade68048f97f00ec734e3a
1 /*
2 * Win32 advapi functions
4 * Copyright 1995 Sven Verdoolaege
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
21 #include <errno.h>
22 #include <stdio.h>
23 #include <string.h>
24 #include <stdarg.h>
26 #include "windef.h"
27 #include "winbase.h"
28 #include "winnls.h"
29 #include "winreg.h"
30 #include "winternl.h"
31 #include "winerror.h"
32 #include "wincred.h"
34 #include "wine/library.h"
35 #include "wine/debug.h"
37 WINE_DEFAULT_DEBUG_CHANNEL(advapi);
39 /******************************************************************************
40 * GetUserNameA [ADVAPI32.@]
42 * Get the current user name.
44 * PARAMS
45 * lpszName [O] Destination for the user name.
46 * lpSize [I/O] Size of lpszName.
48 * RETURNS
49 * Success: The length of the user name, including terminating NUL.
50 * Failure: ERROR_MORE_DATA if *lpSize is too small.
52 BOOL WINAPI
53 GetUserNameA( LPSTR lpszName, LPDWORD lpSize )
55 WCHAR *buffer;
56 BOOL ret;
57 DWORD sizeW = *lpSize * 2;
59 if (!(buffer = HeapAlloc( GetProcessHeap(), 0, sizeW * sizeof(WCHAR) )))
61 SetLastError( ERROR_NOT_ENOUGH_MEMORY );
62 return FALSE;
64 ret = GetUserNameW( buffer, &sizeW );
65 if (ret)
67 if (!(*lpSize = WideCharToMultiByte( CP_ACP, 0, buffer, -1, lpszName, *lpSize, NULL, NULL )))
69 *lpSize = WideCharToMultiByte( CP_ACP, 0, buffer, -1, NULL, 0, NULL, NULL );
70 SetLastError( ERROR_MORE_DATA );
71 ret = FALSE;
74 else *lpSize = sizeW * 2;
75 HeapFree( GetProcessHeap(), 0, buffer );
76 return ret;
79 /******************************************************************************
80 * GetUserNameW [ADVAPI32.@]
82 * See GetUserNameA.
84 BOOL WINAPI
85 GetUserNameW( LPWSTR lpszName, LPDWORD lpSize )
87 const char *name = wine_get_user_name();
88 DWORD i, len = MultiByteToWideChar( CP_UNIXCP, 0, name, -1, NULL, 0 );
90 if (len > *lpSize)
92 SetLastError(ERROR_MORE_DATA);
93 *lpSize = len;
94 return FALSE;
97 *lpSize = len;
98 MultiByteToWideChar( CP_UNIXCP, 0, name, -1, lpszName, len );
100 /* Word uses the user name to create named mutexes and file mappings,
101 * and backslashes in the name cause the creation to fail.
103 for (i = 0; lpszName[i]; i++)
104 if (lpszName[i] == '\\' || lpszName[i] == '/') lpszName[i] = '_';
105 return TRUE;
108 /******************************************************************************
109 * GetCurrentHwProfileA [ADVAPI32.@]
111 * Get the current hardware profile.
113 * PARAMS
114 * pInfo [O] Destination for hardware profile information.
116 * RETURNS
117 * Success: TRUE. pInfo is updated with the hardware profile details.
118 * Failure: FALSE.
120 BOOL WINAPI GetCurrentHwProfileA(LPHW_PROFILE_INFOA pInfo)
122 FIXME("(%p) semi-stub\n", pInfo);
123 pInfo->dwDockInfo = DOCKINFO_DOCKED;
124 strcpy(pInfo->szHwProfileGuid,"{12340001-1234-1234-1234-123456789012}");
125 strcpy(pInfo->szHwProfileName,"Wine Profile");
126 return 1;
129 /******************************************************************************
130 * GetCurrentHwProfileW [ADVAPI32.@]
132 * See GetCurrentHwProfileA.
134 BOOL WINAPI GetCurrentHwProfileW(LPHW_PROFILE_INFOW pInfo)
136 FIXME("(%p)\n", pInfo);
137 return FALSE;
141 /**************************************************************************
142 * IsTextUnicode (ADVAPI32.@)
144 * Attempt to guess whether a text buffer is Unicode.
146 * PARAMS
147 * buf [I] Text buffer to test
148 * len [I] Length of buf
149 * flags [O] Destination for test results
151 * RETURNS
152 * TRUE if the buffer is likely Unicode, FALSE otherwise.
154 BOOL WINAPI IsTextUnicode( LPCVOID buf, INT len, LPINT flags )
156 return RtlIsTextUnicode( buf, len, flags );
160 /******************************************************************************
161 * AbortSystemShutdownA [ADVAPI32.@]
163 * Stop a system shutdown if one is in progress.
165 * PARAMS
166 * lpMachineName [I] Name of machine to not shutdown.
168 * RETURNS
169 * Success: TRUE.
170 * Failure: FALSE.
172 * NOTES
173 * The Wine implementation of this function is a harmless stub.
175 BOOL WINAPI AbortSystemShutdownA( LPSTR lpMachineName )
177 TRACE("stub %s (harmless)\n", lpMachineName);
178 return TRUE;
181 /******************************************************************************
182 * AbortSystemShutdownW [ADVAPI32.@]
184 * See AbortSystemShutdownA.
186 BOOL WINAPI AbortSystemShutdownW( LPWSTR lpMachineName )
188 TRACE("stub %s (harmless)\n", debugstr_w(lpMachineName));
189 return TRUE;
192 /******************************************************************************
193 * InitiateSystemShutdownExA [ADVAPI32.@]
195 * Initiate a shutdown or optionally restart the computer.
197 * PARAMS
198 * lpMachineName [I] Network name of machine to shutdown.
199 * lpMessage [I] Message displayed in shutdown dialog box.
200 * dwTimeout [I] Number of seconds dialog is displayed before shutdown.
201 * bForceAppsClosed [I] If TRUE, apps close without saving, else dialog is
202 * displayed requesting user to close apps.
203 * bRebootAfterShutdown [I] If TRUE, system reboots after restart, else the
204 * system flushes all caches to disk and clears
205 * the screen
206 * dwReason [I] Reason for shutting down. Must be a system shutdown reason
207 * code.
209 * RETURNS
210 * Success: TRUE
211 * Failure: FALSE
213 * NOTES
214 * if lpMachineName is NULL, the local computer is shutdown.
216 BOOL WINAPI InitiateSystemShutdownExA( LPSTR lpMachineName, LPSTR lpMessage,
217 DWORD dwTimeout, BOOL bForceAppsClosed, BOOL bRebootAfterShutdown,
218 DWORD dwReason)
220 FIXME("%s %s %d %d %d %d\n", debugstr_a(lpMachineName),
221 debugstr_a(lpMessage), dwTimeout, bForceAppsClosed,
222 bRebootAfterShutdown, dwReason);
223 return TRUE;
226 /******************************************************************************
227 * InitiateSystemShutdownExW [ADVAPI32.@]
229 * See InitiateSystemShutdownExA.
231 BOOL WINAPI InitiateSystemShutdownExW( LPWSTR lpMachineName, LPWSTR lpMessage,
232 DWORD dwTimeout, BOOL bForceAppsClosed, BOOL bRebootAfterShutdown,
233 DWORD dwReason)
235 FIXME("%s %s %d %d %d %d\n", debugstr_w(lpMachineName),
236 debugstr_w(lpMessage), dwTimeout, bForceAppsClosed,
237 bRebootAfterShutdown, dwReason);
238 return TRUE;
241 BOOL WINAPI InitiateSystemShutdownA( LPSTR lpMachineName, LPSTR lpMessage, DWORD dwTimeout,
242 BOOL bForceAppsClosed, BOOL bRebootAfterShutdown )
244 return InitiateSystemShutdownExA( lpMachineName, lpMessage, dwTimeout,
245 bForceAppsClosed, bRebootAfterShutdown,
246 SHTDN_REASON_MAJOR_LEGACY_API );
249 BOOL WINAPI InitiateSystemShutdownW( LPWSTR lpMachineName, LPWSTR lpMessage, DWORD dwTimeout,
250 BOOL bForceAppsClosed, BOOL bRebootAfterShutdown )
252 return InitiateSystemShutdownExW( lpMachineName, lpMessage, dwTimeout,
253 bForceAppsClosed, bRebootAfterShutdown,
254 SHTDN_REASON_MAJOR_LEGACY_API );
257 BOOL WINAPI LogonUserA( LPCSTR lpszUsername, LPCSTR lpszDomain, LPCSTR lpszPassword,
258 DWORD dwLogonType, DWORD dwLogonProvider, PHANDLE phToken )
260 FIXME("%s %s %p 0x%08x 0x%08x %p - stub\n", debugstr_a(lpszUsername),
261 debugstr_a(lpszDomain), lpszPassword, dwLogonType, dwLogonProvider, phToken);
263 return TRUE;
266 BOOL WINAPI LogonUserW( LPCWSTR lpszUsername, LPCWSTR lpszDomain, LPCWSTR lpszPassword,
267 DWORD dwLogonType, DWORD dwLogonProvider, PHANDLE phToken )
269 FIXME("%s %s %p 0x%08x 0x%08x %p - stub\n", debugstr_w(lpszUsername),
270 debugstr_w(lpszDomain), lpszPassword, dwLogonType, dwLogonProvider, phToken);
272 return TRUE;
275 typedef UINT (WINAPI *fnMsiProvideComponentFromDescriptor)(LPCWSTR,LPWSTR,DWORD*,DWORD*);
277 DWORD WINAPI CommandLineFromMsiDescriptor( WCHAR *szDescriptor,
278 WCHAR *szCommandLine, DWORD *pcchCommandLine )
280 static const WCHAR szMsi[] = { 'm','s','i',0 };
281 fnMsiProvideComponentFromDescriptor mpcfd;
282 HMODULE hmsi;
283 UINT r = ERROR_CALL_NOT_IMPLEMENTED;
285 TRACE("%s %p %p\n", debugstr_w(szDescriptor), szCommandLine, pcchCommandLine);
287 hmsi = LoadLibraryW( szMsi );
288 if (!hmsi)
289 return r;
290 mpcfd = (fnMsiProvideComponentFromDescriptor)GetProcAddress( hmsi,
291 "MsiProvideComponentFromDescriptorW" );
292 if (mpcfd)
293 r = mpcfd( szDescriptor, szCommandLine, pcchCommandLine, NULL );
294 FreeLibrary( hmsi );
295 return r;