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");
102 HeapFree(GetProcessHeap(), 0, mono_exe
);
107 BOOL WINAPI
DllMain(HINSTANCE hinstDLL
, DWORD fdwReason
, LPVOID lpvReserved
)
109 TRACE("(%p, %d, %p)\n", hinstDLL
, fdwReason
, lpvReserved
);
113 case DLL_WINE_PREATTACH
:
114 return FALSE
; /* prefer native version */
115 case DLL_PROCESS_ATTACH
:
116 DisableThreadLibraryCalls(hinstDLL
);
118 case DLL_PROCESS_DETACH
:
124 BOOL WINAPI
_CorDllMain(HINSTANCE hinstDLL
, DWORD fdwReason
, LPVOID lpvReserved
)
126 FIXME("(%p, %d, %p): stub\n", hinstDLL
, fdwReason
, lpvReserved
);
130 case DLL_PROCESS_ATTACH
:
131 DisableThreadLibraryCalls(hinstDLL
);
133 case DLL_PROCESS_DETACH
:
139 __int32 WINAPI
_CorExeMain(void)
142 PROCESS_INFORMATION pi
;
143 WCHAR
*mono_exe
, *cmd_line
;
144 DWORD size
, exit_code
;
146 if (!(mono_exe
= get_mono_exe()))
148 MESSAGE("install the Windows version of Mono to run .NET executables\n");
152 size
= (lstrlenW(mono_exe
) + lstrlenW(GetCommandLineW()) + 1) * sizeof(WCHAR
);
153 if (!(cmd_line
= HeapAlloc(GetProcessHeap(), 0, size
)))
155 HeapFree(GetProcessHeap(), 0, mono_exe
);
159 lstrcpyW(cmd_line
, mono_exe
);
160 HeapFree(GetProcessHeap(), 0, mono_exe
);
161 lstrcatW(cmd_line
, GetCommandLineW());
163 TRACE("new command line: %s\n", debugstr_w(cmd_line
));
165 memset(&si
, 0, sizeof(si
));
167 if (!CreateProcessW(NULL
, cmd_line
, NULL
, NULL
, FALSE
, 0, NULL
, NULL
, &si
, &pi
))
169 HeapFree(GetProcessHeap(), 0, cmd_line
);
172 HeapFree(GetProcessHeap(), 0, cmd_line
);
174 /* wait for the process to exit */
175 WaitForSingleObject(pi
.hProcess
, INFINITE
);
176 GetExitCodeProcess(pi
.hProcess
, &exit_code
);
178 CloseHandle(pi
.hThread
);
179 CloseHandle(pi
.hProcess
);
181 return (int)exit_code
;
184 __int32 WINAPI
_CorExeMain2(PBYTE ptrMemory
, DWORD cntMemory
, LPWSTR imageName
, LPWSTR loaderName
, LPWSTR cmdLine
)
186 TRACE("(%p, %u, %s, %s, %s)\n", ptrMemory
, cntMemory
, debugstr_w(imageName
), debugstr_w(loaderName
), debugstr_w(cmdLine
));
187 FIXME("Directly running .NET applications not supported.\n");
191 void WINAPI
CorExitProcess(int exitCode
)
193 FIXME("(%x) stub\n", exitCode
);
194 ExitProcess(exitCode
);
197 VOID WINAPI
_CorImageUnloading(PVOID imageBase
)
199 TRACE("(%p): stub\n", imageBase
);
202 HRESULT WINAPI
_CorValidateImage(PVOID
* imageBase
, LPCWSTR imageName
)
204 TRACE("(%p, %s): stub\n", imageBase
, debugstr_w(imageName
));
208 HRESULT WINAPI
GetCORSystemDirectory(LPWSTR pbuffer
, DWORD cchBuffer
, DWORD
*dwLength
)
210 FIXME("(%p, %d, %p): stub!\n", pbuffer
, cchBuffer
, dwLength
);
220 HRESULT WINAPI
GetCORVersion(LPWSTR pbuffer
, DWORD cchBuffer
, DWORD
*dwLength
)
222 static const WCHAR version
[] = {'v','1','.','1','.','4','3','2','2',0};
224 FIXME("(%p, %d, %p): semi-stub!\n", pbuffer
, cchBuffer
, dwLength
);
229 *dwLength
= lstrlenW(version
);
231 if (cchBuffer
< *dwLength
)
232 return ERROR_INSUFFICIENT_BUFFER
;
235 lstrcpyW(pbuffer
, version
);
240 HRESULT WINAPI
GetRequestedRuntimeInfo(LPCWSTR pExe
, LPCWSTR pwszVersion
, LPCWSTR pConfigurationFile
,
241 DWORD startupFlags
, DWORD runtimeInfoFlags
, LPWSTR pDirectory
, DWORD dwDirectory
, DWORD
*dwDirectoryLength
,
242 LPWSTR pVersion
, DWORD cchBuffer
, DWORD
*dwlength
)
244 FIXME("(%s, %s, %s, 0x%08x, 0x%08x, %p, 0x%08x, %p, %p, 0x%08x, %p) stub\n", debugstr_w(pExe
),
245 debugstr_w(pwszVersion
), debugstr_w(pConfigurationFile
), startupFlags
, runtimeInfoFlags
, pDirectory
,
246 dwDirectory
, dwDirectoryLength
, pVersion
, cchBuffer
, dwlength
);
247 return GetCORVersion(pVersion
, cchBuffer
, dwlength
);
250 HRESULT WINAPI
LoadLibraryShim( LPCWSTR szDllName
, LPCWSTR szVersion
, LPVOID pvReserved
, HMODULE
* phModDll
)
252 FIXME("(%p %s, %p, %p, %p): semi-stub\n", szDllName
, debugstr_w(szDllName
), szVersion
, pvReserved
, phModDll
);
254 if (phModDll
) *phModDll
= LoadLibraryW(szDllName
);
258 HRESULT WINAPI
CoInitializeCor(DWORD fFlags
)
260 FIXME("(0x%08x): stub\n", fFlags
);
264 HRESULT WINAPI
GetAssemblyMDImport(LPCWSTR szFileName
, REFIID riid
, IUnknown
**ppIUnk
)
266 FIXME("(%p %s, %p, %p): stub\n", szFileName
, debugstr_w(szFileName
), riid
, *ppIUnk
);
267 return ERROR_CALL_NOT_IMPLEMENTED
;
270 HRESULT WINAPI
GetVersionFromProcess(HANDLE hProcess
, LPWSTR pVersion
, DWORD cchBuffer
, DWORD
*dwLength
)
272 FIXME("(%p, %p, %d, %p): stub\n", hProcess
, pVersion
, cchBuffer
, dwLength
);
276 HRESULT WINAPI
LoadStringRCEx(LCID culture
, UINT resId
, LPWSTR pBuffer
, int iBufLen
, int bQuiet
, int* pBufLen
)
279 if ((iBufLen
<= 0) || !pBuffer
)
283 FIXME("(%d, %x, %p, %d, %d, %p): semi-stub\n", culture
, resId
, pBuffer
, iBufLen
, bQuiet
, pBufLen
);
289 *pBufLen
= lstrlenW(pBuffer
);
293 HRESULT WINAPI
LoadStringRC(UINT resId
, LPWSTR pBuffer
, int iBufLen
, int bQuiet
)
295 return LoadStringRCEx(-1, resId
, pBuffer
, iBufLen
, bQuiet
, NULL
);
298 HRESULT WINAPI
DllGetClassObject(REFCLSID rclsid
, REFIID riid
, LPVOID
* ppv
)
300 FIXME("(%p, %p, %p): stub\n", rclsid
, riid
, ppv
);
307 HRESULT WINAPI
DllCanUnloadNow(VOID
)