msxml3: Fix attributes formatting.
[wine/multimedia.git] / dlls / mscoree / mscoree_main.c
blob9e37eae14992c29cfdf117d6cff5b742ac35e543
1 /*
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
22 #include <stdarg.h>
24 #define COBJMACROS
25 #include "wine/unicode.h"
26 #include "wine/library.h"
27 #include "windef.h"
28 #include "winbase.h"
29 #include "winuser.h"
30 #include "winnls.h"
31 #include "winreg.h"
32 #include "ole2.h"
33 #include "ocidl.h"
34 #include "shellapi.h"
36 #include "initguid.h"
37 #include "msxml2.h"
38 #include "cor.h"
39 #include "corerror.h"
40 #include "mscoree.h"
41 #include "fusion.h"
42 #include "metahost.h"
43 #include "wine/list.h"
44 #include "mscoree_private.h"
46 #include "wine/debug.h"
48 WINE_DEFAULT_DEBUG_CHANNEL( mscoree );
50 char *WtoA(LPCWSTR wstr)
52 int length;
53 char *result;
55 length = WideCharToMultiByte(CP_UTF8, 0, wstr, -1, NULL, 0, NULL, NULL);
57 result = HeapAlloc(GetProcessHeap(), 0, length);
59 if (result)
60 WideCharToMultiByte(CP_UTF8, 0, wstr, -1, result, length, NULL, NULL);
62 return result;
65 static BOOL get_install_root(LPWSTR install_dir)
67 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};
68 const WCHAR install_root[] = {'I','n','s','t','a','l','l','R','o','o','t',0};
70 DWORD len;
71 HKEY key;
73 if (RegOpenKeyExW(HKEY_LOCAL_MACHINE, dotnet_key, 0, KEY_READ, &key))
74 return FALSE;
76 len = MAX_PATH;
77 if (RegQueryValueExW(key, install_root, 0, NULL, (LPBYTE)install_dir, &len))
79 RegCloseKey(key);
80 return FALSE;
82 RegCloseKey(key);
84 return TRUE;
87 HRESULT WINAPI CorBindToRuntimeHost(LPCWSTR pwszVersion, LPCWSTR pwszBuildFlavor,
88 LPCWSTR pwszHostConfigFile, VOID *pReserved,
89 DWORD startupFlags, REFCLSID rclsid,
90 REFIID riid, LPVOID *ppv)
92 HRESULT ret;
93 ICLRRuntimeInfo *info;
95 TRACE("(%s, %s, %s, %p, %d, %s, %s, %p)\n", debugstr_w(pwszVersion),
96 debugstr_w(pwszBuildFlavor), debugstr_w(pwszHostConfigFile), pReserved,
97 startupFlags, debugstr_guid(rclsid), debugstr_guid(riid), ppv);
99 *ppv = NULL;
101 ret = get_runtime_info(NULL, pwszVersion, pwszHostConfigFile, startupFlags, 0, TRUE, &info);
103 if (SUCCEEDED(ret))
105 ret = ICLRRuntimeInfo_GetInterface(info, rclsid, riid, ppv);
107 ICLRRuntimeInfo_Release(info);
110 return ret;
113 BOOL WINAPI DllMain(HINSTANCE hinstDLL, DWORD fdwReason, LPVOID lpvReserved)
115 TRACE("(%p, %d, %p)\n", hinstDLL, fdwReason, lpvReserved);
117 switch (fdwReason)
119 case DLL_WINE_PREATTACH:
120 return FALSE; /* prefer native version */
121 case DLL_PROCESS_ATTACH:
122 DisableThreadLibraryCalls(hinstDLL);
123 break;
124 case DLL_PROCESS_DETACH:
125 expect_no_runtimes();
126 break;
128 return TRUE;
131 BOOL WINAPI _CorDllMain(HINSTANCE hinstDLL, DWORD fdwReason, LPVOID lpvReserved)
133 FIXME("(%p, %d, %p): stub\n", hinstDLL, fdwReason, lpvReserved);
135 switch (fdwReason)
137 case DLL_PROCESS_ATTACH:
138 DisableThreadLibraryCalls(hinstDLL);
139 break;
140 case DLL_PROCESS_DETACH:
141 break;
143 return TRUE;
146 __int32 WINAPI _CorExeMain2(PBYTE ptrMemory, DWORD cntMemory, LPWSTR imageName, LPWSTR loaderName, LPWSTR cmdLine)
148 TRACE("(%p, %u, %s, %s, %s)\n", ptrMemory, cntMemory, debugstr_w(imageName), debugstr_w(loaderName), debugstr_w(cmdLine));
149 FIXME("Directly running .NET applications not supported.\n");
150 return -1;
153 void WINAPI CorExitProcess(int exitCode)
155 TRACE("(%x)\n", exitCode);
156 unload_all_runtimes();
157 ExitProcess(exitCode);
160 VOID WINAPI _CorImageUnloading(PVOID imageBase)
162 TRACE("(%p): stub\n", imageBase);
165 HRESULT WINAPI _CorValidateImage(PVOID* imageBase, LPCWSTR imageName)
167 TRACE("(%p, %s): stub\n", imageBase, debugstr_w(imageName));
168 return E_FAIL;
171 HRESULT WINAPI GetCORSystemDirectory(LPWSTR pbuffer, DWORD cchBuffer, DWORD *dwLength)
173 ICLRRuntimeInfo *info;
174 HRESULT ret;
176 TRACE("(%p, %d, %p)!\n", pbuffer, cchBuffer, dwLength);
178 if (!dwLength || !pbuffer)
179 return E_POINTER;
181 ret = get_runtime_info(NULL, NULL, NULL, 0, RUNTIME_INFO_UPGRADE_VERSION, TRUE, &info);
183 if (SUCCEEDED(ret))
185 *dwLength = cchBuffer;
186 ret = ICLRRuntimeInfo_GetRuntimeDirectory(info, pbuffer, dwLength);
188 ICLRRuntimeInfo_Release(info);
191 return ret;
194 HRESULT WINAPI GetCORVersion(LPWSTR pbuffer, DWORD cchBuffer, DWORD *dwLength)
196 ICLRRuntimeInfo *info;
197 HRESULT ret;
199 TRACE("(%p, %d, %p)!\n", pbuffer, cchBuffer, dwLength);
201 if (!dwLength || !pbuffer)
202 return E_POINTER;
204 ret = get_runtime_info(NULL, NULL, NULL, 0, RUNTIME_INFO_UPGRADE_VERSION, TRUE, &info);
206 if (SUCCEEDED(ret))
208 *dwLength = cchBuffer;
209 ret = ICLRRuntimeInfo_GetVersionString(info, pbuffer, dwLength);
211 ICLRRuntimeInfo_Release(info);
214 return ret;
217 HRESULT WINAPI GetRequestedRuntimeInfo(LPCWSTR pExe, LPCWSTR pwszVersion, LPCWSTR pConfigurationFile,
218 DWORD startupFlags, DWORD runtimeInfoFlags, LPWSTR pDirectory, DWORD dwDirectory, DWORD *dwDirectoryLength,
219 LPWSTR pVersion, DWORD cchBuffer, DWORD *dwlength)
221 HRESULT ret;
222 ICLRRuntimeInfo *info;
223 DWORD length_dummy;
225 TRACE("(%s, %s, %s, 0x%08x, 0x%08x, %p, 0x%08x, %p, %p, 0x%08x, %p)\n", debugstr_w(pExe),
226 debugstr_w(pwszVersion), debugstr_w(pConfigurationFile), startupFlags, runtimeInfoFlags, pDirectory,
227 dwDirectory, dwDirectoryLength, pVersion, cchBuffer, dwlength);
229 if (!dwDirectoryLength) dwDirectoryLength = &length_dummy;
231 if (!dwlength) dwlength = &length_dummy;
233 ret = get_runtime_info(pExe, pwszVersion, pConfigurationFile, startupFlags, runtimeInfoFlags, TRUE, &info);
235 if (SUCCEEDED(ret))
237 *dwlength = cchBuffer;
238 ret = ICLRRuntimeInfo_GetVersionString(info, pVersion, dwlength);
240 if (SUCCEEDED(ret))
242 *dwDirectoryLength = dwDirectory;
243 ret = ICLRRuntimeInfo_GetRuntimeDirectory(info, pDirectory, dwDirectoryLength);
246 ICLRRuntimeInfo_Release(info);
249 return ret;
252 HRESULT WINAPI GetRequestedRuntimeVersion(LPWSTR pExe, LPWSTR pVersion, DWORD cchBuffer, DWORD *dwlength)
254 TRACE("(%s, %p, %d, %p)\n", debugstr_w(pExe), debugstr_w(pExe), cchBuffer, dwlength);
256 if(!dwlength)
257 return E_POINTER;
259 return GetRequestedRuntimeInfo(pExe, NULL, NULL, 0, 0, NULL, 0, NULL, pVersion, cchBuffer, dwlength);
262 HRESULT WINAPI GetRealProcAddress(LPCSTR procname, void **ppv)
264 FIXME("(%s, %p)\n", debugstr_a(procname), ppv);
265 return CLR_E_SHIM_RUNTIMEEXPORT;
268 HRESULT WINAPI GetFileVersion(LPCWSTR szFilename, LPWSTR szBuffer, DWORD cchBuffer, DWORD *dwLength)
270 TRACE("(%s, %p, %d, %p)\n", debugstr_w(szFilename), szBuffer, cchBuffer, dwLength);
272 if (!szFilename || !dwLength)
273 return E_POINTER;
275 *dwLength = cchBuffer;
276 return CLRMetaHost_GetVersionFromFile(0, szFilename, szBuffer, dwLength);
279 HRESULT WINAPI LoadLibraryShim( LPCWSTR szDllName, LPCWSTR szVersion, LPVOID pvReserved, HMODULE * phModDll)
281 HRESULT ret=S_OK;
282 WCHAR dll_filename[MAX_PATH];
283 WCHAR version[MAX_PATH];
284 static const WCHAR default_version[] = {'v','1','.','1','.','4','3','2','2',0};
285 static const WCHAR slash[] = {'\\',0};
286 DWORD dummy;
288 TRACE("(%p %s, %p, %p, %p)\n", szDllName, debugstr_w(szDllName), szVersion, pvReserved, phModDll);
290 if (!szDllName || !phModDll)
291 return E_POINTER;
293 if (!get_install_root(dll_filename))
295 ERR("error reading registry key for installroot\n");
296 dll_filename[0] = 0;
298 else
300 if (!szVersion)
302 ret = GetCORVersion(version, MAX_PATH, &dummy);
303 if (SUCCEEDED(ret))
304 szVersion = version;
305 else
306 szVersion = default_version;
308 strcatW(dll_filename, szVersion);
309 strcatW(dll_filename, slash);
312 strcatW(dll_filename, szDllName);
314 *phModDll = LoadLibraryW(dll_filename);
316 return *phModDll ? S_OK : E_HANDLE;
319 HRESULT WINAPI LockClrVersion(FLockClrVersionCallback hostCallback, FLockClrVersionCallback *pBeginHostSetup, FLockClrVersionCallback *pEndHostSetup)
321 FIXME("(%p %p %p): stub\n", hostCallback, pBeginHostSetup, pEndHostSetup);
322 return S_OK;
325 HRESULT WINAPI CoInitializeCor(DWORD fFlags)
327 FIXME("(0x%08x): stub\n", fFlags);
328 return S_OK;
331 HRESULT WINAPI GetAssemblyMDImport(LPCWSTR szFileName, REFIID riid, IUnknown **ppIUnk)
333 FIXME("(%p %s, %s, %p): stub\n", szFileName, debugstr_w(szFileName), debugstr_guid(riid), *ppIUnk);
334 return ERROR_CALL_NOT_IMPLEMENTED;
337 HRESULT WINAPI GetVersionFromProcess(HANDLE hProcess, LPWSTR pVersion, DWORD cchBuffer, DWORD *dwLength)
339 FIXME("(%p, %p, %d, %p): stub\n", hProcess, pVersion, cchBuffer, dwLength);
340 return E_NOTIMPL;
343 HRESULT WINAPI LoadStringRCEx(LCID culture, UINT resId, LPWSTR pBuffer, int iBufLen, int bQuiet, int* pBufLen)
345 HRESULT res = S_OK;
346 if ((iBufLen <= 0) || !pBuffer)
347 return E_INVALIDARG;
348 pBuffer[0] = 0;
349 if (resId) {
350 FIXME("(%d, %x, %p, %d, %d, %p): semi-stub\n", culture, resId, pBuffer, iBufLen, bQuiet, pBufLen);
351 res = E_NOTIMPL;
353 else
354 res = E_FAIL;
355 if (pBufLen)
356 *pBufLen = lstrlenW(pBuffer);
357 return res;
360 HRESULT WINAPI LoadStringRC(UINT resId, LPWSTR pBuffer, int iBufLen, int bQuiet)
362 return LoadStringRCEx(-1, resId, pBuffer, iBufLen, bQuiet, NULL);
365 HRESULT WINAPI CorBindToRuntimeEx(LPWSTR szVersion, LPWSTR szBuildFlavor, DWORD nflags, REFCLSID rslsid,
366 REFIID riid, LPVOID *ppv)
368 HRESULT ret;
369 ICLRRuntimeInfo *info;
371 TRACE("%s %s %d %s %s %p\n", debugstr_w(szVersion), debugstr_w(szBuildFlavor), nflags, debugstr_guid( rslsid ),
372 debugstr_guid( riid ), ppv);
374 *ppv = NULL;
376 ret = get_runtime_info(NULL, szVersion, NULL, nflags, RUNTIME_INFO_UPGRADE_VERSION, TRUE, &info);
378 if (SUCCEEDED(ret))
380 ret = ICLRRuntimeInfo_GetInterface(info, rslsid, riid, ppv);
382 ICLRRuntimeInfo_Release(info);
385 return ret;
388 HRESULT WINAPI CorBindToCurrentRuntime(LPCWSTR filename, REFCLSID rclsid, REFIID riid, LPVOID *ppv)
390 FIXME("(%s, %s, %s, %p): stub\n", debugstr_w(filename), debugstr_guid(rclsid), debugstr_guid(riid), ppv);
391 return E_NOTIMPL;
394 STDAPI ClrCreateManagedInstance(LPCWSTR pTypeName, REFIID riid, void **ppObject)
396 HRESULT ret;
397 ICLRRuntimeInfo *info;
398 RuntimeHost *host;
399 MonoObject *obj;
400 IUnknown *unk;
402 TRACE("(%s,%s,%p)\n", debugstr_w(pTypeName), debugstr_guid(riid), ppObject);
404 /* FIXME: How to determine which runtime version to use? */
405 ret = get_runtime_info(NULL, NULL, NULL, 0, RUNTIME_INFO_UPGRADE_VERSION, TRUE, &info);
407 if (SUCCEEDED(ret))
409 ret = ICLRRuntimeInfo_GetRuntimeHost(info, &host);
411 ICLRRuntimeInfo_Release(info);
414 if (SUCCEEDED(ret))
415 ret = RuntimeHost_CreateManagedInstance(host, pTypeName, NULL, &obj);
417 if (SUCCEEDED(ret))
418 ret = RuntimeHost_GetIUnknownForObject(host, obj, &unk);
420 if (SUCCEEDED(ret))
422 ret = IUnknown_QueryInterface(unk, riid, ppObject);
423 IUnknown_Release(unk);
426 return ret;
429 BOOL WINAPI StrongNameSignatureVerification(LPCWSTR filename, DWORD inFlags, DWORD* pOutFlags)
431 FIXME("(%s, 0x%X, %p): stub\n", debugstr_w(filename), inFlags, pOutFlags);
432 return FALSE;
435 BOOL WINAPI StrongNameSignatureVerificationEx(LPCWSTR filename, BOOL forceVerification, BOOL* pVerified)
437 FIXME("(%s, %u, %p): stub\n", debugstr_w(filename), forceVerification, pVerified);
438 return FALSE;
441 HRESULT WINAPI CreateConfigStream(LPCWSTR filename, IStream **stream)
443 FIXME("(%s, %p): stub\n", debugstr_w(filename), stream);
444 return E_NOTIMPL;
447 HRESULT WINAPI CreateDebuggingInterfaceFromVersion(int nDebugVersion, LPCWSTR version, IUnknown **ppIUnk)
449 FIXME("(%d %s, %p): stub\n", nDebugVersion, debugstr_w(version), ppIUnk);
450 return E_NOTIMPL;
453 HRESULT WINAPI CLRCreateInstance(REFCLSID clsid, REFIID riid, LPVOID *ppInterface)
455 TRACE("(%s,%s,%p)\n", debugstr_guid(clsid), debugstr_guid(riid), ppInterface);
457 if (IsEqualGUID(clsid, &CLSID_CLRMetaHost))
458 return CLRMetaHost_CreateInstance(riid, ppInterface);
460 FIXME("not implemented for class %s\n", debugstr_guid(clsid));
462 return CLASS_E_CLASSNOTAVAILABLE;
465 HRESULT WINAPI DllGetClassObject(REFCLSID rclsid, REFIID riid, LPVOID* ppv)
467 FIXME("(%s, %s, %p): stub\n", debugstr_guid(rclsid), debugstr_guid(riid), ppv);
468 if(!ppv)
469 return E_INVALIDARG;
471 return E_NOTIMPL;
474 HRESULT WINAPI DllRegisterServer(void)
476 FIXME("\n");
477 return S_OK;
480 HRESULT WINAPI DllUnregisterServer(void)
482 FIXME("\n");
483 return S_OK;
486 HRESULT WINAPI DllCanUnloadNow(VOID)
488 return S_FALSE;
491 INT WINAPI ND_RU1( const void *ptr, INT offset )
493 return *((const BYTE *)ptr + offset);
496 INT WINAPI ND_RI2( const void *ptr, INT offset )
498 return *(const SHORT *)((const BYTE *)ptr + offset);
501 INT WINAPI ND_RI4( const void *ptr, INT offset )
503 return *(const INT *)((const BYTE *)ptr + offset);
506 INT64 WINAPI ND_RI8( const void *ptr, INT offset )
508 return *(const INT64 *)((const BYTE *)ptr + offset);
511 void WINAPI ND_WU1( void *ptr, INT offset, BYTE val )
513 *((BYTE *)ptr + offset) = val;
516 void WINAPI ND_WI2( void *ptr, INT offset, SHORT val )
518 *(SHORT *)((BYTE *)ptr + offset) = val;
521 void WINAPI ND_WI4( void *ptr, INT offset, INT val )
523 *(INT *)((BYTE *)ptr + offset) = val;
526 void WINAPI ND_WI8( void *ptr, INT offset, INT64 val )
528 *(INT64 *)((BYTE *)ptr + offset) = val;
531 void WINAPI ND_CopyObjDst( const void *src, void *dst, INT offset, INT size )
533 memcpy( (BYTE *)dst + offset, src, size );
536 void WINAPI ND_CopyObjSrc( const void *src, INT offset, void *dst, INT size )
538 memcpy( dst, (const BYTE *)src + offset, size );