user32/tests: Add some optional keystrokes for AltGr key.
[wine/multimedia.git] / dlls / mscoree / mscoree_main.c
blob386f4f7670749d17783100570f9c43b2dda5c434
1 /*
2 * Implementation of mscoree.dll
3 * Microsoft Component Object Runtime Execution Engine
5 * Copyright 2006 Paul Chitescu
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.
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.
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., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA
22 #include <stdarg.h>
24 #include "windef.h"
25 #include "winbase.h"
26 #include "winuser.h"
27 #include "winreg.h"
28 #include "ole2.h"
30 #include "initguid.h"
31 #include "cor.h"
32 #include "mscoree.h"
33 #include "mscoree_private.h"
35 #include "wine/debug.h"
37 WINE_DEFAULT_DEBUG_CHANNEL( mscoree );
39 static LPWSTR get_mono_exe(void)
41 static const WCHAR mono_exe[] = {'b','i','n','\\','m','o','n','o','.','e','x','e',' ',0};
42 static const WCHAR mono_key[] = {'S','o','f','t','w','a','r','e','\\','N','o','v','e','l','l','\\','M','o','n','o',0};
43 static const WCHAR defaul_clr[] = {'D','e','f','a','u','l','t','C','L','R',0};
44 static const WCHAR install_root[] = {'S','d','k','I','n','s','t','a','l','l','R','o','o','t',0};
45 static const WCHAR slash[] = {'\\',0};
47 WCHAR version[64], version_key[MAX_PATH], root[MAX_PATH], *ret;
48 DWORD len, size;
49 HKEY key;
51 if (RegOpenKeyExW(HKEY_LOCAL_MACHINE, mono_key, 0, KEY_READ, &key))
52 return NULL;
54 len = sizeof(version);
55 if (RegQueryValueExW(key, defaul_clr, 0, NULL, (LPBYTE)version, &len))
57 RegCloseKey(key);
58 return NULL;
60 RegCloseKey(key);
62 lstrcpyW(version_key, mono_key);
63 lstrcatW(version_key, slash);
64 lstrcatW(version_key, version);
66 if (RegOpenKeyExW(HKEY_LOCAL_MACHINE, version_key, 0, KEY_READ, &key))
67 return NULL;
69 len = sizeof(root);
70 if (RegQueryValueExW(key, install_root, 0, NULL, (LPBYTE)root, &len))
72 RegCloseKey(key);
73 return NULL;
75 RegCloseKey(key);
77 size = len + sizeof(slash) + sizeof(mono_exe);
78 if (!(ret = HeapAlloc(GetProcessHeap(), 0, size))) return NULL;
80 lstrcpyW(ret, root);
81 lstrcatW(ret, slash);
82 lstrcatW(ret, mono_exe);
84 return ret;
87 HRESULT WINAPI CorBindToRuntimeHost(LPCWSTR pwszVersion, LPCWSTR pwszBuildFlavor,
88 LPCWSTR pwszHostConfigFile, VOID *pReserved,
89 DWORD startupFlags, REFCLSID rclsid,
90 REFIID riid, LPVOID *ppv)
92 WCHAR *mono_exe;
94 FIXME("(%s, %s, %s, %p, %d, %p, %p, %p): semi-stub!\n", debugstr_w(pwszVersion),
95 debugstr_w(pwszBuildFlavor), debugstr_w(pwszHostConfigFile), pReserved,
96 startupFlags, rclsid, riid, ppv);
98 if (!(mono_exe = get_mono_exe()))
100 MESSAGE("wine: Install the Windows version of Mono to run .NET executables\n");
101 return E_FAIL;
104 HeapFree(GetProcessHeap(), 0, mono_exe);
106 return S_OK;
109 BOOL WINAPI DllMain(HINSTANCE hinstDLL, DWORD fdwReason, LPVOID lpvReserved)
111 TRACE("(%p, %d, %p)\n", hinstDLL, fdwReason, lpvReserved);
113 switch (fdwReason)
115 case DLL_WINE_PREATTACH:
116 return FALSE; /* prefer native version */
117 case DLL_PROCESS_ATTACH:
118 DisableThreadLibraryCalls(hinstDLL);
119 break;
120 case DLL_PROCESS_DETACH:
121 break;
123 return TRUE;
126 BOOL WINAPI _CorDllMain(HINSTANCE hinstDLL, DWORD fdwReason, LPVOID lpvReserved)
128 FIXME("(%p, %d, %p): stub\n", hinstDLL, fdwReason, lpvReserved);
130 switch (fdwReason)
132 case DLL_PROCESS_ATTACH:
133 DisableThreadLibraryCalls(hinstDLL);
134 break;
135 case DLL_PROCESS_DETACH:
136 break;
138 return TRUE;
141 __int32 WINAPI _CorExeMain(void)
143 STARTUPINFOW si;
144 PROCESS_INFORMATION pi;
145 WCHAR *mono_exe, *cmd_line;
146 DWORD size, exit_code;
148 if (!(mono_exe = get_mono_exe()))
150 MESSAGE("install the Windows version of Mono to run .NET executables\n");
151 return -1;
154 size = (lstrlenW(mono_exe) + lstrlenW(GetCommandLineW()) + 1) * sizeof(WCHAR);
155 if (!(cmd_line = HeapAlloc(GetProcessHeap(), 0, size)))
157 HeapFree(GetProcessHeap(), 0, mono_exe);
158 return -1;
161 lstrcpyW(cmd_line, mono_exe);
162 HeapFree(GetProcessHeap(), 0, mono_exe);
163 lstrcatW(cmd_line, GetCommandLineW());
165 TRACE("new command line: %s\n", debugstr_w(cmd_line));
167 memset(&si, 0, sizeof(si));
168 si.cb = sizeof(si);
169 if (!CreateProcessW(NULL, cmd_line, NULL, NULL, FALSE, 0, NULL, NULL, &si, &pi))
171 HeapFree(GetProcessHeap(), 0, cmd_line);
172 return -1;
174 HeapFree(GetProcessHeap(), 0, cmd_line);
176 /* wait for the process to exit */
177 WaitForSingleObject(pi.hProcess, INFINITE);
178 GetExitCodeProcess(pi.hProcess, &exit_code);
180 CloseHandle(pi.hThread);
181 CloseHandle(pi.hProcess);
183 return (int)exit_code;
186 __int32 WINAPI _CorExeMain2(PBYTE ptrMemory, DWORD cntMemory, LPWSTR imageName, LPWSTR loaderName, LPWSTR cmdLine)
188 TRACE("(%p, %u, %s, %s, %s)\n", ptrMemory, cntMemory, debugstr_w(imageName), debugstr_w(loaderName), debugstr_w(cmdLine));
189 FIXME("Directly running .NET applications not supported.\n");
190 return -1;
193 void WINAPI CorExitProcess(int exitCode)
195 FIXME("(%x) stub\n", exitCode);
196 ExitProcess(exitCode);
199 VOID WINAPI _CorImageUnloading(PVOID imageBase)
201 TRACE("(%p): stub\n", imageBase);
204 HRESULT WINAPI _CorValidateImage(PVOID* imageBase, LPCWSTR imageName)
206 TRACE("(%p, %s): stub\n", imageBase, debugstr_w(imageName));
207 return E_FAIL;
210 HRESULT WINAPI GetCORSystemDirectory(LPWSTR pbuffer, DWORD cchBuffer, DWORD *dwLength)
212 FIXME("(%p, %d, %p): stub!\n", pbuffer, cchBuffer, dwLength);
214 if (!dwLength)
215 return E_POINTER;
217 *dwLength = 0;
219 return S_OK;
222 HRESULT WINAPI GetCORVersion(LPWSTR pbuffer, DWORD cchBuffer, DWORD *dwLength)
224 static const WCHAR version[] = {'v','1','.','1','.','4','3','2','2',0};
226 FIXME("(%p, %d, %p): semi-stub!\n", pbuffer, cchBuffer, dwLength);
228 if (!dwLength)
229 return E_POINTER;
231 *dwLength = lstrlenW(version);
233 if (cchBuffer < *dwLength)
234 return ERROR_INSUFFICIENT_BUFFER;
236 if (pbuffer)
237 lstrcpyW(pbuffer, version);
239 return S_OK;
242 HRESULT WINAPI GetRequestedRuntimeInfo(LPCWSTR pExe, LPCWSTR pwszVersion, LPCWSTR pConfigurationFile,
243 DWORD startupFlags, DWORD runtimeInfoFlags, LPWSTR pDirectory, DWORD dwDirectory, DWORD *dwDirectoryLength,
244 LPWSTR pVersion, DWORD cchBuffer, DWORD *dwlength)
246 FIXME("(%s, %s, %s, 0x%08x, 0x%08x, %p, 0x%08x, %p, %p, 0x%08x, %p) stub\n", debugstr_w(pExe),
247 debugstr_w(pwszVersion), debugstr_w(pConfigurationFile), startupFlags, runtimeInfoFlags, pDirectory,
248 dwDirectory, dwDirectoryLength, pVersion, cchBuffer, dwlength);
249 return GetCORVersion(pVersion, cchBuffer, dwlength);
252 HRESULT WINAPI LoadLibraryShim( LPCWSTR szDllName, LPCWSTR szVersion, LPVOID pvReserved, HMODULE * phModDll)
254 FIXME("(%p %s, %p, %p, %p): semi-stub\n", szDllName, debugstr_w(szDllName), szVersion, pvReserved, phModDll);
256 if (phModDll) *phModDll = LoadLibraryW(szDllName);
257 return S_OK;
260 HRESULT WINAPI LockClrVersion(FLockClrVersionCallback hostCallback, FLockClrVersionCallback *pBeginHostSetup, FLockClrVersionCallback *pEndHostSetup)
262 FIXME("(%p %p %p): stub\n", hostCallback, pBeginHostSetup, pEndHostSetup);
263 return S_OK;
266 HRESULT WINAPI CoInitializeCor(DWORD fFlags)
268 FIXME("(0x%08x): stub\n", fFlags);
269 return S_OK;
272 HRESULT WINAPI GetAssemblyMDImport(LPCWSTR szFileName, REFIID riid, IUnknown **ppIUnk)
274 FIXME("(%p %s, %p, %p): stub\n", szFileName, debugstr_w(szFileName), riid, *ppIUnk);
275 return ERROR_CALL_NOT_IMPLEMENTED;
278 HRESULT WINAPI GetVersionFromProcess(HANDLE hProcess, LPWSTR pVersion, DWORD cchBuffer, DWORD *dwLength)
280 FIXME("(%p, %p, %d, %p): stub\n", hProcess, pVersion, cchBuffer, dwLength);
281 return E_NOTIMPL;
284 HRESULT WINAPI LoadStringRCEx(LCID culture, UINT resId, LPWSTR pBuffer, int iBufLen, int bQuiet, int* pBufLen)
286 HRESULT res = S_OK;
287 if ((iBufLen <= 0) || !pBuffer)
288 return E_INVALIDARG;
289 pBuffer[0] = 0;
290 if (resId) {
291 FIXME("(%d, %x, %p, %d, %d, %p): semi-stub\n", culture, resId, pBuffer, iBufLen, bQuiet, pBufLen);
292 res = E_NOTIMPL;
294 else
295 res = E_FAIL;
296 if (pBufLen)
297 *pBufLen = lstrlenW(pBuffer);
298 return res;
301 HRESULT WINAPI LoadStringRC(UINT resId, LPWSTR pBuffer, int iBufLen, int bQuiet)
303 return LoadStringRCEx(-1, resId, pBuffer, iBufLen, bQuiet, NULL);
306 HRESULT WINAPI CorBindToRuntimeEx(LPWSTR szVersion, LPWSTR szBuildFlavor, DWORD nflags, REFCLSID rslsid,
307 REFIID riid, LPVOID *ppv)
309 FIXME("%s %s %d %s %s %p\n", debugstr_w(szVersion), debugstr_w(szBuildFlavor), nflags, debugstr_guid( rslsid ),
310 debugstr_guid( riid ), ppv);
312 if(IsEqualGUID( riid, &IID_ICorRuntimeHost ))
314 *ppv = create_corruntimehost();
315 return S_OK;
317 *ppv = NULL;
318 return E_NOTIMPL;
321 HRESULT WINAPI CorBindToCurrentRuntime(LPCWSTR filename, REFCLSID rclsid, REFIID riid, LPVOID *ppv)
323 FIXME("(%s, %s, %s, %p): stub\n", debugstr_w(filename), debugstr_guid(rclsid), debugstr_guid(riid), ppv);
324 return E_NOTIMPL;
327 HRESULT WINAPI DllGetClassObject(REFCLSID rclsid, REFIID riid, LPVOID* ppv)
329 FIXME("(%p, %p, %p): stub\n", rclsid, riid, ppv);
330 if(!ppv)
331 return E_INVALIDARG;
333 return E_NOTIMPL;
336 HRESULT WINAPI DllCanUnloadNow(VOID)
338 FIXME("stub\n");
339 return S_OK;
342 INT WINAPI ND_RU1( const void *ptr, INT offset )
344 return *((const BYTE *)ptr + offset);
347 INT WINAPI ND_RI2( const void *ptr, INT offset )
349 return *(const SHORT *)((const BYTE *)ptr + offset);
352 INT WINAPI ND_RI4( const void *ptr, INT offset )
354 return *(const INT *)((const BYTE *)ptr + offset);
357 INT64 WINAPI ND_RI8( const void *ptr, INT offset )
359 return *(const INT64 *)((const BYTE *)ptr + offset);
362 void WINAPI ND_WU1( void *ptr, INT offset, BYTE val )
364 *((BYTE *)ptr + offset) = val;
367 void WINAPI ND_WI2( void *ptr, INT offset, SHORT val )
369 *(SHORT *)((BYTE *)ptr + offset) = val;
372 void WINAPI ND_WI4( void *ptr, INT offset, INT val )
374 *(INT *)((BYTE *)ptr + offset) = val;
377 void WINAPI ND_WI8( void *ptr, INT offset, INT64 val )
379 *(INT64 *)((BYTE *)ptr + offset) = val;
382 void WINAPI ND_CopyObjDst( const void *src, void *dst, INT offset, INT size )
384 memcpy( (BYTE *)dst + offset, src, size );
387 void WINAPI ND_CopyObjSrc( const void *src, INT offset, void *dst, INT size )
389 memcpy( dst, (const BYTE *)src + offset, size );