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
30 #include "wine/debug.h"
32 WINE_DEFAULT_DEBUG_CHANNEL( mscoree );
34 HRESULT WINAPI CorBindToRuntimeHost(LPCWSTR pwszVersion, LPCWSTR pwszBuildFlavor,
35 LPCWSTR pwszHostConfigFile, VOID *pReserved,
36 DWORD startupFlags, REFCLSID rclsid,
37 REFIID riid, LPVOID *ppv)
39 FIXME("(%s, %s, %s, %p, %d, %p, %p, %p): stub!\n", debugstr_w(pwszVersion),
40 debugstr_w(pwszBuildFlavor), debugstr_w(pwszHostConfigFile), pReserved,
41 startupFlags, rclsid, riid, ppv);
46 BOOL WINAPI DllMain(HINSTANCE hinstDLL, DWORD fdwReason, LPVOID lpvReserved)
48 TRACE("(%p, %d, %p)\n", hinstDLL, fdwReason, lpvReserved);
52 case DLL_WINE_PREATTACH:
53 return FALSE; /* prefer native version */
54 case DLL_PROCESS_ATTACH:
55 DisableThreadLibraryCalls(hinstDLL);
57 case DLL_PROCESS_DETACH:
63 BOOL WINAPI _CorDllMain(HINSTANCE hinstDLL, DWORD fdwReason, LPVOID lpvReserved)
65 FIXME("(%p, %d, %p): stub\n", hinstDLL, fdwReason, lpvReserved);
69 case DLL_PROCESS_ATTACH:
70 DisableThreadLibraryCalls(hinstDLL);
72 case DLL_PROCESS_DETACH:
78 static LPWSTR get_mono_exe()
80 static const WCHAR mono_exe[] = {'b','i','n','\\','m','o','n','o','.','e','x','e',' ',0};
81 static const WCHAR mono_key[] = {'S','o','f','t','w','a','r','e','\\','N','o','v','e','l','l','\\','M','o','n','o',0};
82 static const WCHAR defaul_clr[] = {'D','e','f','a','u','l','t','C','L','R',0};
83 static const WCHAR install_root[] = {'S','d','k','I','n','s','t','a','l','l','R','o','o','t',0};
84 static const WCHAR slash[] = {'\\',0};
86 WCHAR version[64], version_key[MAX_PATH], root[MAX_PATH], *ret;
90 if (RegOpenKeyExW(HKEY_LOCAL_MACHINE, mono_key, 0, KEY_READ, &key))
93 len = sizeof(version);
94 if (RegQueryValueExW(key, defaul_clr, 0, NULL, (LPBYTE)version, &len))
101 lstrcpyW(version_key, mono_key);
102 lstrcatW(version_key, slash);
103 lstrcatW(version_key, version);
105 if (RegOpenKeyExW(HKEY_LOCAL_MACHINE, version_key, 0, KEY_READ, &key))
109 if (RegQueryValueExW(key, install_root, 0, NULL, (LPBYTE)root, &len))
116 size = len + sizeof(slash) + sizeof(mono_exe);
117 if (!(ret = HeapAlloc(GetProcessHeap(), 0, size))) return NULL;
120 lstrcatW(ret, slash);
121 lstrcatW(ret, mono_exe);
126 int WINAPI _CorExeMain(void)
129 PROCESS_INFORMATION pi;
130 WCHAR *mono_exe, *cmd_line;
131 DWORD size, exit_code;
133 if (!(mono_exe = get_mono_exe()))
135 MESSAGE("install the Windows version of Mono to run .NET executables\n");
139 size = (lstrlenW(mono_exe) + lstrlenW(GetCommandLineW()) + 1) * sizeof(WCHAR);
140 if (!(cmd_line = HeapAlloc(GetProcessHeap(), 0, size)))
142 HeapFree(GetProcessHeap(), 0, mono_exe);
146 lstrcpyW(cmd_line, mono_exe);
147 HeapFree(GetProcessHeap(), 0, mono_exe);
148 lstrcatW(cmd_line, GetCommandLineW());
150 TRACE("new command line: %s\n", debugstr_w(cmd_line));
152 memset(&si, 0, sizeof(si));
154 if (!CreateProcessW(NULL, cmd_line, NULL, NULL, FALSE, 0, NULL, NULL, &si, &pi))
156 HeapFree(GetProcessHeap(), 0, cmd_line);
159 HeapFree(GetProcessHeap(), 0, cmd_line);
161 /* wait for the process to exit */
162 WaitForSingleObject(pi.hProcess, INFINITE);
163 GetExitCodeProcess(pi.hProcess, &exit_code);
165 CloseHandle(pi.hThread);
166 CloseHandle(pi.hProcess);
168 return (int)exit_code;
171 int WINAPI _CorExeMain2(PBYTE ptrMemory, DWORD cntMemory, LPCWSTR imageName, LPCWSTR loaderName, LPCWSTR cmdLine)
173 TRACE("(%p, %u, %s, %s, %s)\n", ptrMemory, cntMemory, debugstr_w(imageName), debugstr_w(loaderName), debugstr_w(cmdLine));
174 FIXME("Directly running .NET applications not supported.\n");
178 void WINAPI CorExitProcess(int exitCode)
180 FIXME("(%x) stub\n", exitCode);
181 ExitProcess(exitCode);
184 void WINAPI _CorImageUnloading(LPCVOID* imageBase)
186 TRACE("(%p): stub\n", imageBase);
189 DWORD _CorValidateImage(LPCVOID* imageBase, LPCWSTR imageName)
191 TRACE("(%p, %s): stub\n", imageBase, debugstr_w(imageName));
195 HRESULT WINAPI GetCORSystemDirectory(LPWSTR pbuffer, DWORD cchBuffer, DWORD *dwLength)
197 FIXME("(%p, %d, %p): stub!\n", pbuffer, cchBuffer, dwLength);
207 HRESULT WINAPI GetCORVersion(LPWSTR pbuffer, DWORD cchBuffer, DWORD *dwLength)
209 static const WCHAR version[] = {'v','1','.','1','.','4','3','2','2',0};
211 FIXME("(%p, %d, %p): semi-stub!\n", pbuffer, cchBuffer, dwLength);
216 *dwLength = lstrlenW(version);
218 if (cchBuffer < *dwLength)
219 return ERROR_INSUFFICIENT_BUFFER;
222 lstrcpyW(pbuffer, version);
227 HRESULT WINAPI GetRequestedRuntimeInfo(LPCWSTR pExe, LPCWSTR pwszVersion, LPCWSTR pConfigurationFile,
228 DWORD startupFlags, DWORD runtimeInfoFlags, LPWSTR pDirectory, DWORD dwDirectory, DWORD *dwDirectoryLength,
229 LPWSTR pVersion, DWORD cchBuffer, DWORD *dwlength)
231 FIXME("(%s, %s, %s, 0x%08x, 0x%08x, %p, 0x%08x, %p, %p, 0x%08x, %p) stub\n", debugstr_w(pExe),
232 debugstr_w(pwszVersion), debugstr_w(pConfigurationFile), startupFlags, runtimeInfoFlags, pDirectory,
233 dwDirectory, dwDirectoryLength, pVersion, cchBuffer, dwlength);
234 return GetCORVersion(pVersion, cchBuffer, dwlength);
237 HRESULT WINAPI LoadLibraryShim( LPCWSTR szDllName, LPCWSTR szVersion, LPVOID pvReserved, HMODULE * phModDll)
239 FIXME("(%p %s, %p, %p, %p): semi-stub\n", szDllName, debugstr_w(szDllName), szVersion, pvReserved, phModDll);
241 if (phModDll) *phModDll = LoadLibraryW(szDllName);
245 HRESULT WINAPI CoInitializeCor(DWORD fFlags)
247 FIXME("(0x%08x): stub\n", fFlags);
251 HRESULT WINAPI GetAssemblyMDImport(LPCWSTR szFileName, REFIID riid, IUnknown **ppIUnk)
253 FIXME("(%p %s, %p, %p): stub\n", szFileName, debugstr_w(szFileName), riid, *ppIUnk);
254 return ERROR_CALL_NOT_IMPLEMENTED;