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"
43 #include "wine/list.h"
44 #include "mscoree_private.h"
46 #include "wine/debug.h"
48 WINE_DEFAULT_DEBUG_CHANNEL( mscoree
);
52 char *WtoA(LPCWSTR wstr
)
57 length
= WideCharToMultiByte(CP_UTF8
, 0, wstr
, -1, NULL
, 0, NULL
, NULL
);
59 result
= HeapAlloc(GetProcessHeap(), 0, length
);
62 WideCharToMultiByte(CP_UTF8
, 0, wstr
, -1, result
, length
, NULL
, NULL
);
67 static BOOL
get_install_root(LPWSTR install_dir
)
69 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};
70 const WCHAR install_root
[] = {'I','n','s','t','a','l','l','R','o','o','t',0};
75 if (RegOpenKeyExW(HKEY_LOCAL_MACHINE
, dotnet_key
, 0, KEY_READ
, &key
))
79 if (RegQueryValueExW(key
, install_root
, 0, NULL
, (LPBYTE
)install_dir
, &len
))
89 HRESULT WINAPI
CorBindToRuntimeHost(LPCWSTR pwszVersion
, LPCWSTR pwszBuildFlavor
,
90 LPCWSTR pwszHostConfigFile
, VOID
*pReserved
,
91 DWORD startupFlags
, REFCLSID rclsid
,
92 REFIID riid
, LPVOID
*ppv
)
95 ICLRRuntimeInfo
*info
;
97 TRACE("(%s, %s, %s, %p, %d, %s, %s, %p)\n", debugstr_w(pwszVersion
),
98 debugstr_w(pwszBuildFlavor
), debugstr_w(pwszHostConfigFile
), pReserved
,
99 startupFlags
, debugstr_guid(rclsid
), debugstr_guid(riid
), ppv
);
103 ret
= get_runtime_info(NULL
, pwszVersion
, pwszHostConfigFile
, startupFlags
, 0, TRUE
, &info
);
107 ret
= ICLRRuntimeInfo_GetInterface(info
, rclsid
, riid
, ppv
);
109 ICLRRuntimeInfo_Release(info
);
115 BOOL WINAPI
DllMain(HINSTANCE hinstDLL
, DWORD fdwReason
, LPVOID lpvReserved
)
117 TRACE("(%p, %d, %p)\n", hinstDLL
, fdwReason
, lpvReserved
);
121 case DLL_WINE_PREATTACH
:
122 return FALSE
; /* prefer native version */
123 case DLL_PROCESS_ATTACH
:
124 DisableThreadLibraryCalls(hinstDLL
);
126 case DLL_PROCESS_DETACH
:
127 unload_all_runtimes();
133 BOOL WINAPI
_CorDllMain(HINSTANCE hinstDLL
, DWORD fdwReason
, LPVOID lpvReserved
)
135 FIXME("(%p, %d, %p): stub\n", hinstDLL
, fdwReason
, lpvReserved
);
139 case DLL_PROCESS_ATTACH
:
140 DisableThreadLibraryCalls(hinstDLL
);
142 case DLL_PROCESS_DETACH
:
148 __int32 WINAPI
_CorExeMain2(PBYTE ptrMemory
, DWORD cntMemory
, LPWSTR imageName
, LPWSTR loaderName
, LPWSTR cmdLine
)
150 TRACE("(%p, %u, %s, %s, %s)\n", ptrMemory
, cntMemory
, debugstr_w(imageName
), debugstr_w(loaderName
), debugstr_w(cmdLine
));
151 FIXME("Directly running .NET applications not supported.\n");
155 void WINAPI
CorExitProcess(int exitCode
)
157 FIXME("(%x) stub\n", exitCode
);
158 ExitProcess(exitCode
);
161 VOID WINAPI
_CorImageUnloading(PVOID imageBase
)
163 TRACE("(%p): stub\n", imageBase
);
166 HRESULT WINAPI
_CorValidateImage(PVOID
* imageBase
, LPCWSTR imageName
)
168 TRACE("(%p, %s): stub\n", imageBase
, debugstr_w(imageName
));
172 HRESULT WINAPI
GetCORSystemDirectory(LPWSTR pbuffer
, DWORD cchBuffer
, DWORD
*dwLength
)
174 ICLRRuntimeInfo
*info
;
177 TRACE("(%p, %d, %p)!\n", pbuffer
, cchBuffer
, dwLength
);
179 if (!dwLength
|| !pbuffer
)
182 ret
= get_runtime_info(NULL
, NULL
, NULL
, 0, RUNTIME_INFO_UPGRADE_VERSION
, TRUE
, &info
);
186 *dwLength
= cchBuffer
;
187 ret
= ICLRRuntimeInfo_GetRuntimeDirectory(info
, pbuffer
, dwLength
);
189 ICLRRuntimeInfo_Release(info
);
195 HRESULT WINAPI
GetCORVersion(LPWSTR pbuffer
, DWORD cchBuffer
, DWORD
*dwLength
)
197 ICLRRuntimeInfo
*info
;
200 TRACE("(%p, %d, %p)!\n", pbuffer
, cchBuffer
, dwLength
);
202 if (!dwLength
|| !pbuffer
)
205 ret
= get_runtime_info(NULL
, NULL
, NULL
, 0, RUNTIME_INFO_UPGRADE_VERSION
, TRUE
, &info
);
209 *dwLength
= cchBuffer
;
210 ret
= ICLRRuntimeInfo_GetVersionString(info
, pbuffer
, dwLength
);
212 ICLRRuntimeInfo_Release(info
);
218 HRESULT WINAPI
GetRequestedRuntimeInfo(LPCWSTR pExe
, LPCWSTR pwszVersion
, LPCWSTR pConfigurationFile
,
219 DWORD startupFlags
, DWORD runtimeInfoFlags
, LPWSTR pDirectory
, DWORD dwDirectory
, DWORD
*dwDirectoryLength
,
220 LPWSTR pVersion
, DWORD cchBuffer
, DWORD
*dwlength
)
223 ICLRRuntimeInfo
*info
;
226 TRACE("(%s, %s, %s, 0x%08x, 0x%08x, %p, 0x%08x, %p, %p, 0x%08x, %p)\n", debugstr_w(pExe
),
227 debugstr_w(pwszVersion
), debugstr_w(pConfigurationFile
), startupFlags
, runtimeInfoFlags
, pDirectory
,
228 dwDirectory
, dwDirectoryLength
, pVersion
, cchBuffer
, dwlength
);
230 if (!dwDirectoryLength
) dwDirectoryLength
= &length_dummy
;
232 if (!dwlength
) dwlength
= &length_dummy
;
234 ret
= get_runtime_info(pExe
, pwszVersion
, pConfigurationFile
, startupFlags
, runtimeInfoFlags
, TRUE
, &info
);
238 *dwlength
= cchBuffer
;
239 ret
= ICLRRuntimeInfo_GetVersionString(info
, pVersion
, dwlength
);
243 *dwDirectoryLength
= dwDirectory
;
244 ret
= ICLRRuntimeInfo_GetRuntimeDirectory(info
, pDirectory
, dwDirectoryLength
);
247 ICLRRuntimeInfo_Release(info
);
253 HRESULT WINAPI
LoadLibraryShim( LPCWSTR szDllName
, LPCWSTR szVersion
, LPVOID pvReserved
, HMODULE
* phModDll
)
256 WCHAR dll_filename
[MAX_PATH
];
257 WCHAR version
[MAX_PATH
];
258 static const WCHAR default_version
[] = {'v','1','.','1','.','4','3','2','2',0};
259 static const WCHAR slash
[] = {'\\',0};
262 TRACE("(%p %s, %p, %p, %p)\n", szDllName
, debugstr_w(szDllName
), szVersion
, pvReserved
, phModDll
);
264 if (!szDllName
|| !phModDll
)
267 if (!get_install_root(dll_filename
))
269 ERR("error reading registry key for installroot\n");
276 ret
= GetCORVersion(version
, MAX_PATH
, &dummy
);
280 szVersion
= default_version
;
282 strcatW(dll_filename
, szVersion
);
283 strcatW(dll_filename
, slash
);
286 strcatW(dll_filename
, szDllName
);
288 *phModDll
= LoadLibraryW(dll_filename
);
290 return *phModDll
? S_OK
: E_HANDLE
;
293 HRESULT WINAPI
LockClrVersion(FLockClrVersionCallback hostCallback
, FLockClrVersionCallback
*pBeginHostSetup
, FLockClrVersionCallback
*pEndHostSetup
)
295 FIXME("(%p %p %p): stub\n", hostCallback
, pBeginHostSetup
, pEndHostSetup
);
299 HRESULT WINAPI
CoInitializeCor(DWORD fFlags
)
301 FIXME("(0x%08x): stub\n", fFlags
);
305 HRESULT WINAPI
GetAssemblyMDImport(LPCWSTR szFileName
, REFIID riid
, IUnknown
**ppIUnk
)
307 FIXME("(%p %s, %s, %p): stub\n", szFileName
, debugstr_w(szFileName
), debugstr_guid(riid
), *ppIUnk
);
308 return ERROR_CALL_NOT_IMPLEMENTED
;
311 HRESULT WINAPI
GetVersionFromProcess(HANDLE hProcess
, LPWSTR pVersion
, DWORD cchBuffer
, DWORD
*dwLength
)
313 FIXME("(%p, %p, %d, %p): stub\n", hProcess
, pVersion
, cchBuffer
, dwLength
);
317 HRESULT WINAPI
LoadStringRCEx(LCID culture
, UINT resId
, LPWSTR pBuffer
, int iBufLen
, int bQuiet
, int* pBufLen
)
320 if ((iBufLen
<= 0) || !pBuffer
)
324 FIXME("(%d, %x, %p, %d, %d, %p): semi-stub\n", culture
, resId
, pBuffer
, iBufLen
, bQuiet
, pBufLen
);
330 *pBufLen
= lstrlenW(pBuffer
);
334 HRESULT WINAPI
LoadStringRC(UINT resId
, LPWSTR pBuffer
, int iBufLen
, int bQuiet
)
336 return LoadStringRCEx(-1, resId
, pBuffer
, iBufLen
, bQuiet
, NULL
);
339 HRESULT WINAPI
CorBindToRuntimeEx(LPWSTR szVersion
, LPWSTR szBuildFlavor
, DWORD nflags
, REFCLSID rslsid
,
340 REFIID riid
, LPVOID
*ppv
)
343 ICLRRuntimeInfo
*info
;
345 TRACE("%s %s %d %s %s %p\n", debugstr_w(szVersion
), debugstr_w(szBuildFlavor
), nflags
, debugstr_guid( rslsid
),
346 debugstr_guid( riid
), ppv
);
350 ret
= get_runtime_info(NULL
, szVersion
, NULL
, nflags
, 0, TRUE
, &info
);
354 ret
= ICLRRuntimeInfo_GetInterface(info
, rslsid
, riid
, ppv
);
356 ICLRRuntimeInfo_Release(info
);
362 HRESULT WINAPI
CorBindToCurrentRuntime(LPCWSTR filename
, REFCLSID rclsid
, REFIID riid
, LPVOID
*ppv
)
364 FIXME("(%s, %s, %s, %p): stub\n", debugstr_w(filename
), debugstr_guid(rclsid
), debugstr_guid(riid
), ppv
);
368 STDAPI
ClrCreateManagedInstance(LPCWSTR pTypeName
, REFIID riid
, void **ppObject
)
371 ICLRRuntimeInfo
*info
;
376 TRACE("(%s,%s,%p)\n", debugstr_w(pTypeName
), debugstr_guid(riid
), ppObject
);
378 /* FIXME: How to determine which runtime version to use? */
379 ret
= get_runtime_info(NULL
, NULL
, NULL
, 0, RUNTIME_INFO_UPGRADE_VERSION
, TRUE
, &info
);
383 ret
= ICLRRuntimeInfo_GetRuntimeHost(info
, &host
);
385 ICLRRuntimeInfo_Release(info
);
389 ret
= RuntimeHost_CreateManagedInstance(host
, pTypeName
, NULL
, &obj
);
392 ret
= RuntimeHost_GetIUnknownForObject(host
, obj
, &unk
);
396 ret
= IUnknown_QueryInterface(unk
, riid
, ppObject
);
397 IUnknown_Release(unk
);
403 BOOL WINAPI
StrongNameSignatureVerification(LPCWSTR filename
, DWORD inFlags
, DWORD
* pOutFlags
)
405 FIXME("(%s, 0x%X, %p): stub\n", debugstr_w(filename
), inFlags
, pOutFlags
);
409 BOOL WINAPI
StrongNameSignatureVerificationEx(LPCWSTR filename
, BOOL forceVerification
, BOOL
* pVerified
)
411 FIXME("(%s, %u, %p): stub\n", debugstr_w(filename
), forceVerification
, pVerified
);
415 HRESULT WINAPI
CLRCreateInstance(REFCLSID clsid
, REFIID riid
, LPVOID
*ppInterface
)
417 TRACE("(%s,%s,%p)\n", debugstr_guid(clsid
), debugstr_guid(riid
), ppInterface
);
419 if (IsEqualGUID(clsid
, &CLSID_CLRMetaHost
))
420 return CLRMetaHost_CreateInstance(riid
, ppInterface
);
422 FIXME("not implemented for class %s\n", debugstr_guid(clsid
));
424 return CLASS_E_CLASSNOTAVAILABLE
;
427 HRESULT WINAPI
DllGetClassObject(REFCLSID rclsid
, REFIID riid
, LPVOID
* ppv
)
429 FIXME("(%s, %s, %p): stub\n", debugstr_guid(rclsid
), debugstr_guid(riid
), ppv
);
436 HRESULT WINAPI
DllRegisterServer(void)
442 HRESULT WINAPI
DllUnregisterServer(void)
448 HRESULT WINAPI
DllCanUnloadNow(VOID
)
456 INT WINAPI
ND_RU1( const void *ptr
, INT offset
)
458 return *((const BYTE
*)ptr
+ offset
);
461 INT WINAPI
ND_RI2( const void *ptr
, INT offset
)
463 return *(const SHORT
*)((const BYTE
*)ptr
+ offset
);
466 INT WINAPI
ND_RI4( const void *ptr
, INT offset
)
468 return *(const INT
*)((const BYTE
*)ptr
+ offset
);
471 INT64 WINAPI
ND_RI8( const void *ptr
, INT offset
)
473 return *(const INT64
*)((const BYTE
*)ptr
+ offset
);
476 void WINAPI
ND_WU1( void *ptr
, INT offset
, BYTE val
)
478 *((BYTE
*)ptr
+ offset
) = val
;
481 void WINAPI
ND_WI2( void *ptr
, INT offset
, SHORT val
)
483 *(SHORT
*)((BYTE
*)ptr
+ offset
) = val
;
486 void WINAPI
ND_WI4( void *ptr
, INT offset
, INT val
)
488 *(INT
*)((BYTE
*)ptr
+ offset
) = val
;
491 void WINAPI
ND_WI8( void *ptr
, INT offset
, INT64 val
)
493 *(INT64
*)((BYTE
*)ptr
+ offset
) = val
;
496 void WINAPI
ND_CopyObjDst( const void *src
, void *dst
, INT offset
, INT size
)
498 memcpy( (BYTE
*)dst
+ offset
, src
, size
);
501 void WINAPI
ND_CopyObjSrc( const void *src
, INT offset
, void *dst
, INT size
)
503 memcpy( dst
, (const BYTE
*)src
+ offset
, size
);