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
25 #include "wine/unicode.h"
26 #include "wine/library.h"
45 #include "wine/list.h"
46 #include "mscoree_private.h"
48 #include "wine/debug.h"
50 WINE_DEFAULT_DEBUG_CHANNEL( mscoree
);
54 char *WtoA(LPCWSTR wstr
)
59 length
= WideCharToMultiByte(CP_UTF8
, 0, wstr
, -1, NULL
, 0, NULL
, NULL
);
61 result
= HeapAlloc(GetProcessHeap(), 0, length
);
64 WideCharToMultiByte(CP_UTF8
, 0, wstr
, -1, result
, length
, NULL
, NULL
);
69 static BOOL
get_install_root(LPWSTR install_dir
)
71 const WCHAR dotnet_key
[] = {'S','O','F','T','W','A','R','E','\\','M','i','c','r','o','s','o','f','t','\\','.','N','E','T','F','r','a','m','e','w','o','r','k','\\',0};
72 const WCHAR install_root
[] = {'I','n','s','t','a','l','l','R','o','o','t',0};
77 if (RegOpenKeyExW(HKEY_LOCAL_MACHINE
, dotnet_key
, 0, KEY_READ
, &key
))
81 if (RegQueryValueExW(key
, install_root
, 0, NULL
, (LPBYTE
)install_dir
, &len
))
91 HRESULT WINAPI
CorBindToRuntimeHost(LPCWSTR pwszVersion
, LPCWSTR pwszBuildFlavor
,
92 LPCWSTR pwszHostConfigFile
, VOID
*pReserved
,
93 DWORD startupFlags
, REFCLSID rclsid
,
94 REFIID riid
, LPVOID
*ppv
)
97 ICLRRuntimeInfo
*info
;
99 TRACE("(%s, %s, %s, %p, %d, %s, %s, %p)\n", debugstr_w(pwszVersion
),
100 debugstr_w(pwszBuildFlavor
), debugstr_w(pwszHostConfigFile
), pReserved
,
101 startupFlags
, debugstr_guid(rclsid
), debugstr_guid(riid
), ppv
);
105 ret
= get_runtime_info(NULL
, pwszVersion
, pwszHostConfigFile
, startupFlags
, 0, TRUE
, &info
);
109 ret
= ICLRRuntimeInfo_GetInterface(info
, rclsid
, riid
, ppv
);
111 ICLRRuntimeInfo_Release(info
);
117 BOOL WINAPI
DllMain(HINSTANCE hinstDLL
, DWORD fdwReason
, LPVOID lpvReserved
)
119 TRACE("(%p, %d, %p)\n", hinstDLL
, fdwReason
, lpvReserved
);
123 case DLL_WINE_PREATTACH
:
124 return FALSE
; /* prefer native version */
125 case DLL_PROCESS_ATTACH
:
126 DisableThreadLibraryCalls(hinstDLL
);
128 case DLL_PROCESS_DETACH
:
129 unload_all_runtimes();
135 BOOL WINAPI
_CorDllMain(HINSTANCE hinstDLL
, DWORD fdwReason
, LPVOID lpvReserved
)
137 FIXME("(%p, %d, %p): stub\n", hinstDLL
, fdwReason
, lpvReserved
);
141 case DLL_PROCESS_ATTACH
:
142 DisableThreadLibraryCalls(hinstDLL
);
144 case DLL_PROCESS_DETACH
:
150 __int32 WINAPI
_CorExeMain2(PBYTE ptrMemory
, DWORD cntMemory
, LPWSTR imageName
, LPWSTR loaderName
, LPWSTR cmdLine
)
152 TRACE("(%p, %u, %s, %s, %s)\n", ptrMemory
, cntMemory
, debugstr_w(imageName
), debugstr_w(loaderName
), debugstr_w(cmdLine
));
153 FIXME("Directly running .NET applications not supported.\n");
157 void WINAPI
CorExitProcess(int exitCode
)
159 FIXME("(%x) stub\n", exitCode
);
160 ExitProcess(exitCode
);
163 VOID WINAPI
_CorImageUnloading(PVOID imageBase
)
165 TRACE("(%p): stub\n", imageBase
);
168 HRESULT WINAPI
_CorValidateImage(PVOID
* imageBase
, LPCWSTR imageName
)
170 TRACE("(%p, %s): stub\n", imageBase
, debugstr_w(imageName
));
174 HRESULT WINAPI
GetCORSystemDirectory(LPWSTR pbuffer
, DWORD cchBuffer
, DWORD
*dwLength
)
176 ICLRRuntimeInfo
*info
;
179 TRACE("(%p, %d, %p)!\n", pbuffer
, cchBuffer
, dwLength
);
181 if (!dwLength
|| !pbuffer
)
184 ret
= get_runtime_info(NULL
, NULL
, NULL
, 0, RUNTIME_INFO_UPGRADE_VERSION
, TRUE
, &info
);
188 *dwLength
= cchBuffer
;
189 ret
= ICLRRuntimeInfo_GetRuntimeDirectory(info
, pbuffer
, dwLength
);
191 ICLRRuntimeInfo_Release(info
);
197 HRESULT WINAPI
GetCORVersion(LPWSTR pbuffer
, DWORD cchBuffer
, DWORD
*dwLength
)
199 ICLRRuntimeInfo
*info
;
202 TRACE("(%p, %d, %p)!\n", pbuffer
, cchBuffer
, dwLength
);
204 if (!dwLength
|| !pbuffer
)
207 ret
= get_runtime_info(NULL
, NULL
, NULL
, 0, RUNTIME_INFO_UPGRADE_VERSION
, TRUE
, &info
);
211 *dwLength
= cchBuffer
;
212 ret
= ICLRRuntimeInfo_GetVersionString(info
, pbuffer
, dwLength
);
214 ICLRRuntimeInfo_Release(info
);
220 HRESULT WINAPI
GetRequestedRuntimeInfo(LPCWSTR pExe
, LPCWSTR pwszVersion
, LPCWSTR pConfigurationFile
,
221 DWORD startupFlags
, DWORD runtimeInfoFlags
, LPWSTR pDirectory
, DWORD dwDirectory
, DWORD
*dwDirectoryLength
,
222 LPWSTR pVersion
, DWORD cchBuffer
, DWORD
*dwlength
)
225 ICLRRuntimeInfo
*info
;
228 TRACE("(%s, %s, %s, 0x%08x, 0x%08x, %p, 0x%08x, %p, %p, 0x%08x, %p)\n", debugstr_w(pExe
),
229 debugstr_w(pwszVersion
), debugstr_w(pConfigurationFile
), startupFlags
, runtimeInfoFlags
, pDirectory
,
230 dwDirectory
, dwDirectoryLength
, pVersion
, cchBuffer
, dwlength
);
232 if (!dwDirectoryLength
) dwDirectoryLength
= &length_dummy
;
234 if (!dwlength
) dwlength
= &length_dummy
;
236 ret
= get_runtime_info(pExe
, pwszVersion
, pConfigurationFile
, startupFlags
, runtimeInfoFlags
, TRUE
, &info
);
240 *dwlength
= cchBuffer
;
241 ret
= ICLRRuntimeInfo_GetVersionString(info
, pVersion
, dwlength
);
245 *dwDirectoryLength
= dwDirectory
;
246 ret
= ICLRRuntimeInfo_GetRuntimeDirectory(info
, pDirectory
, dwDirectoryLength
);
249 ICLRRuntimeInfo_Release(info
);
255 HRESULT WINAPI
LoadLibraryShim( LPCWSTR szDllName
, LPCWSTR szVersion
, LPVOID pvReserved
, HMODULE
* phModDll
)
258 WCHAR dll_filename
[MAX_PATH
];
259 WCHAR version
[MAX_PATH
];
260 static const WCHAR default_version
[] = {'v','1','.','1','.','4','3','2','2',0};
261 static const WCHAR slash
[] = {'\\',0};
264 TRACE("(%p %s, %p, %p, %p)\n", szDllName
, debugstr_w(szDllName
), szVersion
, pvReserved
, phModDll
);
266 if (!szDllName
|| !phModDll
)
269 if (!get_install_root(dll_filename
))
271 ERR("error reading registry key for installroot\n");
278 ret
= GetCORVersion(version
, MAX_PATH
, &dummy
);
282 szVersion
= default_version
;
284 strcatW(dll_filename
, szVersion
);
285 strcatW(dll_filename
, slash
);
288 strcatW(dll_filename
, szDllName
);
290 *phModDll
= LoadLibraryW(dll_filename
);
292 return *phModDll
? S_OK
: E_HANDLE
;
295 HRESULT WINAPI
LockClrVersion(FLockClrVersionCallback hostCallback
, FLockClrVersionCallback
*pBeginHostSetup
, FLockClrVersionCallback
*pEndHostSetup
)
297 FIXME("(%p %p %p): stub\n", hostCallback
, pBeginHostSetup
, pEndHostSetup
);
301 HRESULT WINAPI
CoInitializeCor(DWORD fFlags
)
303 FIXME("(0x%08x): stub\n", fFlags
);
307 HRESULT WINAPI
GetAssemblyMDImport(LPCWSTR szFileName
, REFIID riid
, IUnknown
**ppIUnk
)
309 FIXME("(%p %s, %s, %p): stub\n", szFileName
, debugstr_w(szFileName
), debugstr_guid(riid
), *ppIUnk
);
310 return ERROR_CALL_NOT_IMPLEMENTED
;
313 HRESULT WINAPI
GetVersionFromProcess(HANDLE hProcess
, LPWSTR pVersion
, DWORD cchBuffer
, DWORD
*dwLength
)
315 FIXME("(%p, %p, %d, %p): stub\n", hProcess
, pVersion
, cchBuffer
, dwLength
);
319 HRESULT WINAPI
LoadStringRCEx(LCID culture
, UINT resId
, LPWSTR pBuffer
, int iBufLen
, int bQuiet
, int* pBufLen
)
322 if ((iBufLen
<= 0) || !pBuffer
)
326 FIXME("(%d, %x, %p, %d, %d, %p): semi-stub\n", culture
, resId
, pBuffer
, iBufLen
, bQuiet
, pBufLen
);
332 *pBufLen
= lstrlenW(pBuffer
);
336 HRESULT WINAPI
LoadStringRC(UINT resId
, LPWSTR pBuffer
, int iBufLen
, int bQuiet
)
338 return LoadStringRCEx(-1, resId
, pBuffer
, iBufLen
, bQuiet
, NULL
);
341 HRESULT WINAPI
CorBindToRuntimeEx(LPWSTR szVersion
, LPWSTR szBuildFlavor
, DWORD nflags
, REFCLSID rslsid
,
342 REFIID riid
, LPVOID
*ppv
)
345 ICLRRuntimeInfo
*info
;
347 TRACE("%s %s %d %s %s %p\n", debugstr_w(szVersion
), debugstr_w(szBuildFlavor
), nflags
, debugstr_guid( rslsid
),
348 debugstr_guid( riid
), ppv
);
352 ret
= get_runtime_info(NULL
, szVersion
, NULL
, nflags
, 0, TRUE
, &info
);
356 ret
= ICLRRuntimeInfo_GetInterface(info
, rslsid
, riid
, ppv
);
358 ICLRRuntimeInfo_Release(info
);
364 HRESULT WINAPI
CorBindToCurrentRuntime(LPCWSTR filename
, REFCLSID rclsid
, REFIID riid
, LPVOID
*ppv
)
366 FIXME("(%s, %s, %s, %p): stub\n", debugstr_w(filename
), debugstr_guid(rclsid
), debugstr_guid(riid
), ppv
);
370 STDAPI
ClrCreateManagedInstance(LPCWSTR pTypeName
, REFIID riid
, void **ppObject
)
373 ICLRRuntimeInfo
*info
;
378 TRACE("(%s,%s,%p)\n", debugstr_w(pTypeName
), debugstr_guid(riid
), ppObject
);
380 /* FIXME: How to determine which runtime version to use? */
381 ret
= get_runtime_info(NULL
, NULL
, NULL
, 0, RUNTIME_INFO_UPGRADE_VERSION
, TRUE
, &info
);
385 ret
= ICLRRuntimeInfo_GetRuntimeHost(info
, &host
);
387 ICLRRuntimeInfo_Release(info
);
391 ret
= RuntimeHost_CreateManagedInstance(host
, pTypeName
, NULL
, &obj
);
394 ret
= RuntimeHost_GetIUnknownForObject(host
, obj
, &unk
);
398 ret
= IUnknown_QueryInterface(unk
, riid
, ppObject
);
399 IUnknown_Release(unk
);
405 BOOL WINAPI
StrongNameSignatureVerification(LPCWSTR filename
, DWORD inFlags
, DWORD
* pOutFlags
)
407 FIXME("(%s, 0x%X, %p): stub\n", debugstr_w(filename
), inFlags
, pOutFlags
);
411 BOOL WINAPI
StrongNameSignatureVerificationEx(LPCWSTR filename
, BOOL forceVerification
, BOOL
* pVerified
)
413 FIXME("(%s, %u, %p): stub\n", debugstr_w(filename
), forceVerification
, pVerified
);
417 HRESULT WINAPI
CLRCreateInstance(REFCLSID clsid
, REFIID riid
, LPVOID
*ppInterface
)
419 TRACE("(%s,%s,%p)\n", debugstr_guid(clsid
), debugstr_guid(riid
), ppInterface
);
421 if (IsEqualGUID(clsid
, &CLSID_CLRMetaHost
))
422 return CLRMetaHost_CreateInstance(riid
, ppInterface
);
424 FIXME("not implemented for class %s\n", debugstr_guid(clsid
));
426 return CLASS_E_CLASSNOTAVAILABLE
;
429 HRESULT WINAPI
DllGetClassObject(REFCLSID rclsid
, REFIID riid
, LPVOID
* ppv
)
431 FIXME("(%s, %s, %p): stub\n", debugstr_guid(rclsid
), debugstr_guid(riid
), ppv
);
438 HRESULT WINAPI
DllRegisterServer(void)
444 HRESULT WINAPI
DllUnregisterServer(void)
450 HRESULT WINAPI
DllCanUnloadNow(VOID
)
458 INT WINAPI
ND_RU1( const void *ptr
, INT offset
)
460 return *((const BYTE
*)ptr
+ offset
);
463 INT WINAPI
ND_RI2( const void *ptr
, INT offset
)
465 return *(const SHORT
*)((const BYTE
*)ptr
+ offset
);
468 INT WINAPI
ND_RI4( const void *ptr
, INT offset
)
470 return *(const INT
*)((const BYTE
*)ptr
+ offset
);
473 INT64 WINAPI
ND_RI8( const void *ptr
, INT offset
)
475 return *(const INT64
*)((const BYTE
*)ptr
+ offset
);
478 void WINAPI
ND_WU1( void *ptr
, INT offset
, BYTE val
)
480 *((BYTE
*)ptr
+ offset
) = val
;
483 void WINAPI
ND_WI2( void *ptr
, INT offset
, SHORT val
)
485 *(SHORT
*)((BYTE
*)ptr
+ offset
) = val
;
488 void WINAPI
ND_WI4( void *ptr
, INT offset
, INT val
)
490 *(INT
*)((BYTE
*)ptr
+ offset
) = val
;
493 void WINAPI
ND_WI8( void *ptr
, INT offset
, INT64 val
)
495 *(INT64
*)((BYTE
*)ptr
+ offset
) = val
;
498 void WINAPI
ND_CopyObjDst( const void *src
, void *dst
, INT offset
, INT size
)
500 memcpy( (BYTE
*)dst
+ offset
, src
, size
);
503 void WINAPI
ND_CopyObjSrc( const void *src
, INT offset
, void *dst
, INT size
)
505 memcpy( dst
, (const BYTE
*)src
+ offset
, size
);