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 "wine/debug.h"
35 WINE_DEFAULT_DEBUG_CHANNEL( mscoree );
37 HRESULT WINAPI CorBindToRuntimeHost(LPCWSTR pwszVersion, LPCWSTR pwszBuildFlavor,
38 LPCWSTR pwszHostConfigFile, VOID *pReserved,
39 DWORD startupFlags, REFCLSID rclsid,
40 REFIID riid, LPVOID *ppv)
42 FIXME("(%s, %s, %s, %p, %d, %p, %p, %p): stub!\n", debugstr_w(pwszVersion),
43 debugstr_w(pwszBuildFlavor), debugstr_w(pwszHostConfigFile), pReserved,
44 startupFlags, rclsid, riid, ppv);
49 BOOL WINAPI DllMain(HINSTANCE hinstDLL, DWORD fdwReason, LPVOID lpvReserved)
51 TRACE("(%p, %d, %p)\n", hinstDLL, fdwReason, lpvReserved);
55 case DLL_WINE_PREATTACH:
56 return FALSE; /* prefer native version */
57 case DLL_PROCESS_ATTACH:
58 DisableThreadLibraryCalls(hinstDLL);
60 case DLL_PROCESS_DETACH:
66 BOOL WINAPI _CorDllMain(HINSTANCE hinstDLL, DWORD fdwReason, LPVOID lpvReserved)
68 FIXME("(%p, %d, %p): stub\n", hinstDLL, fdwReason, lpvReserved);
72 case DLL_PROCESS_ATTACH:
73 DisableThreadLibraryCalls(hinstDLL);
75 case DLL_PROCESS_DETACH:
81 static LPWSTR get_mono_exe(void)
83 static const WCHAR mono_exe[] = {'b','i','n','\\','m','o','n','o','.','e','x','e',' ',0};
84 static const WCHAR mono_key[] = {'S','o','f','t','w','a','r','e','\\','N','o','v','e','l','l','\\','M','o','n','o',0};
85 static const WCHAR defaul_clr[] = {'D','e','f','a','u','l','t','C','L','R',0};
86 static const WCHAR install_root[] = {'S','d','k','I','n','s','t','a','l','l','R','o','o','t',0};
87 static const WCHAR slash[] = {'\\',0};
89 WCHAR version[64], version_key[MAX_PATH], root[MAX_PATH], *ret;
93 if (RegOpenKeyExW(HKEY_LOCAL_MACHINE, mono_key, 0, KEY_READ, &key))
96 len = sizeof(version);
97 if (RegQueryValueExW(key, defaul_clr, 0, NULL, (LPBYTE)version, &len))
104 lstrcpyW(version_key, mono_key);
105 lstrcatW(version_key, slash);
106 lstrcatW(version_key, version);
108 if (RegOpenKeyExW(HKEY_LOCAL_MACHINE, version_key, 0, KEY_READ, &key))
112 if (RegQueryValueExW(key, install_root, 0, NULL, (LPBYTE)root, &len))
119 size = len + sizeof(slash) + sizeof(mono_exe);
120 if (!(ret = HeapAlloc(GetProcessHeap(), 0, size))) return NULL;
123 lstrcatW(ret, slash);
124 lstrcatW(ret, mono_exe);
129 __int32 WINAPI _CorExeMain(void)
132 PROCESS_INFORMATION pi;
133 WCHAR *mono_exe, *cmd_line;
134 DWORD size, exit_code;
136 if (!(mono_exe = get_mono_exe()))
138 MESSAGE("install the Windows version of Mono to run .NET executables\n");
142 size = (lstrlenW(mono_exe) + lstrlenW(GetCommandLineW()) + 1) * sizeof(WCHAR);
143 if (!(cmd_line = HeapAlloc(GetProcessHeap(), 0, size)))
145 HeapFree(GetProcessHeap(), 0, mono_exe);
149 lstrcpyW(cmd_line, mono_exe);
150 HeapFree(GetProcessHeap(), 0, mono_exe);
151 lstrcatW(cmd_line, GetCommandLineW());
153 TRACE("new command line: %s\n", debugstr_w(cmd_line));
155 memset(&si, 0, sizeof(si));
157 if (!CreateProcessW(NULL, cmd_line, NULL, NULL, FALSE, 0, NULL, NULL, &si, &pi))
159 HeapFree(GetProcessHeap(), 0, cmd_line);
162 HeapFree(GetProcessHeap(), 0, cmd_line);
164 /* wait for the process to exit */
165 WaitForSingleObject(pi.hProcess, INFINITE);
166 GetExitCodeProcess(pi.hProcess, &exit_code);
168 CloseHandle(pi.hThread);
169 CloseHandle(pi.hProcess);
171 return (int)exit_code;
174 __int32 WINAPI _CorExeMain2(PBYTE ptrMemory, DWORD cntMemory, LPWSTR imageName, LPWSTR loaderName, LPWSTR cmdLine)
176 TRACE("(%p, %u, %s, %s, %s)\n", ptrMemory, cntMemory, debugstr_w(imageName), debugstr_w(loaderName), debugstr_w(cmdLine));
177 FIXME("Directly running .NET applications not supported.\n");
181 void WINAPI CorExitProcess(int exitCode)
183 FIXME("(%x) stub\n", exitCode);
184 ExitProcess(exitCode);
187 VOID WINAPI _CorImageUnloading(PVOID imageBase)
189 TRACE("(%p): stub\n", imageBase);
192 HRESULT WINAPI _CorValidateImage(PVOID* imageBase, LPCWSTR imageName)
194 TRACE("(%p, %s): stub\n", imageBase, debugstr_w(imageName));
198 HRESULT WINAPI GetCORSystemDirectory(LPWSTR pbuffer, DWORD cchBuffer, DWORD *dwLength)
200 FIXME("(%p, %d, %p): stub!\n", pbuffer, cchBuffer, dwLength);
210 HRESULT WINAPI GetCORVersion(LPWSTR pbuffer, DWORD cchBuffer, DWORD *dwLength)
212 static const WCHAR version[] = {'v','1','.','1','.','4','3','2','2',0};
214 FIXME("(%p, %d, %p): semi-stub!\n", pbuffer, cchBuffer, dwLength);
219 *dwLength = lstrlenW(version);
221 if (cchBuffer < *dwLength)
222 return ERROR_INSUFFICIENT_BUFFER;
225 lstrcpyW(pbuffer, version);
230 HRESULT WINAPI GetRequestedRuntimeInfo(LPCWSTR pExe, LPCWSTR pwszVersion, LPCWSTR pConfigurationFile,
231 DWORD startupFlags, DWORD runtimeInfoFlags, LPWSTR pDirectory, DWORD dwDirectory, DWORD *dwDirectoryLength,
232 LPWSTR pVersion, DWORD cchBuffer, DWORD *dwlength)
234 FIXME("(%s, %s, %s, 0x%08x, 0x%08x, %p, 0x%08x, %p, %p, 0x%08x, %p) stub\n", debugstr_w(pExe),
235 debugstr_w(pwszVersion), debugstr_w(pConfigurationFile), startupFlags, runtimeInfoFlags, pDirectory,
236 dwDirectory, dwDirectoryLength, pVersion, cchBuffer, dwlength);
237 return GetCORVersion(pVersion, cchBuffer, dwlength);
240 HRESULT WINAPI LoadLibraryShim( LPCWSTR szDllName, LPCWSTR szVersion, LPVOID pvReserved, HMODULE * phModDll)
242 FIXME("(%p %s, %p, %p, %p): semi-stub\n", szDllName, debugstr_w(szDllName), szVersion, pvReserved, phModDll);
244 if (phModDll) *phModDll = LoadLibraryW(szDllName);
248 HRESULT WINAPI CoInitializeCor(DWORD fFlags)
250 FIXME("(0x%08x): stub\n", fFlags);
254 HRESULT WINAPI GetAssemblyMDImport(LPCWSTR szFileName, REFIID riid, IUnknown **ppIUnk)
256 FIXME("(%p %s, %p, %p): stub\n", szFileName, debugstr_w(szFileName), riid, *ppIUnk);
257 return ERROR_CALL_NOT_IMPLEMENTED;