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
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;
51 if (RegOpenKeyExW(HKEY_LOCAL_MACHINE, mono_key, 0, KEY_READ, &key))
54 len = sizeof(version);
55 if (RegQueryValueExW(key, defaul_clr, 0, NULL, (LPBYTE)version, &len))
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))
70 if (RegQueryValueExW(key, install_root, 0, NULL, (LPBYTE)root, &len))
77 size = len + sizeof(slash) + sizeof(mono_exe);
78 if (!(ret = HeapAlloc(GetProcessHeap(), 0, size))) return NULL;
82 lstrcatW(ret, mono_exe);
87 HRESULT WINAPI CorBindToRuntimeHost(LPCWSTR pwszVersion, LPCWSTR pwszBuildFlavor,
88 LPCWSTR pwszHostConfigFile, VOID *pReserved,
89 DWORD startupFlags, REFCLSID rclsid,
90 REFIID riid, LPVOID *ppv)
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");
104 HeapFree(GetProcessHeap(), 0, mono_exe);
109 BOOL WINAPI DllMain(HINSTANCE hinstDLL, DWORD fdwReason, LPVOID lpvReserved)
111 TRACE("(%p, %d, %p)\n", hinstDLL, fdwReason, lpvReserved);
115 case DLL_WINE_PREATTACH:
116 return FALSE; /* prefer native version */
117 case DLL_PROCESS_ATTACH:
118 DisableThreadLibraryCalls(hinstDLL);
120 case DLL_PROCESS_DETACH:
126 BOOL WINAPI _CorDllMain(HINSTANCE hinstDLL, DWORD fdwReason, LPVOID lpvReserved)
128 FIXME("(%p, %d, %p): stub\n", hinstDLL, fdwReason, lpvReserved);
132 case DLL_PROCESS_ATTACH:
133 DisableThreadLibraryCalls(hinstDLL);
135 case DLL_PROCESS_DETACH:
141 __int32 WINAPI _CorExeMain(void)
144 PROCESS_INFORMATION pi;
145 WCHAR *mono_exe, *cmd_line;
146 DWORD size, exit_code;
147 static const WCHAR WINE_MONO_TRACE[]={'W','I','N','E','_','M','O','N','O','_','T','R','A','C','E',0};
148 static const WCHAR trace_switch_start[]={'"','-','-','t','r','a','c','e','=',0};
149 static const WCHAR trace_switch_end[]={'"',' ',0};
151 WCHAR trace_setting[256];
153 if (!(mono_exe = get_mono_exe()))
155 MESSAGE("install the Windows version of Mono to run .NET executables\n");
159 trace_size = GetEnvironmentVariableW(WINE_MONO_TRACE, trace_setting, sizeof(trace_setting)/sizeof(WCHAR));
161 size = (lstrlenW(mono_exe) + lstrlenW(GetCommandLineW()) + 1) * sizeof(WCHAR);
164 size += (trace_size + lstrlenW(trace_switch_start) + lstrlenW(trace_switch_end)) * sizeof(WCHAR);
166 if (!(cmd_line = HeapAlloc(GetProcessHeap(), 0, size)))
168 HeapFree(GetProcessHeap(), 0, mono_exe);
172 lstrcpyW(cmd_line, mono_exe);
173 HeapFree(GetProcessHeap(), 0, mono_exe);
177 lstrcatW(cmd_line, trace_switch_start);
178 lstrcatW(cmd_line, trace_setting);
179 lstrcatW(cmd_line, trace_switch_end);
182 lstrcatW(cmd_line, GetCommandLineW());
184 TRACE("new command line: %s\n", debugstr_w(cmd_line));
186 memset(&si, 0, sizeof(si));
188 if (!CreateProcessW(NULL, cmd_line, NULL, NULL, FALSE, 0, NULL, NULL, &si, &pi))
190 HeapFree(GetProcessHeap(), 0, cmd_line);
193 HeapFree(GetProcessHeap(), 0, cmd_line);
195 /* wait for the process to exit */
196 WaitForSingleObject(pi.hProcess, INFINITE);
197 GetExitCodeProcess(pi.hProcess, &exit_code);
199 CloseHandle(pi.hThread);
200 CloseHandle(pi.hProcess);
202 return (int)exit_code;
205 __int32 WINAPI _CorExeMain2(PBYTE ptrMemory, DWORD cntMemory, LPWSTR imageName, LPWSTR loaderName, LPWSTR cmdLine)
207 TRACE("(%p, %u, %s, %s, %s)\n", ptrMemory, cntMemory, debugstr_w(imageName), debugstr_w(loaderName), debugstr_w(cmdLine));
208 FIXME("Directly running .NET applications not supported.\n");
212 void WINAPI CorExitProcess(int exitCode)
214 FIXME("(%x) stub\n", exitCode);
215 ExitProcess(exitCode);
218 VOID WINAPI _CorImageUnloading(PVOID imageBase)
220 TRACE("(%p): stub\n", imageBase);
223 HRESULT WINAPI _CorValidateImage(PVOID* imageBase, LPCWSTR imageName)
225 TRACE("(%p, %s): stub\n", imageBase, debugstr_w(imageName));
229 HRESULT WINAPI GetCORSystemDirectory(LPWSTR pbuffer, DWORD cchBuffer, DWORD *dwLength)
231 FIXME("(%p, %d, %p): stub!\n", pbuffer, cchBuffer, dwLength);
241 HRESULT WINAPI GetCORVersion(LPWSTR pbuffer, DWORD cchBuffer, DWORD *dwLength)
243 static const WCHAR version[] = {'v','1','.','1','.','4','3','2','2',0};
245 FIXME("(%p, %d, %p): semi-stub!\n", pbuffer, cchBuffer, dwLength);
250 *dwLength = lstrlenW(version);
252 if (cchBuffer < *dwLength)
253 return ERROR_INSUFFICIENT_BUFFER;
256 lstrcpyW(pbuffer, version);
261 HRESULT WINAPI GetRequestedRuntimeInfo(LPCWSTR pExe, LPCWSTR pwszVersion, LPCWSTR pConfigurationFile,
262 DWORD startupFlags, DWORD runtimeInfoFlags, LPWSTR pDirectory, DWORD dwDirectory, DWORD *dwDirectoryLength,
263 LPWSTR pVersion, DWORD cchBuffer, DWORD *dwlength)
265 FIXME("(%s, %s, %s, 0x%08x, 0x%08x, %p, 0x%08x, %p, %p, 0x%08x, %p) stub\n", debugstr_w(pExe),
266 debugstr_w(pwszVersion), debugstr_w(pConfigurationFile), startupFlags, runtimeInfoFlags, pDirectory,
267 dwDirectory, dwDirectoryLength, pVersion, cchBuffer, dwlength);
268 return GetCORVersion(pVersion, cchBuffer, dwlength);
271 HRESULT WINAPI LoadLibraryShim( LPCWSTR szDllName, LPCWSTR szVersion, LPVOID pvReserved, HMODULE * phModDll)
273 FIXME("(%p %s, %p, %p, %p): semi-stub\n", szDllName, debugstr_w(szDllName), szVersion, pvReserved, phModDll);
275 if (phModDll) *phModDll = LoadLibraryW(szDllName);
279 HRESULT WINAPI LockClrVersion(FLockClrVersionCallback hostCallback, FLockClrVersionCallback *pBeginHostSetup, FLockClrVersionCallback *pEndHostSetup)
281 FIXME("(%p %p %p): stub\n", hostCallback, pBeginHostSetup, pEndHostSetup);
285 HRESULT WINAPI CoInitializeCor(DWORD fFlags)
287 FIXME("(0x%08x): stub\n", fFlags);
291 HRESULT WINAPI GetAssemblyMDImport(LPCWSTR szFileName, REFIID riid, IUnknown **ppIUnk)
293 FIXME("(%p %s, %p, %p): stub\n", szFileName, debugstr_w(szFileName), riid, *ppIUnk);
294 return ERROR_CALL_NOT_IMPLEMENTED;
297 HRESULT WINAPI GetVersionFromProcess(HANDLE hProcess, LPWSTR pVersion, DWORD cchBuffer, DWORD *dwLength)
299 FIXME("(%p, %p, %d, %p): stub\n", hProcess, pVersion, cchBuffer, dwLength);
303 HRESULT WINAPI LoadStringRCEx(LCID culture, UINT resId, LPWSTR pBuffer, int iBufLen, int bQuiet, int* pBufLen)
306 if ((iBufLen <= 0) || !pBuffer)
310 FIXME("(%d, %x, %p, %d, %d, %p): semi-stub\n", culture, resId, pBuffer, iBufLen, bQuiet, pBufLen);
316 *pBufLen = lstrlenW(pBuffer);
320 HRESULT WINAPI LoadStringRC(UINT resId, LPWSTR pBuffer, int iBufLen, int bQuiet)
322 return LoadStringRCEx(-1, resId, pBuffer, iBufLen, bQuiet, NULL);
325 HRESULT WINAPI CorBindToRuntimeEx(LPWSTR szVersion, LPWSTR szBuildFlavor, DWORD nflags, REFCLSID rslsid,
326 REFIID riid, LPVOID *ppv)
328 FIXME("%s %s %d %s %s %p\n", debugstr_w(szVersion), debugstr_w(szBuildFlavor), nflags, debugstr_guid( rslsid ),
329 debugstr_guid( riid ), ppv);
331 if(IsEqualGUID( riid, &IID_ICorRuntimeHost ))
333 *ppv = create_corruntimehost();
340 HRESULT WINAPI CorBindToCurrentRuntime(LPCWSTR filename, REFCLSID rclsid, REFIID riid, LPVOID *ppv)
342 FIXME("(%s, %s, %s, %p): stub\n", debugstr_w(filename), debugstr_guid(rclsid), debugstr_guid(riid), ppv);
346 BOOL WINAPI StrongNameSignatureVerification(LPCWSTR filename, DWORD inFlags, DWORD* pOutFlags)
348 FIXME("(%s, 0x%X, %p): stub\n", debugstr_w(filename), inFlags, pOutFlags);
352 BOOL WINAPI StrongNameSignatureVerificationEx(LPCWSTR filename, BOOL forceVerification, BOOL* pVerified)
354 FIXME("(%s, %u, %p): stub\n", debugstr_w(filename), forceVerification, pVerified);
358 HRESULT WINAPI DllGetClassObject(REFCLSID rclsid, REFIID riid, LPVOID* ppv)
360 FIXME("(%p, %p, %p): stub\n", rclsid, riid, ppv);
367 HRESULT WINAPI DllRegisterServer(void)
373 HRESULT WINAPI DllUnregisterServer(void)
379 HRESULT WINAPI DllCanUnloadNow(VOID)
384 INT WINAPI ND_RU1( const void *ptr, INT offset )
386 return *((const BYTE *)ptr + offset);
389 INT WINAPI ND_RI2( const void *ptr, INT offset )
391 return *(const SHORT *)((const BYTE *)ptr + offset);
394 INT WINAPI ND_RI4( const void *ptr, INT offset )
396 return *(const INT *)((const BYTE *)ptr + offset);
399 INT64 WINAPI ND_RI8( const void *ptr, INT offset )
401 return *(const INT64 *)((const BYTE *)ptr + offset);
404 void WINAPI ND_WU1( void *ptr, INT offset, BYTE val )
406 *((BYTE *)ptr + offset) = val;
409 void WINAPI ND_WI2( void *ptr, INT offset, SHORT val )
411 *(SHORT *)((BYTE *)ptr + offset) = val;
414 void WINAPI ND_WI4( void *ptr, INT offset, INT val )
416 *(INT *)((BYTE *)ptr + offset) = val;
419 void WINAPI ND_WI8( void *ptr, INT offset, INT64 val )
421 *(INT64 *)((BYTE *)ptr + offset) = val;
424 void WINAPI ND_CopyObjDst( const void *src, void *dst, INT offset, INT size )
426 memcpy( (BYTE *)dst + offset, src, size );
429 void WINAPI ND_CopyObjSrc( const void *src, INT offset, void *dst, INT size )
431 memcpy( dst, (const BYTE *)src + offset, size );