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
;
148 if (!(mono_exe
= get_mono_exe()))
150 MESSAGE("install the Windows version of Mono to run .NET executables\n");
154 size
= (lstrlenW(mono_exe
) + lstrlenW(GetCommandLineW()) + 1) * sizeof(WCHAR
);
155 if (!(cmd_line
= HeapAlloc(GetProcessHeap(), 0, size
)))
157 HeapFree(GetProcessHeap(), 0, mono_exe
);
161 lstrcpyW(cmd_line
, mono_exe
);
162 HeapFree(GetProcessHeap(), 0, mono_exe
);
163 lstrcatW(cmd_line
, GetCommandLineW());
165 TRACE("new command line: %s\n", debugstr_w(cmd_line
));
167 memset(&si
, 0, sizeof(si
));
169 if (!CreateProcessW(NULL
, cmd_line
, NULL
, NULL
, FALSE
, 0, NULL
, NULL
, &si
, &pi
))
171 HeapFree(GetProcessHeap(), 0, cmd_line
);
174 HeapFree(GetProcessHeap(), 0, cmd_line
);
176 /* wait for the process to exit */
177 WaitForSingleObject(pi
.hProcess
, INFINITE
);
178 GetExitCodeProcess(pi
.hProcess
, &exit_code
);
180 CloseHandle(pi
.hThread
);
181 CloseHandle(pi
.hProcess
);
183 return (int)exit_code
;
186 __int32 WINAPI
_CorExeMain2(PBYTE ptrMemory
, DWORD cntMemory
, LPWSTR imageName
, LPWSTR loaderName
, LPWSTR cmdLine
)
188 TRACE("(%p, %u, %s, %s, %s)\n", ptrMemory
, cntMemory
, debugstr_w(imageName
), debugstr_w(loaderName
), debugstr_w(cmdLine
));
189 FIXME("Directly running .NET applications not supported.\n");
193 void WINAPI
CorExitProcess(int exitCode
)
195 FIXME("(%x) stub\n", exitCode
);
196 ExitProcess(exitCode
);
199 VOID WINAPI
_CorImageUnloading(PVOID imageBase
)
201 TRACE("(%p): stub\n", imageBase
);
204 HRESULT WINAPI
_CorValidateImage(PVOID
* imageBase
, LPCWSTR imageName
)
206 TRACE("(%p, %s): stub\n", imageBase
, debugstr_w(imageName
));
210 HRESULT WINAPI
GetCORSystemDirectory(LPWSTR pbuffer
, DWORD cchBuffer
, DWORD
*dwLength
)
212 FIXME("(%p, %d, %p): stub!\n", pbuffer
, cchBuffer
, dwLength
);
222 HRESULT WINAPI
GetCORVersion(LPWSTR pbuffer
, DWORD cchBuffer
, DWORD
*dwLength
)
224 static const WCHAR version
[] = {'v','1','.','1','.','4','3','2','2',0};
226 FIXME("(%p, %d, %p): semi-stub!\n", pbuffer
, cchBuffer
, dwLength
);
231 *dwLength
= lstrlenW(version
);
233 if (cchBuffer
< *dwLength
)
234 return ERROR_INSUFFICIENT_BUFFER
;
237 lstrcpyW(pbuffer
, version
);
242 HRESULT WINAPI
GetRequestedRuntimeInfo(LPCWSTR pExe
, LPCWSTR pwszVersion
, LPCWSTR pConfigurationFile
,
243 DWORD startupFlags
, DWORD runtimeInfoFlags
, LPWSTR pDirectory
, DWORD dwDirectory
, DWORD
*dwDirectoryLength
,
244 LPWSTR pVersion
, DWORD cchBuffer
, DWORD
*dwlength
)
246 FIXME("(%s, %s, %s, 0x%08x, 0x%08x, %p, 0x%08x, %p, %p, 0x%08x, %p) stub\n", debugstr_w(pExe
),
247 debugstr_w(pwszVersion
), debugstr_w(pConfigurationFile
), startupFlags
, runtimeInfoFlags
, pDirectory
,
248 dwDirectory
, dwDirectoryLength
, pVersion
, cchBuffer
, dwlength
);
249 return GetCORVersion(pVersion
, cchBuffer
, dwlength
);
252 HRESULT WINAPI
LoadLibraryShim( LPCWSTR szDllName
, LPCWSTR szVersion
, LPVOID pvReserved
, HMODULE
* phModDll
)
254 FIXME("(%p %s, %p, %p, %p): semi-stub\n", szDllName
, debugstr_w(szDllName
), szVersion
, pvReserved
, phModDll
);
256 if (phModDll
) *phModDll
= LoadLibraryW(szDllName
);
260 HRESULT WINAPI
LockClrVersion(FLockClrVersionCallback hostCallback
, FLockClrVersionCallback
*pBeginHostSetup
, FLockClrVersionCallback
*pEndHostSetup
)
262 FIXME("(%p %p %p): stub\n", hostCallback
, pBeginHostSetup
, pEndHostSetup
);
266 HRESULT WINAPI
CoInitializeCor(DWORD fFlags
)
268 FIXME("(0x%08x): stub\n", fFlags
);
272 HRESULT WINAPI
GetAssemblyMDImport(LPCWSTR szFileName
, REFIID riid
, IUnknown
**ppIUnk
)
274 FIXME("(%p %s, %p, %p): stub\n", szFileName
, debugstr_w(szFileName
), riid
, *ppIUnk
);
275 return ERROR_CALL_NOT_IMPLEMENTED
;
278 HRESULT WINAPI
GetVersionFromProcess(HANDLE hProcess
, LPWSTR pVersion
, DWORD cchBuffer
, DWORD
*dwLength
)
280 FIXME("(%p, %p, %d, %p): stub\n", hProcess
, pVersion
, cchBuffer
, dwLength
);
284 HRESULT WINAPI
LoadStringRCEx(LCID culture
, UINT resId
, LPWSTR pBuffer
, int iBufLen
, int bQuiet
, int* pBufLen
)
287 if ((iBufLen
<= 0) || !pBuffer
)
291 FIXME("(%d, %x, %p, %d, %d, %p): semi-stub\n", culture
, resId
, pBuffer
, iBufLen
, bQuiet
, pBufLen
);
297 *pBufLen
= lstrlenW(pBuffer
);
301 HRESULT WINAPI
LoadStringRC(UINT resId
, LPWSTR pBuffer
, int iBufLen
, int bQuiet
)
303 return LoadStringRCEx(-1, resId
, pBuffer
, iBufLen
, bQuiet
, NULL
);
306 HRESULT WINAPI
CorBindToRuntimeEx(LPWSTR szVersion
, LPWSTR szBuildFlavor
, DWORD nflags
, REFCLSID rslsid
,
307 REFIID riid
, LPVOID
*ppv
)
309 FIXME("%s %s %d %s %s %p\n", debugstr_w(szVersion
), debugstr_w(szBuildFlavor
), nflags
, debugstr_guid( rslsid
),
310 debugstr_guid( riid
), ppv
);
312 if(IsEqualGUID( riid
, &IID_ICorRuntimeHost
))
314 *ppv
= create_corruntimehost();
321 HRESULT WINAPI
CorBindToCurrentRuntime(LPCWSTR filename
, REFCLSID rclsid
, REFIID riid
, LPVOID
*ppv
)
323 FIXME("(%s, %s, %s, %p): stub\n", debugstr_w(filename
), debugstr_guid(rclsid
), debugstr_guid(riid
), ppv
);
327 HRESULT WINAPI
DllGetClassObject(REFCLSID rclsid
, REFIID riid
, LPVOID
* ppv
)
329 FIXME("(%p, %p, %p): stub\n", rclsid
, riid
, ppv
);
336 HRESULT WINAPI
DllCanUnloadNow(VOID
)
342 INT WINAPI
ND_RU1( const void *ptr
, INT offset
)
344 return *((const BYTE
*)ptr
+ offset
);
347 INT WINAPI
ND_RI2( const void *ptr
, INT offset
)
349 return *(const SHORT
*)((const BYTE
*)ptr
+ offset
);
352 INT WINAPI
ND_RI4( const void *ptr
, INT offset
)
354 return *(const INT
*)((const BYTE
*)ptr
+ offset
);
357 INT64 WINAPI
ND_RI8( const void *ptr
, INT offset
)
359 return *(const INT64
*)((const BYTE
*)ptr
+ offset
);
362 void WINAPI
ND_WU1( void *ptr
, INT offset
, BYTE val
)
364 *((BYTE
*)ptr
+ offset
) = val
;
367 void WINAPI
ND_WI2( void *ptr
, INT offset
, SHORT val
)
369 *(SHORT
*)((BYTE
*)ptr
+ offset
) = val
;
372 void WINAPI
ND_WI4( void *ptr
, INT offset
, INT val
)
374 *(INT
*)((BYTE
*)ptr
+ offset
) = val
;
377 void WINAPI
ND_WI8( void *ptr
, INT offset
, INT64 val
)
379 *(INT64
*)((BYTE
*)ptr
+ offset
) = val
;
382 void WINAPI
ND_CopyObjDst( const void *src
, void *dst
, INT offset
, INT size
)
384 memcpy( (BYTE
*)dst
+ offset
, src
, size
);
387 void WINAPI
ND_CopyObjSrc( const void *src
, INT offset
, void *dst
, INT size
)
389 memcpy( dst
, (const BYTE
*)src
+ offset
, size
);