Home | Info | Community | Development | myReactOS | Contact Us
ReactOS Development > Doxygenmscoree_main.c
Go to the documentation of this file.
00001 /* 00002 * Implementation of mscoree.dll 00003 * Microsoft Component Object Runtime Execution Engine 00004 * 00005 * Copyright 2006 Paul Chitescu 00006 * 00007 * This library is free software; you can redistribute it and/or 00008 * modify it under the terms of the GNU Lesser General Public 00009 * License as published by the Free Software Foundation; either 00010 * version 2.1 of the License, or (at your option) any later version. 00011 * 00012 * This library is distributed in the hope that it will be useful, 00013 * but WITHOUT ANY WARRANTY; without even the implied warranty of 00014 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 00015 * Lesser General Public License for more details. 00016 * 00017 * You should have received a copy of the GNU Lesser General Public 00018 * License along with this library; if not, write to the Free Software 00019 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA 00020 */ 00021 00022 #include <stdarg.h> 00023 00024 #define COBJMACROS 00025 #include "wine/unicode.h" 00026 #include "wine/library.h" 00027 #include "windef.h" 00028 #include "winbase.h" 00029 #include "winuser.h" 00030 #include "winnls.h" 00031 #include "winreg.h" 00032 #include "ole2.h" 00033 #include "ocidl.h" 00034 #include "shellapi.h" 00035 00036 #include "initguid.h" 00037 #include "msxml2.h" 00038 #include "corerror.h" 00039 #include "cor.h" 00040 #include "mscoree.h" 00041 #include "corhdr.h" 00042 #include "cordebug.h" 00043 #include "metahost.h" 00044 #include "fusion.h" 00045 #include "wine/list.h" 00046 #include "mscoree_private.h" 00047 #include "rpcproxy.h" 00048 00049 #include "wine/debug.h" 00050 00051 WINE_DEFAULT_DEBUG_CHANNEL( mscoree ); 00052 00053 static HINSTANCE MSCOREE_hInstance; 00054 00055 char *WtoA(LPCWSTR wstr) 00056 { 00057 int length; 00058 char *result; 00059 00060 length = WideCharToMultiByte(CP_UTF8, 0, wstr, -1, NULL, 0, NULL, NULL); 00061 00062 result = HeapAlloc(GetProcessHeap(), 0, length); 00063 00064 if (result) 00065 WideCharToMultiByte(CP_UTF8, 0, wstr, -1, result, length, NULL, NULL); 00066 00067 return result; 00068 } 00069 00070 static BOOL get_install_root(LPWSTR install_dir) 00071 { 00072 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}; 00073 const WCHAR install_root[] = {'I','n','s','t','a','l','l','R','o','o','t',0}; 00074 00075 DWORD len; 00076 HKEY key; 00077 00078 if (RegOpenKeyExW(HKEY_LOCAL_MACHINE, dotnet_key, 0, KEY_READ, &key)) 00079 return FALSE; 00080 00081 len = MAX_PATH; 00082 if (RegQueryValueExW(key, install_root, 0, NULL, (LPBYTE)install_dir, &len)) 00083 { 00084 RegCloseKey(key); 00085 return FALSE; 00086 } 00087 RegCloseKey(key); 00088 00089 return TRUE; 00090 } 00091 00092 HRESULT WINAPI CorBindToRuntimeHost(LPCWSTR pwszVersion, LPCWSTR pwszBuildFlavor, 00093 LPCWSTR pwszHostConfigFile, VOID *pReserved, 00094 DWORD startupFlags, REFCLSID rclsid, 00095 REFIID riid, LPVOID *ppv) 00096 { 00097 HRESULT ret; 00098 ICLRRuntimeInfo *info; 00099 00100 TRACE("(%s, %s, %s, %p, %d, %s, %s, %p)\n", debugstr_w(pwszVersion), 00101 debugstr_w(pwszBuildFlavor), debugstr_w(pwszHostConfigFile), pReserved, 00102 startupFlags, debugstr_guid(rclsid), debugstr_guid(riid), ppv); 00103 00104 *ppv = NULL; 00105 00106 ret = get_runtime_info(NULL, pwszVersion, pwszHostConfigFile, startupFlags, 0, TRUE, &info); 00107 00108 if (SUCCEEDED(ret)) 00109 { 00110 ret = ICLRRuntimeInfo_GetInterface(info, rclsid, riid, ppv); 00111 00112 ICLRRuntimeInfo_Release(info); 00113 } 00114 00115 return ret; 00116 } 00117 00118 BOOL WINAPI DllMain(HINSTANCE hinstDLL, DWORD fdwReason, LPVOID lpvReserved) 00119 { 00120 TRACE("(%p, %d, %p)\n", hinstDLL, fdwReason, lpvReserved); 00121 00122 MSCOREE_hInstance = hinstDLL; 00123 00124 switch (fdwReason) 00125 { 00126 case DLL_WINE_PREATTACH: 00127 return FALSE; /* prefer native version */ 00128 case DLL_PROCESS_ATTACH: 00129 DisableThreadLibraryCalls(hinstDLL); 00130 break; 00131 case DLL_PROCESS_DETACH: 00132 expect_no_runtimes(); 00133 break; 00134 } 00135 return TRUE; 00136 } 00137 00138 BOOL WINAPI _CorDllMain(HINSTANCE hinstDLL, DWORD fdwReason, LPVOID lpvReserved) 00139 { 00140 FIXME("(%p, %d, %p): stub\n", hinstDLL, fdwReason, lpvReserved); 00141 00142 switch (fdwReason) 00143 { 00144 case DLL_PROCESS_ATTACH: 00145 DisableThreadLibraryCalls(hinstDLL); 00146 break; 00147 case DLL_PROCESS_DETACH: 00148 break; 00149 } 00150 return TRUE; 00151 } 00152 00153 __int32 WINAPI _CorExeMain2(PBYTE ptrMemory, DWORD cntMemory, LPWSTR imageName, LPWSTR loaderName, LPWSTR cmdLine) 00154 { 00155 TRACE("(%p, %u, %s, %s, %s)\n", ptrMemory, cntMemory, debugstr_w(imageName), debugstr_w(loaderName), debugstr_w(cmdLine)); 00156 FIXME("Directly running .NET applications not supported.\n"); 00157 return -1; 00158 } 00159 00160 void WINAPI CorExitProcess(int exitCode) 00161 { 00162 TRACE("(%x)\n", exitCode); 00163 unload_all_runtimes(); 00164 ExitProcess(exitCode); 00165 } 00166 00167 VOID WINAPI _CorImageUnloading(PVOID imageBase) 00168 { 00169 TRACE("(%p): stub\n", imageBase); 00170 } 00171 00172 HRESULT WINAPI _CorValidateImage(PVOID* imageBase, LPCWSTR imageName) 00173 { 00174 TRACE("(%p, %s): stub\n", imageBase, debugstr_w(imageName)); 00175 return E_FAIL; 00176 } 00177 00178 HRESULT WINAPI GetCORSystemDirectory(LPWSTR pbuffer, DWORD cchBuffer, DWORD *dwLength) 00179 { 00180 ICLRRuntimeInfo *info; 00181 HRESULT ret; 00182 00183 TRACE("(%p, %d, %p)!\n", pbuffer, cchBuffer, dwLength); 00184 00185 if (!dwLength || !pbuffer) 00186 return E_POINTER; 00187 00188 ret = get_runtime_info(NULL, NULL, NULL, 0, RUNTIME_INFO_UPGRADE_VERSION, TRUE, &info); 00189 00190 if (SUCCEEDED(ret)) 00191 { 00192 *dwLength = cchBuffer; 00193 ret = ICLRRuntimeInfo_GetRuntimeDirectory(info, pbuffer, dwLength); 00194 00195 ICLRRuntimeInfo_Release(info); 00196 } 00197 00198 return ret; 00199 } 00200 00201 HRESULT WINAPI GetCORVersion(LPWSTR pbuffer, DWORD cchBuffer, DWORD *dwLength) 00202 { 00203 ICLRRuntimeInfo *info; 00204 HRESULT ret; 00205 00206 TRACE("(%p, %d, %p)!\n", pbuffer, cchBuffer, dwLength); 00207 00208 if (!dwLength || !pbuffer) 00209 return E_POINTER; 00210 00211 ret = get_runtime_info(NULL, NULL, NULL, 0, RUNTIME_INFO_UPGRADE_VERSION, TRUE, &info); 00212 00213 if (SUCCEEDED(ret)) 00214 { 00215 *dwLength = cchBuffer; 00216 ret = ICLRRuntimeInfo_GetVersionString(info, pbuffer, dwLength); 00217 00218 ICLRRuntimeInfo_Release(info); 00219 } 00220 00221 return ret; 00222 } 00223 00224 HRESULT WINAPI GetRequestedRuntimeInfo(LPCWSTR pExe, LPCWSTR pwszVersion, LPCWSTR pConfigurationFile, 00225 DWORD startupFlags, DWORD runtimeInfoFlags, LPWSTR pDirectory, DWORD dwDirectory, DWORD *dwDirectoryLength, 00226 LPWSTR pVersion, DWORD cchBuffer, DWORD *dwlength) 00227 { 00228 HRESULT ret; 00229 ICLRRuntimeInfo *info; 00230 DWORD length_dummy; 00231 00232 TRACE("(%s, %s, %s, 0x%08x, 0x%08x, %p, 0x%08x, %p, %p, 0x%08x, %p)\n", debugstr_w(pExe), 00233 debugstr_w(pwszVersion), debugstr_w(pConfigurationFile), startupFlags, runtimeInfoFlags, pDirectory, 00234 dwDirectory, dwDirectoryLength, pVersion, cchBuffer, dwlength); 00235 00236 if (!dwDirectoryLength) dwDirectoryLength = &length_dummy; 00237 00238 if (!dwlength) dwlength = &length_dummy; 00239 00240 ret = get_runtime_info(pExe, pwszVersion, pConfigurationFile, startupFlags, runtimeInfoFlags, TRUE, &info); 00241 00242 if (SUCCEEDED(ret)) 00243 { 00244 *dwlength = cchBuffer; 00245 ret = ICLRRuntimeInfo_GetVersionString(info, pVersion, dwlength); 00246 00247 if (SUCCEEDED(ret)) 00248 { 00249 *dwDirectoryLength = dwDirectory; 00250 ret = ICLRRuntimeInfo_GetRuntimeDirectory(info, pDirectory, dwDirectoryLength); 00251 } 00252 00253 ICLRRuntimeInfo_Release(info); 00254 } 00255 00256 return ret; 00257 } 00258 00259 HRESULT WINAPI GetRequestedRuntimeVersion(LPWSTR pExe, LPWSTR pVersion, DWORD cchBuffer, DWORD *dwlength) 00260 { 00261 TRACE("(%s, %p, %d, %p)\n", debugstr_w(pExe), debugstr_w(pExe), cchBuffer, dwlength); 00262 00263 if(!dwlength) 00264 return E_POINTER; 00265 00266 return GetRequestedRuntimeInfo(pExe, NULL, NULL, 0, 0, NULL, 0, NULL, pVersion, cchBuffer, dwlength); 00267 } 00268 00269 HRESULT WINAPI GetRealProcAddress(LPCSTR procname, void **ppv) 00270 { 00271 FIXME("(%s, %p)\n", debugstr_a(procname), ppv); 00272 return CLR_E_SHIM_RUNTIMEEXPORT; 00273 } 00274 00275 HRESULT WINAPI GetFileVersion(LPCWSTR szFilename, LPWSTR szBuffer, DWORD cchBuffer, DWORD *dwLength) 00276 { 00277 TRACE("(%s, %p, %d, %p)\n", debugstr_w(szFilename), szBuffer, cchBuffer, dwLength); 00278 00279 if (!szFilename || !dwLength) 00280 return E_POINTER; 00281 00282 *dwLength = cchBuffer; 00283 return CLRMetaHost_GetVersionFromFile(0, szFilename, szBuffer, dwLength); 00284 } 00285 00286 HRESULT WINAPI LoadLibraryShim( LPCWSTR szDllName, LPCWSTR szVersion, LPVOID pvReserved, HMODULE * phModDll) 00287 { 00288 HRESULT ret=S_OK; 00289 WCHAR dll_filename[MAX_PATH]; 00290 WCHAR version[MAX_PATH]; 00291 static const WCHAR default_version[] = {'v','1','.','1','.','4','3','2','2',0}; 00292 static const WCHAR slash[] = {'\\',0}; 00293 DWORD dummy; 00294 00295 TRACE("(%p %s, %p, %p, %p)\n", szDllName, debugstr_w(szDllName), szVersion, pvReserved, phModDll); 00296 00297 if (!szDllName || !phModDll) 00298 return E_POINTER; 00299 00300 if (!get_install_root(dll_filename)) 00301 { 00302 ERR("error reading registry key for installroot\n"); 00303 dll_filename[0] = 0; 00304 } 00305 else 00306 { 00307 if (!szVersion) 00308 { 00309 ret = GetCORVersion(version, MAX_PATH, &dummy); 00310 if (SUCCEEDED(ret)) 00311 szVersion = version; 00312 else 00313 szVersion = default_version; 00314 } 00315 strcatW(dll_filename, szVersion); 00316 strcatW(dll_filename, slash); 00317 } 00318 00319 strcatW(dll_filename, szDllName); 00320 00321 *phModDll = LoadLibraryW(dll_filename); 00322 00323 return *phModDll ? S_OK : E_HANDLE; 00324 } 00325 00326 HRESULT WINAPI LockClrVersion(FLockClrVersionCallback hostCallback, FLockClrVersionCallback *pBeginHostSetup, FLockClrVersionCallback *pEndHostSetup) 00327 { 00328 FIXME("(%p %p %p): stub\n", hostCallback, pBeginHostSetup, pEndHostSetup); 00329 return S_OK; 00330 } 00331 00332 HRESULT WINAPI CoInitializeCor(DWORD fFlags) 00333 { 00334 FIXME("(0x%08x): stub\n", fFlags); 00335 return S_OK; 00336 } 00337 00338 HRESULT WINAPI GetAssemblyMDImport(LPCWSTR szFileName, REFIID riid, IUnknown **ppIUnk) 00339 { 00340 FIXME("(%p %s, %s, %p): stub\n", szFileName, debugstr_w(szFileName), debugstr_guid(riid), *ppIUnk); 00341 return ERROR_CALL_NOT_IMPLEMENTED; 00342 } 00343 00344 HRESULT WINAPI GetVersionFromProcess(HANDLE hProcess, LPWSTR pVersion, DWORD cchBuffer, DWORD *dwLength) 00345 { 00346 FIXME("(%p, %p, %d, %p): stub\n", hProcess, pVersion, cchBuffer, dwLength); 00347 return E_NOTIMPL; 00348 } 00349 00350 HRESULT WINAPI LoadStringRCEx(LCID culture, UINT resId, LPWSTR pBuffer, int iBufLen, int bQuiet, int* pBufLen) 00351 { 00352 HRESULT res = S_OK; 00353 if ((iBufLen <= 0) || !pBuffer) 00354 return E_INVALIDARG; 00355 pBuffer[0] = 0; 00356 if (resId) { 00357 FIXME("(%d, %x, %p, %d, %d, %p): semi-stub\n", culture, resId, pBuffer, iBufLen, bQuiet, pBufLen); 00358 res = E_NOTIMPL; 00359 } 00360 else 00361 res = E_FAIL; 00362 if (pBufLen) 00363 *pBufLen = lstrlenW(pBuffer); 00364 return res; 00365 } 00366 00367 HRESULT WINAPI LoadStringRC(UINT resId, LPWSTR pBuffer, int iBufLen, int bQuiet) 00368 { 00369 return LoadStringRCEx(-1, resId, pBuffer, iBufLen, bQuiet, NULL); 00370 } 00371 00372 HRESULT WINAPI CorBindToRuntimeEx(LPWSTR szVersion, LPWSTR szBuildFlavor, DWORD nflags, REFCLSID rslsid, 00373 REFIID riid, LPVOID *ppv) 00374 { 00375 HRESULT ret; 00376 ICLRRuntimeInfo *info; 00377 00378 TRACE("%s %s %d %s %s %p\n", debugstr_w(szVersion), debugstr_w(szBuildFlavor), nflags, debugstr_guid( rslsid ), 00379 debugstr_guid( riid ), ppv); 00380 00381 *ppv = NULL; 00382 00383 ret = get_runtime_info(NULL, szVersion, NULL, nflags, RUNTIME_INFO_UPGRADE_VERSION, TRUE, &info); 00384 00385 if (SUCCEEDED(ret)) 00386 { 00387 ret = ICLRRuntimeInfo_GetInterface(info, rslsid, riid, ppv); 00388 00389 ICLRRuntimeInfo_Release(info); 00390 } 00391 00392 return ret; 00393 } 00394 00395 HRESULT WINAPI CorBindToCurrentRuntime(LPCWSTR filename, REFCLSID rclsid, REFIID riid, LPVOID *ppv) 00396 { 00397 FIXME("(%s, %s, %s, %p): stub\n", debugstr_w(filename), debugstr_guid(rclsid), debugstr_guid(riid), ppv); 00398 return E_NOTIMPL; 00399 } 00400 00401 STDAPI ClrCreateManagedInstance(LPCWSTR pTypeName, REFIID riid, void **ppObject) 00402 { 00403 HRESULT ret; 00404 ICLRRuntimeInfo *info; 00405 RuntimeHost *host; 00406 MonoObject *obj; 00407 IUnknown *unk; 00408 00409 TRACE("(%s,%s,%p)\n", debugstr_w(pTypeName), debugstr_guid(riid), ppObject); 00410 00411 /* FIXME: How to determine which runtime version to use? */ 00412 ret = get_runtime_info(NULL, NULL, NULL, 0, RUNTIME_INFO_UPGRADE_VERSION, TRUE, &info); 00413 00414 if (SUCCEEDED(ret)) 00415 { 00416 ret = ICLRRuntimeInfo_GetRuntimeHost(info, &host); 00417 00418 ICLRRuntimeInfo_Release(info); 00419 } 00420 00421 if (SUCCEEDED(ret)) 00422 ret = RuntimeHost_CreateManagedInstance(host, pTypeName, NULL, &obj); 00423 00424 if (SUCCEEDED(ret)) 00425 ret = RuntimeHost_GetIUnknownForObject(host, obj, &unk); 00426 00427 if (SUCCEEDED(ret)) 00428 { 00429 ret = IUnknown_QueryInterface(unk, riid, ppObject); 00430 IUnknown_Release(unk); 00431 } 00432 00433 return ret; 00434 } 00435 00436 BOOL WINAPI StrongNameSignatureVerification(LPCWSTR filename, DWORD inFlags, DWORD* pOutFlags) 00437 { 00438 FIXME("(%s, 0x%X, %p): stub\n", debugstr_w(filename), inFlags, pOutFlags); 00439 return FALSE; 00440 } 00441 00442 BOOL WINAPI StrongNameSignatureVerificationEx(LPCWSTR filename, BOOL forceVerification, BOOL* pVerified) 00443 { 00444 FIXME("(%s, %u, %p): stub\n", debugstr_w(filename), forceVerification, pVerified); 00445 return FALSE; 00446 } 00447 00448 HRESULT WINAPI CreateConfigStream(LPCWSTR filename, IStream **stream) 00449 { 00450 FIXME("(%s, %p): stub\n", debugstr_w(filename), stream); 00451 return E_NOTIMPL; 00452 } 00453 00454 HRESULT WINAPI CreateDebuggingInterfaceFromVersion(int nDebugVersion, LPCWSTR version, IUnknown **ppv) 00455 { 00456 const WCHAR v2_0[] = {'v','2','.','0','.','5','0','7','2','7',0}; 00457 HRESULT hr = E_FAIL; 00458 ICLRRuntimeInfo *runtimeinfo; 00459 00460 if(nDebugVersion < 1 || nDebugVersion > 4) 00461 return E_INVALIDARG; 00462 00463 TRACE("(%d %s, %p): stub\n", nDebugVersion, debugstr_w(version), ppv); 00464 00465 if(!ppv) 00466 return E_INVALIDARG; 00467 00468 *ppv = NULL; 00469 00470 if(strcmpW(version, v2_0) != 0) 00471 { 00472 FIXME("Currently .NET Version '%s' not support.\n", debugstr_w(version)); 00473 return E_INVALIDARG; 00474 } 00475 00476 if(nDebugVersion != 3) 00477 return E_INVALIDARG; 00478 00479 hr = CLRMetaHost_GetRuntime(0, version, &IID_ICLRRuntimeInfo, (void**)&runtimeinfo); 00480 if(hr == S_OK) 00481 { 00482 hr = ICLRRuntimeInfo_GetInterface(runtimeinfo, &CLSID_CLRDebuggingLegacy, &IID_ICorDebug, (void**)ppv); 00483 00484 ICLRRuntimeInfo_Release(runtimeinfo); 00485 } 00486 00487 if(!*ppv) 00488 return E_FAIL; 00489 00490 return hr; 00491 } 00492 00493 HRESULT WINAPI CLRCreateInstance(REFCLSID clsid, REFIID riid, LPVOID *ppInterface) 00494 { 00495 TRACE("(%s,%s,%p)\n", debugstr_guid(clsid), debugstr_guid(riid), ppInterface); 00496 00497 if (IsEqualGUID(clsid, &CLSID_CLRMetaHost)) 00498 return CLRMetaHost_CreateInstance(riid, ppInterface); 00499 00500 FIXME("not implemented for class %s\n", debugstr_guid(clsid)); 00501 00502 return CLASS_E_CLASSNOTAVAILABLE; 00503 } 00504 00505 HRESULT WINAPI DllGetClassObject(REFCLSID rclsid, REFIID riid, LPVOID* ppv) 00506 { 00507 FIXME("(%s, %s, %p): stub\n", debugstr_guid(rclsid), debugstr_guid(riid), ppv); 00508 if(!ppv) 00509 return E_INVALIDARG; 00510 00511 return E_NOTIMPL; 00512 } 00513 00514 HRESULT WINAPI DllRegisterServer(void) 00515 { 00516 return __wine_register_resources( MSCOREE_hInstance ); 00517 } 00518 00519 HRESULT WINAPI DllUnregisterServer(void) 00520 { 00521 return __wine_unregister_resources( MSCOREE_hInstance ); 00522 } 00523 00524 HRESULT WINAPI DllCanUnloadNow(VOID) 00525 { 00526 return S_FALSE; 00527 } 00528 00529 INT WINAPI ND_RU1( const void *ptr, INT offset ) 00530 { 00531 return *((const BYTE *)ptr + offset); 00532 } 00533 00534 INT WINAPI ND_RI2( const void *ptr, INT offset ) 00535 { 00536 return *(const SHORT *)((const BYTE *)ptr + offset); 00537 } 00538 00539 INT WINAPI ND_RI4( const void *ptr, INT offset ) 00540 { 00541 return *(const INT *)((const BYTE *)ptr + offset); 00542 } 00543 00544 INT64 WINAPI ND_RI8( const void *ptr, INT offset ) 00545 { 00546 return *(const INT64 *)((const BYTE *)ptr + offset); 00547 } 00548 00549 void WINAPI ND_WU1( void *ptr, INT offset, BYTE val ) 00550 { 00551 *((BYTE *)ptr + offset) = val; 00552 } 00553 00554 void WINAPI ND_WI2( void *ptr, INT offset, SHORT val ) 00555 { 00556 *(SHORT *)((BYTE *)ptr + offset) = val; 00557 } 00558 00559 void WINAPI ND_WI4( void *ptr, INT offset, INT val ) 00560 { 00561 *(INT *)((BYTE *)ptr + offset) = val; 00562 } 00563 00564 void WINAPI ND_WI8( void *ptr, INT offset, INT64 val ) 00565 { 00566 *(INT64 *)((BYTE *)ptr + offset) = val; 00567 } 00568 00569 void WINAPI ND_CopyObjDst( const void *src, void *dst, INT offset, INT size ) 00570 { 00571 memcpy( (BYTE *)dst + offset, src, size ); 00572 } 00573 00574 void WINAPI ND_CopyObjSrc( const void *src, INT offset, void *dst, INT size ) 00575 { 00576 memcpy( dst, (const BYTE *)src + offset, size ); 00577 } Generated on Sun May 27 2012 04:24:48 for ReactOS by
1.7.6.1
|