user32: Move *RegisterDeviceNotification*() to input.c.
[wine.git] / dlls / kernelbase / main.c
blobf1edf8614e7c7c1a60f91cb5f362dd2519378d5e
1 /*
2 * Copyright 2016 Michael Müller
3 * Copyright 2017 Andrey Gusev
5 * This library is free software; you can redistribute it and/or
6 * modify it under the terms of the GNU Lesser General Public
7 * License as published by the Free Software Foundation; either
8 * version 2.1 of the License, or (at your option) any later version.
10 * This library is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13 * Lesser General Public License for more details.
15 * You should have received a copy of the GNU Lesser General Public
16 * License along with this library; if not, write to the Free Software
17 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA
20 #define COBJMACROS
22 #include "ntstatus.h"
23 #define WIN32_NO_STATUS
24 #include "windows.h"
25 #include "appmodel.h"
26 #include "shlwapi.h"
27 #include "perflib.h"
28 #include "winternl.h"
30 #include "wine/debug.h"
31 #include "kernelbase.h"
32 #include "wine/heap.h"
34 WINE_DEFAULT_DEBUG_CHANNEL(kernelbase);
37 BOOL is_wow64 = FALSE;
39 /***********************************************************************
40 * DllMain
42 BOOL WINAPI DllMain( HINSTANCE hinst, DWORD reason, LPVOID reserved )
44 if (reason == DLL_PROCESS_ATTACH)
46 DisableThreadLibraryCalls( hinst );
47 IsWow64Process( GetCurrentProcess(), &is_wow64 );
48 init_locale();
49 init_startup_info( NtCurrentTeb()->Peb->ProcessParameters );
51 return TRUE;
55 /*************************************************************
56 * DllMainCRTStartup
58 BOOL WINAPI DllMainCRTStartup( HANDLE inst, DWORD reason, LPVOID reserved )
60 return DllMain( inst, reason, reserved );
64 /***********************************************************************
65 * AppPolicyGetProcessTerminationMethod (KERNELBASE.@)
67 LONG WINAPI AppPolicyGetProcessTerminationMethod(HANDLE token, AppPolicyProcessTerminationMethod *policy)
69 FIXME("%p, %p\n", token, policy);
71 if(policy)
72 *policy = AppPolicyProcessTerminationMethod_ExitProcess;
74 return ERROR_SUCCESS;
77 /***********************************************************************
78 * AppPolicyGetThreadInitializationType (KERNELBASE.@)
80 LONG WINAPI AppPolicyGetThreadInitializationType(HANDLE token, AppPolicyThreadInitializationType *policy)
82 FIXME("%p, %p\n", token, policy);
84 if(policy)
85 *policy = AppPolicyThreadInitializationType_None;
87 return ERROR_SUCCESS;
90 /***********************************************************************
91 * AppPolicyGetShowDeveloperDiagnostic (KERNELBASE.@)
93 LONG WINAPI AppPolicyGetShowDeveloperDiagnostic(HANDLE token, AppPolicyShowDeveloperDiagnostic *policy)
95 FIXME("%p, %p\n", token, policy);
97 if(policy)
98 *policy = AppPolicyShowDeveloperDiagnostic_ShowUI;
100 return ERROR_SUCCESS;
103 /***********************************************************************
104 * AppPolicyGetWindowingModel (KERNELBASE.@)
106 LONG WINAPI AppPolicyGetWindowingModel(HANDLE token, AppPolicyWindowingModel *policy)
108 FIXME("%p, %p\n", token, policy);
110 if(policy)
111 *policy = AppPolicyWindowingModel_ClassicDesktop;
113 return ERROR_SUCCESS;
116 /***********************************************************************
117 * PerfCreateInstance (KERNELBASE.@)
119 PPERF_COUNTERSET_INSTANCE WINAPI PerfCreateInstance(HANDLE handle, LPCGUID guid,
120 const WCHAR *name, ULONG id)
122 FIXME("%p %s %s %u: stub\n", handle, debugstr_guid(guid), debugstr_w(name), id);
123 return NULL;
126 /***********************************************************************
127 * PerfDeleteInstance (KERNELBASE.@)
129 ULONG WINAPI PerfDeleteInstance(HANDLE provider, PPERF_COUNTERSET_INSTANCE block)
131 FIXME("%p %p: stub\n", provider, block);
132 return ERROR_CALL_NOT_IMPLEMENTED;
135 /***********************************************************************
136 * PerfSetCounterSetInfo (KERNELBASE.@)
138 ULONG WINAPI PerfSetCounterSetInfo(HANDLE handle, PPERF_COUNTERSET_INFO template, ULONG size)
140 FIXME("%p %p %u: stub\n", handle, template, size);
141 return ERROR_CALL_NOT_IMPLEMENTED;
144 /***********************************************************************
145 * PerfSetCounterRefValue (KERNELBASE.@)
147 ULONG WINAPI PerfSetCounterRefValue(HANDLE provider, PPERF_COUNTERSET_INSTANCE instance,
148 ULONG counterid, void *address)
150 FIXME("%p %p %u %p: stub\n", provider, instance, counterid, address);
151 return ERROR_CALL_NOT_IMPLEMENTED;
154 /***********************************************************************
155 * PerfStartProvider (KERNELBASE.@)
157 ULONG WINAPI PerfStartProvider(GUID *guid, PERFLIBREQUEST callback, HANDLE *provider)
159 FIXME("%s %p %p: stub\n", debugstr_guid(guid), callback, provider);
160 return ERROR_CALL_NOT_IMPLEMENTED;
163 /***********************************************************************
164 * PerfStartProviderEx (KERNELBASE.@)
166 ULONG WINAPI PerfStartProviderEx(GUID *guid, PPERF_PROVIDER_CONTEXT context, HANDLE *provider)
168 FIXME("%s %p %p: stub\n", debugstr_guid(guid), context, provider);
169 return ERROR_CALL_NOT_IMPLEMENTED;
172 /***********************************************************************
173 * PerfStopProvider (KERNELBASE.@)
175 ULONG WINAPI PerfStopProvider(HANDLE handle)
177 FIXME("%p: stub\n", handle);
178 return ERROR_CALL_NOT_IMPLEMENTED;
181 /***********************************************************************
182 * QuirkIsEnabled (KERNELBASE.@)
184 BOOL WINAPI QuirkIsEnabled(void *arg)
186 FIXME("(%p): stub\n", arg);
187 return FALSE;
190 /***********************************************************************
191 * QuirkIsEnabled3 (KERNELBASE.@)
193 BOOL WINAPI QuirkIsEnabled3(void *unk1, void *unk2)
195 static int once;
197 if (!once++)
198 FIXME("(%p, %p) stub!\n", unk1, unk2);
200 return FALSE;
203 HRESULT WINAPI QISearch(void *base, const QITAB *table, REFIID riid, void **obj)
205 const QITAB *ptr;
206 IUnknown *unk;
208 TRACE("%p, %p, %s, %p\n", base, table, debugstr_guid(riid), obj);
210 if (!obj)
211 return E_POINTER;
213 for (ptr = table; ptr->piid; ++ptr)
215 TRACE("trying (offset %d) %s\n", ptr->dwOffset, debugstr_guid(ptr->piid));
216 if (IsEqualIID(riid, ptr->piid))
218 unk = (IUnknown *)((BYTE *)base + ptr->dwOffset);
219 TRACE("matched, returning (%p)\n", unk);
220 *obj = unk;
221 IUnknown_AddRef(unk);
222 return S_OK;
226 if (IsEqualIID(riid, &IID_IUnknown))
228 unk = (IUnknown *)((BYTE *)base + table->dwOffset);
229 TRACE("returning first for IUnknown (%p)\n", unk);
230 *obj = unk;
231 IUnknown_AddRef(unk);
232 return S_OK;
235 WARN("Not found %s.\n", debugstr_guid(riid));
236 *obj = NULL;
237 return E_NOINTERFACE;
240 HRESULT WINAPI GetAcceptLanguagesA(LPSTR langbuf, DWORD *buflen)
242 DWORD buflenW, convlen;
243 WCHAR *langbufW;
244 HRESULT hr;
246 TRACE("%p, %p, *%p: %d\n", langbuf, buflen, buflen, buflen ? *buflen : -1);
248 if (!langbuf || !buflen || !*buflen)
249 return E_FAIL;
251 buflenW = *buflen;
252 langbufW = heap_alloc(sizeof(WCHAR) * buflenW);
253 hr = GetAcceptLanguagesW(langbufW, &buflenW);
255 if (hr == S_OK)
257 convlen = WideCharToMultiByte(CP_ACP, 0, langbufW, -1, langbuf, *buflen, NULL, NULL);
258 convlen--; /* do not count the terminating 0 */
260 else /* copy partial string anyway */
262 convlen = WideCharToMultiByte(CP_ACP, 0, langbufW, *buflen, langbuf, *buflen, NULL, NULL);
263 if (convlen < *buflen)
265 langbuf[convlen] = 0;
266 convlen--; /* do not count the terminating 0 */
268 else
270 convlen = *buflen;
273 *buflen = buflenW ? convlen : 0;
275 heap_free(langbufW);
276 return hr;
279 static HRESULT lcid_to_rfc1766(LCID lcid, WCHAR *rfc1766, INT len)
281 WCHAR buffer[6 /* MAX_RFC1766_NAME */];
282 INT n = GetLocaleInfoW(lcid, LOCALE_SISO639LANGNAME, buffer, ARRAY_SIZE(buffer));
283 INT i;
285 if (n)
287 i = PRIMARYLANGID(lcid);
288 if ((((i == LANG_ENGLISH) || (i == LANG_CHINESE) || (i == LANG_ARABIC)) &&
289 (SUBLANGID(lcid) == SUBLANG_DEFAULT)) ||
290 (SUBLANGID(lcid) > SUBLANG_DEFAULT)) {
292 buffer[n - 1] = '-';
293 i = GetLocaleInfoW(lcid, LOCALE_SISO3166CTRYNAME, buffer + n, ARRAY_SIZE(buffer) - n);
294 if (!i)
295 buffer[n - 1] = '\0';
297 else
298 i = 0;
300 LCMapStringW(LOCALE_USER_DEFAULT, LCMAP_LOWERCASE, buffer, n + i, rfc1766, len);
301 return ((n + i) > len) ? E_INVALIDARG : S_OK;
303 return E_FAIL;
306 HRESULT WINAPI GetAcceptLanguagesW(WCHAR *langbuf, DWORD *buflen)
308 DWORD mystrlen, mytype;
309 WCHAR *mystr;
310 LCID mylcid;
311 HKEY mykey;
312 LONG lres;
313 DWORD len;
315 TRACE("%p, %p, *%p: %d\n", langbuf, buflen, buflen, buflen ? *buflen : -1);
317 if (!langbuf || !buflen || !*buflen)
318 return E_FAIL;
320 mystrlen = (*buflen > 20) ? *buflen : 20 ;
321 len = mystrlen * sizeof(WCHAR);
322 mystr = heap_alloc(len);
323 mystr[0] = 0;
324 RegOpenKeyExW(HKEY_CURRENT_USER, L"Software\\Microsoft\\Internet Explorer\\International",
325 0, KEY_QUERY_VALUE, &mykey);
326 lres = RegQueryValueExW(mykey, L"AcceptLanguage", 0, &mytype, (PBYTE)mystr, &len);
327 RegCloseKey(mykey);
328 len = lstrlenW(mystr);
330 if (!lres && (*buflen > len))
332 lstrcpyW(langbuf, mystr);
333 *buflen = len;
334 heap_free(mystr);
335 return S_OK;
338 /* Did not find a value in the registry or the user buffer is too small */
339 mylcid = GetUserDefaultLCID();
340 lcid_to_rfc1766(mylcid, mystr, mystrlen);
341 len = lstrlenW(mystr);
343 memcpy(langbuf, mystr, min(*buflen, len + 1)*sizeof(WCHAR));
344 heap_free(mystr);
346 if (*buflen > len)
348 *buflen = len;
349 return S_OK;
352 *buflen = 0;
353 return E_NOT_SUFFICIENT_BUFFER;