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
);
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 expect_no_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 TRACE("(%x)\n", exitCode
);
158 unload_all_runtimes();
159 ExitProcess(exitCode
);
162 VOID WINAPI
_CorImageUnloading(PVOID imageBase
)
164 TRACE("(%p): stub\n", imageBase
);
167 HRESULT WINAPI
_CorValidateImage(PVOID
* imageBase
, LPCWSTR imageName
)
169 TRACE("(%p, %s): stub\n", imageBase
, debugstr_w(imageName
));
173 HRESULT WINAPI
GetCORSystemDirectory(LPWSTR pbuffer
, DWORD cchBuffer
, DWORD
*dwLength
)
175 ICLRRuntimeInfo
*info
;
178 TRACE("(%p, %d, %p)!\n", pbuffer
, cchBuffer
, dwLength
);
180 if (!dwLength
|| !pbuffer
)
183 ret
= get_runtime_info(NULL
, NULL
, NULL
, 0, RUNTIME_INFO_UPGRADE_VERSION
, TRUE
, &info
);
187 *dwLength
= cchBuffer
;
188 ret
= ICLRRuntimeInfo_GetRuntimeDirectory(info
, pbuffer
, dwLength
);
190 ICLRRuntimeInfo_Release(info
);
196 HRESULT WINAPI
GetCORVersion(LPWSTR pbuffer
, DWORD cchBuffer
, DWORD
*dwLength
)
198 ICLRRuntimeInfo
*info
;
201 TRACE("(%p, %d, %p)!\n", pbuffer
, cchBuffer
, dwLength
);
203 if (!dwLength
|| !pbuffer
)
206 ret
= get_runtime_info(NULL
, NULL
, NULL
, 0, RUNTIME_INFO_UPGRADE_VERSION
, TRUE
, &info
);
210 *dwLength
= cchBuffer
;
211 ret
= ICLRRuntimeInfo_GetVersionString(info
, pbuffer
, dwLength
);
213 ICLRRuntimeInfo_Release(info
);
219 HRESULT WINAPI
GetRequestedRuntimeInfo(LPCWSTR pExe
, LPCWSTR pwszVersion
, LPCWSTR pConfigurationFile
,
220 DWORD startupFlags
, DWORD runtimeInfoFlags
, LPWSTR pDirectory
, DWORD dwDirectory
, DWORD
*dwDirectoryLength
,
221 LPWSTR pVersion
, DWORD cchBuffer
, DWORD
*dwlength
)
224 ICLRRuntimeInfo
*info
;
227 TRACE("(%s, %s, %s, 0x%08x, 0x%08x, %p, 0x%08x, %p, %p, 0x%08x, %p)\n", debugstr_w(pExe
),
228 debugstr_w(pwszVersion
), debugstr_w(pConfigurationFile
), startupFlags
, runtimeInfoFlags
, pDirectory
,
229 dwDirectory
, dwDirectoryLength
, pVersion
, cchBuffer
, dwlength
);
231 if (!dwDirectoryLength
) dwDirectoryLength
= &length_dummy
;
233 if (!dwlength
) dwlength
= &length_dummy
;
235 ret
= get_runtime_info(pExe
, pwszVersion
, pConfigurationFile
, startupFlags
, runtimeInfoFlags
, TRUE
, &info
);
239 *dwlength
= cchBuffer
;
240 ret
= ICLRRuntimeInfo_GetVersionString(info
, pVersion
, dwlength
);
244 *dwDirectoryLength
= dwDirectory
;
245 ret
= ICLRRuntimeInfo_GetRuntimeDirectory(info
, pDirectory
, dwDirectoryLength
);
248 ICLRRuntimeInfo_Release(info
);
254 HRESULT WINAPI
GetRequestedRuntimeVersion(LPWSTR pExe
, LPWSTR pVersion
, DWORD cchBuffer
, DWORD
*dwlength
)
256 TRACE("(%s, %p, %d, %p)\n", debugstr_w(pExe
), debugstr_w(pExe
), cchBuffer
, dwlength
);
261 return GetRequestedRuntimeInfo(pExe
, NULL
, NULL
, 0, 0, NULL
, 0, NULL
, pVersion
, cchBuffer
, dwlength
);
264 HRESULT WINAPI
GetRealProcAddress(LPCSTR procname
, void **ppv
)
266 FIXME("(%s, %p)\n", debugstr_a(procname
), ppv
);
267 return CLR_E_SHIM_RUNTIMEEXPORT
;
270 HRESULT WINAPI
GetFileVersion(LPCWSTR szFilename
, LPWSTR szBuffer
, DWORD cchBuffer
, DWORD
*dwLength
)
272 TRACE("(%s, %p, %d, %p)\n", debugstr_w(szFilename
), szBuffer
, cchBuffer
, dwLength
);
274 if (!szFilename
|| !dwLength
)
277 *dwLength
= cchBuffer
;
278 return CLRMetaHost_GetVersionFromFile(0, szFilename
, szBuffer
, dwLength
);
281 HRESULT WINAPI
LoadLibraryShim( LPCWSTR szDllName
, LPCWSTR szVersion
, LPVOID pvReserved
, HMODULE
* phModDll
)
284 WCHAR dll_filename
[MAX_PATH
];
285 WCHAR version
[MAX_PATH
];
286 static const WCHAR default_version
[] = {'v','1','.','1','.','4','3','2','2',0};
287 static const WCHAR slash
[] = {'\\',0};
290 TRACE("(%p %s, %p, %p, %p)\n", szDllName
, debugstr_w(szDllName
), szVersion
, pvReserved
, phModDll
);
292 if (!szDllName
|| !phModDll
)
295 if (!get_install_root(dll_filename
))
297 ERR("error reading registry key for installroot\n");
304 ret
= GetCORVersion(version
, MAX_PATH
, &dummy
);
308 szVersion
= default_version
;
310 strcatW(dll_filename
, szVersion
);
311 strcatW(dll_filename
, slash
);
314 strcatW(dll_filename
, szDllName
);
316 *phModDll
= LoadLibraryW(dll_filename
);
318 return *phModDll
? S_OK
: E_HANDLE
;
321 HRESULT WINAPI
LockClrVersion(FLockClrVersionCallback hostCallback
, FLockClrVersionCallback
*pBeginHostSetup
, FLockClrVersionCallback
*pEndHostSetup
)
323 FIXME("(%p %p %p): stub\n", hostCallback
, pBeginHostSetup
, pEndHostSetup
);
327 HRESULT WINAPI
CoInitializeCor(DWORD fFlags
)
329 FIXME("(0x%08x): stub\n", fFlags
);
333 HRESULT WINAPI
GetAssemblyMDImport(LPCWSTR szFileName
, REFIID riid
, IUnknown
**ppIUnk
)
335 FIXME("(%p %s, %s, %p): stub\n", szFileName
, debugstr_w(szFileName
), debugstr_guid(riid
), *ppIUnk
);
336 return ERROR_CALL_NOT_IMPLEMENTED
;
339 HRESULT WINAPI
GetVersionFromProcess(HANDLE hProcess
, LPWSTR pVersion
, DWORD cchBuffer
, DWORD
*dwLength
)
341 FIXME("(%p, %p, %d, %p): stub\n", hProcess
, pVersion
, cchBuffer
, dwLength
);
345 HRESULT WINAPI
LoadStringRCEx(LCID culture
, UINT resId
, LPWSTR pBuffer
, int iBufLen
, int bQuiet
, int* pBufLen
)
348 if ((iBufLen
<= 0) || !pBuffer
)
352 FIXME("(%d, %x, %p, %d, %d, %p): semi-stub\n", culture
, resId
, pBuffer
, iBufLen
, bQuiet
, pBufLen
);
358 *pBufLen
= lstrlenW(pBuffer
);
362 HRESULT WINAPI
LoadStringRC(UINT resId
, LPWSTR pBuffer
, int iBufLen
, int bQuiet
)
364 return LoadStringRCEx(-1, resId
, pBuffer
, iBufLen
, bQuiet
, NULL
);
367 HRESULT WINAPI
CorBindToRuntimeEx(LPWSTR szVersion
, LPWSTR szBuildFlavor
, DWORD nflags
, REFCLSID rslsid
,
368 REFIID riid
, LPVOID
*ppv
)
371 ICLRRuntimeInfo
*info
;
373 TRACE("%s %s %d %s %s %p\n", debugstr_w(szVersion
), debugstr_w(szBuildFlavor
), nflags
, debugstr_guid( rslsid
),
374 debugstr_guid( riid
), ppv
);
378 ret
= get_runtime_info(NULL
, szVersion
, NULL
, nflags
, RUNTIME_INFO_UPGRADE_VERSION
, TRUE
, &info
);
382 ret
= ICLRRuntimeInfo_GetInterface(info
, rslsid
, riid
, ppv
);
384 ICLRRuntimeInfo_Release(info
);
390 HRESULT WINAPI
CorBindToCurrentRuntime(LPCWSTR filename
, REFCLSID rclsid
, REFIID riid
, LPVOID
*ppv
)
392 FIXME("(%s, %s, %s, %p): stub\n", debugstr_w(filename
), debugstr_guid(rclsid
), debugstr_guid(riid
), ppv
);
396 STDAPI
ClrCreateManagedInstance(LPCWSTR pTypeName
, REFIID riid
, void **ppObject
)
399 ICLRRuntimeInfo
*info
;
404 TRACE("(%s,%s,%p)\n", debugstr_w(pTypeName
), debugstr_guid(riid
), ppObject
);
406 /* FIXME: How to determine which runtime version to use? */
407 ret
= get_runtime_info(NULL
, NULL
, NULL
, 0, RUNTIME_INFO_UPGRADE_VERSION
, TRUE
, &info
);
411 ret
= ICLRRuntimeInfo_GetRuntimeHost(info
, &host
);
413 ICLRRuntimeInfo_Release(info
);
417 ret
= RuntimeHost_CreateManagedInstance(host
, pTypeName
, NULL
, &obj
);
420 ret
= RuntimeHost_GetIUnknownForObject(host
, obj
, &unk
);
424 ret
= IUnknown_QueryInterface(unk
, riid
, ppObject
);
425 IUnknown_Release(unk
);
431 BOOL WINAPI
StrongNameSignatureVerification(LPCWSTR filename
, DWORD inFlags
, DWORD
* pOutFlags
)
433 FIXME("(%s, 0x%X, %p): stub\n", debugstr_w(filename
), inFlags
, pOutFlags
);
437 BOOL WINAPI
StrongNameSignatureVerificationEx(LPCWSTR filename
, BOOL forceVerification
, BOOL
* pVerified
)
439 FIXME("(%s, %u, %p): stub\n", debugstr_w(filename
), forceVerification
, pVerified
);
443 HRESULT WINAPI
CreateConfigStream(LPCWSTR filename
, IStream
**stream
)
445 FIXME("(%s, %p): stub\n", debugstr_w(filename
), stream
);
449 HRESULT WINAPI
CreateDebuggingInterfaceFromVersion(int nDebugVersion
, LPCWSTR version
, IUnknown
**ppv
)
451 const WCHAR v2_0
[] = {'v','2','.','0','.','5','0','7','2','7',0};
453 ICLRRuntimeInfo
*runtimeinfo
;
455 if(nDebugVersion
< 1 || nDebugVersion
> 4)
458 TRACE("(%d %s, %p): stub\n", nDebugVersion
, debugstr_w(version
), ppv
);
465 if(strcmpW(version
, v2_0
) != 0)
467 FIXME("Currently .NET Version '%s' not support.\n", debugstr_w(version
));
471 if(nDebugVersion
!= 3)
474 hr
= CLRMetaHost_GetRuntime(0, version
, &IID_ICLRRuntimeInfo
, (void**)&runtimeinfo
);
477 hr
= ICLRRuntimeInfo_GetInterface(runtimeinfo
, &CLSID_CLRDebuggingLegacy
, &IID_ICorDebug
, (void**)ppv
);
479 ICLRRuntimeInfo_Release(runtimeinfo
);
488 HRESULT WINAPI
CLRCreateInstance(REFCLSID clsid
, REFIID riid
, LPVOID
*ppInterface
)
490 TRACE("(%s,%s,%p)\n", debugstr_guid(clsid
), debugstr_guid(riid
), ppInterface
);
492 if (IsEqualGUID(clsid
, &CLSID_CLRMetaHost
))
493 return CLRMetaHost_CreateInstance(riid
, ppInterface
);
495 FIXME("not implemented for class %s\n", debugstr_guid(clsid
));
497 return CLASS_E_CLASSNOTAVAILABLE
;
500 HRESULT WINAPI
DllGetClassObject(REFCLSID rclsid
, REFIID riid
, LPVOID
* ppv
)
502 FIXME("(%s, %s, %p): stub\n", debugstr_guid(rclsid
), debugstr_guid(riid
), ppv
);
509 HRESULT WINAPI
DllRegisterServer(void)
515 HRESULT WINAPI
DllUnregisterServer(void)
521 HRESULT WINAPI
DllCanUnloadNow(VOID
)
526 INT WINAPI
ND_RU1( const void *ptr
, INT offset
)
528 return *((const BYTE
*)ptr
+ offset
);
531 INT WINAPI
ND_RI2( const void *ptr
, INT offset
)
533 return *(const SHORT
*)((const BYTE
*)ptr
+ offset
);
536 INT WINAPI
ND_RI4( const void *ptr
, INT offset
)
538 return *(const INT
*)((const BYTE
*)ptr
+ offset
);
541 INT64 WINAPI
ND_RI8( const void *ptr
, INT offset
)
543 return *(const INT64
*)((const BYTE
*)ptr
+ offset
);
546 void WINAPI
ND_WU1( void *ptr
, INT offset
, BYTE val
)
548 *((BYTE
*)ptr
+ offset
) = val
;
551 void WINAPI
ND_WI2( void *ptr
, INT offset
, SHORT val
)
553 *(SHORT
*)((BYTE
*)ptr
+ offset
) = val
;
556 void WINAPI
ND_WI4( void *ptr
, INT offset
, INT val
)
558 *(INT
*)((BYTE
*)ptr
+ offset
) = val
;
561 void WINAPI
ND_WI8( void *ptr
, INT offset
, INT64 val
)
563 *(INT64
*)((BYTE
*)ptr
+ offset
) = val
;
566 void WINAPI
ND_CopyObjDst( const void *src
, void *dst
, INT offset
, INT size
)
568 memcpy( (BYTE
*)dst
+ offset
, src
, size
);
571 void WINAPI
ND_CopyObjSrc( const void *src
, INT offset
, void *dst
, INT size
)
573 memcpy( dst
, (const BYTE
*)src
+ offset
, size
);