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 static LPWSTR
get_mono_exe(void)
39 static const WCHAR mono_exe
[] = {'b','i','n','\\','m','o','n','o','.','e','x','e',' ',0};
40 static const WCHAR mono_key
[] = {'S','o','f','t','w','a','r','e','\\','N','o','v','e','l','l','\\','M','o','n','o',0};
41 static const WCHAR defaul_clr
[] = {'D','e','f','a','u','l','t','C','L','R',0};
42 static const WCHAR install_root
[] = {'S','d','k','I','n','s','t','a','l','l','R','o','o','t',0};
43 static const WCHAR slash
[] = {'\\',0};
45 WCHAR version
[64], version_key
[MAX_PATH
], root
[MAX_PATH
], *ret
;
49 if (RegOpenKeyExW(HKEY_LOCAL_MACHINE
, mono_key
, 0, KEY_READ
, &key
))
52 len
= sizeof(version
);
53 if (RegQueryValueExW(key
, defaul_clr
, 0, NULL
, (LPBYTE
)version
, &len
))
60 lstrcpyW(version_key
, mono_key
);
61 lstrcatW(version_key
, slash
);
62 lstrcatW(version_key
, version
);
64 if (RegOpenKeyExW(HKEY_LOCAL_MACHINE
, version_key
, 0, KEY_READ
, &key
))
68 if (RegQueryValueExW(key
, install_root
, 0, NULL
, (LPBYTE
)root
, &len
))
75 size
= len
+ sizeof(slash
) + sizeof(mono_exe
);
76 if (!(ret
= HeapAlloc(GetProcessHeap(), 0, size
))) return NULL
;
80 lstrcatW(ret
, mono_exe
);
85 HRESULT WINAPI
CorBindToRuntimeHost(LPCWSTR pwszVersion
, LPCWSTR pwszBuildFlavor
,
86 LPCWSTR pwszHostConfigFile
, VOID
*pReserved
,
87 DWORD startupFlags
, REFCLSID rclsid
,
88 REFIID riid
, LPVOID
*ppv
)
92 FIXME("(%s, %s, %s, %p, %d, %p, %p, %p): semi-stub!\n", debugstr_w(pwszVersion
),
93 debugstr_w(pwszBuildFlavor
), debugstr_w(pwszHostConfigFile
), pReserved
,
94 startupFlags
, rclsid
, riid
, ppv
);
96 if (!(mono_exe
= get_mono_exe()))
98 MESSAGE("wine: Install the Windows version of Mono to run .NET executables\n");
105 BOOL WINAPI
DllMain(HINSTANCE hinstDLL
, DWORD fdwReason
, LPVOID lpvReserved
)
107 TRACE("(%p, %d, %p)\n", hinstDLL
, fdwReason
, lpvReserved
);
111 case DLL_WINE_PREATTACH
:
112 return FALSE
; /* prefer native version */
113 case DLL_PROCESS_ATTACH
:
114 DisableThreadLibraryCalls(hinstDLL
);
116 case DLL_PROCESS_DETACH
:
122 BOOL WINAPI
_CorDllMain(HINSTANCE hinstDLL
, DWORD fdwReason
, LPVOID lpvReserved
)
124 FIXME("(%p, %d, %p): stub\n", hinstDLL
, fdwReason
, lpvReserved
);
128 case DLL_PROCESS_ATTACH
:
129 DisableThreadLibraryCalls(hinstDLL
);
131 case DLL_PROCESS_DETACH
:
137 __int32 WINAPI
_CorExeMain(void)
140 PROCESS_INFORMATION pi
;
141 WCHAR
*mono_exe
, *cmd_line
;
142 DWORD size
, exit_code
;
144 if (!(mono_exe
= get_mono_exe()))
146 MESSAGE("install the Windows version of Mono to run .NET executables\n");
150 size
= (lstrlenW(mono_exe
) + lstrlenW(GetCommandLineW()) + 1) * sizeof(WCHAR
);
151 if (!(cmd_line
= HeapAlloc(GetProcessHeap(), 0, size
)))
153 HeapFree(GetProcessHeap(), 0, mono_exe
);
157 lstrcpyW(cmd_line
, mono_exe
);
158 HeapFree(GetProcessHeap(), 0, mono_exe
);
159 lstrcatW(cmd_line
, GetCommandLineW());
161 TRACE("new command line: %s\n", debugstr_w(cmd_line
));
163 memset(&si
, 0, sizeof(si
));
165 if (!CreateProcessW(NULL
, cmd_line
, NULL
, NULL
, FALSE
, 0, NULL
, NULL
, &si
, &pi
))
167 HeapFree(GetProcessHeap(), 0, cmd_line
);
170 HeapFree(GetProcessHeap(), 0, cmd_line
);
172 /* wait for the process to exit */
173 WaitForSingleObject(pi
.hProcess
, INFINITE
);
174 GetExitCodeProcess(pi
.hProcess
, &exit_code
);
176 CloseHandle(pi
.hThread
);
177 CloseHandle(pi
.hProcess
);
179 return (int)exit_code
;
182 __int32 WINAPI
_CorExeMain2(PBYTE ptrMemory
, DWORD cntMemory
, LPWSTR imageName
, LPWSTR loaderName
, LPWSTR cmdLine
)
184 TRACE("(%p, %u, %s, %s, %s)\n", ptrMemory
, cntMemory
, debugstr_w(imageName
), debugstr_w(loaderName
), debugstr_w(cmdLine
));
185 FIXME("Directly running .NET applications not supported.\n");
189 void WINAPI
CorExitProcess(int exitCode
)
191 FIXME("(%x) stub\n", exitCode
);
192 ExitProcess(exitCode
);
195 VOID WINAPI
_CorImageUnloading(PVOID imageBase
)
197 TRACE("(%p): stub\n", imageBase
);
200 HRESULT WINAPI
_CorValidateImage(PVOID
* imageBase
, LPCWSTR imageName
)
202 TRACE("(%p, %s): stub\n", imageBase
, debugstr_w(imageName
));
206 HRESULT WINAPI
GetCORSystemDirectory(LPWSTR pbuffer
, DWORD cchBuffer
, DWORD
*dwLength
)
208 FIXME("(%p, %d, %p): stub!\n", pbuffer
, cchBuffer
, dwLength
);
218 HRESULT WINAPI
GetCORVersion(LPWSTR pbuffer
, DWORD cchBuffer
, DWORD
*dwLength
)
220 static const WCHAR version
[] = {'v','1','.','1','.','4','3','2','2',0};
222 FIXME("(%p, %d, %p): semi-stub!\n", pbuffer
, cchBuffer
, dwLength
);
227 *dwLength
= lstrlenW(version
);
229 if (cchBuffer
< *dwLength
)
230 return ERROR_INSUFFICIENT_BUFFER
;
233 lstrcpyW(pbuffer
, version
);
238 HRESULT WINAPI
GetRequestedRuntimeInfo(LPCWSTR pExe
, LPCWSTR pwszVersion
, LPCWSTR pConfigurationFile
,
239 DWORD startupFlags
, DWORD runtimeInfoFlags
, LPWSTR pDirectory
, DWORD dwDirectory
, DWORD
*dwDirectoryLength
,
240 LPWSTR pVersion
, DWORD cchBuffer
, DWORD
*dwlength
)
242 FIXME("(%s, %s, %s, 0x%08x, 0x%08x, %p, 0x%08x, %p, %p, 0x%08x, %p) stub\n", debugstr_w(pExe
),
243 debugstr_w(pwszVersion
), debugstr_w(pConfigurationFile
), startupFlags
, runtimeInfoFlags
, pDirectory
,
244 dwDirectory
, dwDirectoryLength
, pVersion
, cchBuffer
, dwlength
);
245 return GetCORVersion(pVersion
, cchBuffer
, dwlength
);
248 HRESULT WINAPI
LoadLibraryShim( LPCWSTR szDllName
, LPCWSTR szVersion
, LPVOID pvReserved
, HMODULE
* phModDll
)
250 FIXME("(%p %s, %p, %p, %p): semi-stub\n", szDllName
, debugstr_w(szDllName
), szVersion
, pvReserved
, phModDll
);
252 if (phModDll
) *phModDll
= LoadLibraryW(szDllName
);
256 HRESULT WINAPI
CoInitializeCor(DWORD fFlags
)
258 FIXME("(0x%08x): stub\n", fFlags
);
262 HRESULT WINAPI
GetAssemblyMDImport(LPCWSTR szFileName
, REFIID riid
, IUnknown
**ppIUnk
)
264 FIXME("(%p %s, %p, %p): stub\n", szFileName
, debugstr_w(szFileName
), riid
, *ppIUnk
);
265 return ERROR_CALL_NOT_IMPLEMENTED
;