mscoree: Update Wine Mono to 4.8.0.
[wine.git] / dlls / mscoree / mscoree_main.c
blob785ecd0404019662bf734bb3c919e30d8c760003
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 "corerror.h"
39 #include "cor.h"
40 #include "mscoree.h"
41 #include "corhdr.h"
42 #include "cordebug.h"
43 #include "metahost.h"
44 #include "fusion.h"
45 #include "wine/list.h"
46 #include "mscoree_private.h"
47 #include "rpcproxy.h"
49 #include "wine/debug.h"
51 WINE_DEFAULT_DEBUG_CHANNEL( mscoree );
52 WINE_DECLARE_DEBUG_CHANNEL(winediag);
54 static HINSTANCE MSCOREE_hInstance;
56 typedef HRESULT (*fnCreateInstance)(REFIID riid, LPVOID *ppObj);
58 char *WtoA(LPCWSTR wstr)
60 int length;
61 char *result;
63 length = WideCharToMultiByte(CP_UTF8, 0, wstr, -1, NULL, 0, NULL, NULL);
65 result = HeapAlloc(GetProcessHeap(), 0, length);
67 if (result)
68 WideCharToMultiByte(CP_UTF8, 0, wstr, -1, result, length, NULL, NULL);
70 return result;
73 static BOOL get_install_root(LPWSTR install_dir)
75 static 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};
76 static const WCHAR install_root[] = {'I','n','s','t','a','l','l','R','o','o','t',0};
78 DWORD len;
79 HKEY key;
81 if (RegOpenKeyExW(HKEY_LOCAL_MACHINE, dotnet_key, 0, KEY_READ, &key))
82 return FALSE;
84 len = MAX_PATH;
85 if (RegQueryValueExW(key, install_root, 0, NULL, (LPBYTE)install_dir, &len))
87 RegCloseKey(key);
88 return FALSE;
90 RegCloseKey(key);
92 return TRUE;
95 typedef struct mscorecf
97 IClassFactory IClassFactory_iface;
98 LONG ref;
100 fnCreateInstance pfnCreateInstance;
102 CLSID clsid;
103 } mscorecf;
105 static inline mscorecf *impl_from_IClassFactory( IClassFactory *iface )
107 return CONTAINING_RECORD(iface, mscorecf, IClassFactory_iface);
110 static HRESULT WINAPI mscorecf_QueryInterface(IClassFactory *iface, REFIID riid, LPVOID *ppobj )
112 TRACE("%s %p\n", debugstr_guid(riid), ppobj);
114 if (IsEqualGUID(riid, &IID_IUnknown) ||
115 IsEqualGUID(riid, &IID_IClassFactory))
117 IClassFactory_AddRef( iface );
118 *ppobj = iface;
119 return S_OK;
122 ERR("interface %s not implemented\n", debugstr_guid(riid));
123 return E_NOINTERFACE;
126 static ULONG WINAPI mscorecf_AddRef(IClassFactory *iface )
128 mscorecf *This = impl_from_IClassFactory(iface);
129 ULONG ref = InterlockedIncrement(&This->ref);
131 TRACE("%p ref=%u\n", This, ref);
133 return ref;
136 static ULONG WINAPI mscorecf_Release(IClassFactory *iface )
138 mscorecf *This = impl_from_IClassFactory(iface);
139 ULONG ref = InterlockedDecrement(&This->ref);
141 TRACE("%p ref=%u\n", This, ref);
143 if (ref == 0)
145 HeapFree(GetProcessHeap(), 0, This);
148 return ref;
151 static HRESULT WINAPI mscorecf_CreateInstance(IClassFactory *iface,LPUNKNOWN pOuter,
152 REFIID riid, LPVOID *ppobj )
154 mscorecf *This = impl_from_IClassFactory( iface );
155 HRESULT hr;
156 IUnknown *punk;
158 TRACE("%p %s %p\n", pOuter, debugstr_guid(riid), ppobj );
160 *ppobj = NULL;
162 if (pOuter)
163 return CLASS_E_NOAGGREGATION;
165 hr = This->pfnCreateInstance( &This->clsid, (LPVOID*) &punk );
166 if (SUCCEEDED(hr))
168 hr = IUnknown_QueryInterface( punk, riid, ppobj );
170 IUnknown_Release( punk );
172 else
174 WARN("Cannot create an instance object. 0x%08x\n", hr);
176 return hr;
179 static HRESULT WINAPI mscorecf_LockServer(IClassFactory *iface, BOOL dolock)
181 FIXME("(%p)->(%d),stub!\n",iface,dolock);
182 return S_OK;
185 static const struct IClassFactoryVtbl mscorecf_vtbl =
187 mscorecf_QueryInterface,
188 mscorecf_AddRef,
189 mscorecf_Release,
190 mscorecf_CreateInstance,
191 mscorecf_LockServer
194 HRESULT WINAPI CorBindToRuntimeHost(LPCWSTR pwszVersion, LPCWSTR pwszBuildFlavor,
195 LPCWSTR pwszHostConfigFile, VOID *pReserved,
196 DWORD startupFlags, REFCLSID rclsid,
197 REFIID riid, LPVOID *ppv)
199 HRESULT ret;
200 ICLRRuntimeInfo *info;
202 TRACE("(%s, %s, %s, %p, %d, %s, %s, %p)\n", debugstr_w(pwszVersion),
203 debugstr_w(pwszBuildFlavor), debugstr_w(pwszHostConfigFile), pReserved,
204 startupFlags, debugstr_guid(rclsid), debugstr_guid(riid), ppv);
206 *ppv = NULL;
208 ret = get_runtime_info(NULL, pwszVersion, pwszHostConfigFile, startupFlags, 0, TRUE, &info);
210 if (SUCCEEDED(ret))
212 ret = ICLRRuntimeInfo_GetInterface(info, rclsid, riid, ppv);
214 ICLRRuntimeInfo_Release(info);
217 return ret;
220 BOOL WINAPI DllMain(HINSTANCE hinstDLL, DWORD fdwReason, LPVOID lpvReserved)
222 TRACE("(%p, %d, %p)\n", hinstDLL, fdwReason, lpvReserved);
224 MSCOREE_hInstance = hinstDLL;
226 switch (fdwReason)
228 case DLL_WINE_PREATTACH:
229 return FALSE; /* prefer native version */
230 case DLL_PROCESS_ATTACH:
231 runtimehost_init();
232 DisableThreadLibraryCalls(hinstDLL);
233 break;
234 case DLL_PROCESS_DETACH:
235 expect_no_runtimes();
236 if (lpvReserved) break; /* process is terminating */
237 runtimehost_uninit();
238 break;
240 return TRUE;
243 __int32 WINAPI _CorExeMain2(PBYTE ptrMemory, DWORD cntMemory, LPWSTR imageName, LPWSTR loaderName, LPWSTR cmdLine)
245 TRACE("(%p, %u, %s, %s, %s)\n", ptrMemory, cntMemory, debugstr_w(imageName), debugstr_w(loaderName), debugstr_w(cmdLine));
246 FIXME("Directly running .NET applications not supported.\n");
247 return -1;
250 void WINAPI CorExitProcess(int exitCode)
252 TRACE("(%x)\n", exitCode);
253 CLRMetaHost_ExitProcess(0, exitCode);
256 VOID WINAPI _CorImageUnloading(PVOID imageBase)
258 TRACE("(%p): stub\n", imageBase);
261 HRESULT WINAPI _CorValidateImage(PVOID* imageBase, LPCWSTR imageName)
263 TRACE("(%p, %s): stub\n", imageBase, debugstr_w(imageName));
264 return E_FAIL;
267 HRESULT WINAPI GetCORSystemDirectory(LPWSTR pbuffer, DWORD cchBuffer, DWORD *dwLength)
269 ICLRRuntimeInfo *info;
270 HRESULT ret;
272 TRACE("(%p, %d, %p)!\n", pbuffer, cchBuffer, dwLength);
274 if (!dwLength || !pbuffer)
275 return E_POINTER;
277 ret = get_runtime_info(NULL, NULL, NULL, 0, RUNTIME_INFO_UPGRADE_VERSION, TRUE, &info);
279 if (SUCCEEDED(ret))
281 *dwLength = cchBuffer;
282 ret = ICLRRuntimeInfo_GetRuntimeDirectory(info, pbuffer, dwLength);
284 ICLRRuntimeInfo_Release(info);
287 return ret;
290 HRESULT WINAPI GetCORVersion(LPWSTR pbuffer, DWORD cchBuffer, DWORD *dwLength)
292 ICLRRuntimeInfo *info;
293 HRESULT ret;
295 TRACE("(%p, %d, %p)!\n", pbuffer, cchBuffer, dwLength);
297 if (!dwLength || !pbuffer)
298 return E_POINTER;
300 ret = get_runtime_info(NULL, NULL, NULL, 0, RUNTIME_INFO_UPGRADE_VERSION, TRUE, &info);
302 if (SUCCEEDED(ret))
304 *dwLength = cchBuffer;
305 ret = ICLRRuntimeInfo_GetVersionString(info, pbuffer, dwLength);
307 ICLRRuntimeInfo_Release(info);
310 return ret;
313 HRESULT WINAPI CorIsLatestSvc(int *unk1, int *unk2)
315 ERR_(winediag)("If this function is called, it is likely the result of a broken .NET installation\n");
317 if (!unk1 || !unk2)
318 return E_POINTER;
320 return S_OK;
323 HRESULT WINAPI GetRequestedRuntimeInfo(LPCWSTR pExe, LPCWSTR pwszVersion, LPCWSTR pConfigurationFile,
324 DWORD startupFlags, DWORD runtimeInfoFlags, LPWSTR pDirectory, DWORD dwDirectory, DWORD *dwDirectoryLength,
325 LPWSTR pVersion, DWORD cchBuffer, DWORD *dwlength)
327 HRESULT ret;
328 ICLRRuntimeInfo *info;
329 DWORD length_dummy;
331 TRACE("(%s, %s, %s, 0x%08x, 0x%08x, %p, 0x%08x, %p, %p, 0x%08x, %p)\n", debugstr_w(pExe),
332 debugstr_w(pwszVersion), debugstr_w(pConfigurationFile), startupFlags, runtimeInfoFlags, pDirectory,
333 dwDirectory, dwDirectoryLength, pVersion, cchBuffer, dwlength);
335 if (!dwDirectoryLength) dwDirectoryLength = &length_dummy;
337 if (!dwlength) dwlength = &length_dummy;
339 ret = get_runtime_info(pExe, pwszVersion, pConfigurationFile, startupFlags, runtimeInfoFlags, TRUE, &info);
341 if (SUCCEEDED(ret))
343 *dwlength = cchBuffer;
344 ret = ICLRRuntimeInfo_GetVersionString(info, pVersion, dwlength);
346 if (SUCCEEDED(ret))
348 if(pwszVersion)
349 pVersion[0] = pwszVersion[0];
351 *dwDirectoryLength = dwDirectory;
352 ret = ICLRRuntimeInfo_GetRuntimeDirectory(info, pDirectory, dwDirectoryLength);
355 ICLRRuntimeInfo_Release(info);
358 return ret;
361 HRESULT WINAPI GetRequestedRuntimeVersion(LPWSTR pExe, LPWSTR pVersion, DWORD cchBuffer, DWORD *dwlength)
363 TRACE("(%s, %p, %d, %p)\n", debugstr_w(pExe), pVersion, cchBuffer, dwlength);
365 if(!dwlength)
366 return E_POINTER;
368 return GetRequestedRuntimeInfo(pExe, NULL, NULL, 0, 0, NULL, 0, NULL, pVersion, cchBuffer, dwlength);
371 HRESULT WINAPI GetRealProcAddress(LPCSTR procname, void **ppv)
373 FIXME("(%s, %p)\n", debugstr_a(procname), ppv);
374 return CLR_E_SHIM_RUNTIMEEXPORT;
377 HRESULT WINAPI GetFileVersion(LPCWSTR szFilename, LPWSTR szBuffer, DWORD cchBuffer, DWORD *dwLength)
379 TRACE("(%s, %p, %d, %p)\n", debugstr_w(szFilename), szBuffer, cchBuffer, dwLength);
381 if (!szFilename || !dwLength)
382 return E_POINTER;
384 *dwLength = cchBuffer;
385 return CLRMetaHost_GetVersionFromFile(0, szFilename, szBuffer, dwLength);
388 HRESULT WINAPI LoadLibraryShim( LPCWSTR szDllName, LPCWSTR szVersion, LPVOID pvReserved, HMODULE * phModDll)
390 HRESULT ret=S_OK;
391 WCHAR dll_filename[MAX_PATH];
392 WCHAR version[MAX_PATH];
393 static const WCHAR default_version[] = {'v','1','.','1','.','4','3','2','2',0};
394 static const WCHAR slash[] = {'\\',0};
395 DWORD dummy;
397 TRACE("(%p %s, %p, %p, %p)\n", szDllName, debugstr_w(szDllName), szVersion, pvReserved, phModDll);
399 if (!szDllName || !phModDll)
400 return E_POINTER;
402 if (!get_install_root(dll_filename))
404 ERR("error reading registry key for installroot\n");
405 dll_filename[0] = 0;
407 else
409 if (!szVersion)
411 ret = GetCORVersion(version, MAX_PATH, &dummy);
412 if (SUCCEEDED(ret))
413 szVersion = version;
414 else
415 szVersion = default_version;
417 strcatW(dll_filename, szVersion);
418 strcatW(dll_filename, slash);
421 strcatW(dll_filename, szDllName);
423 *phModDll = LoadLibraryW(dll_filename);
425 return *phModDll ? S_OK : E_HANDLE;
428 HRESULT WINAPI LockClrVersion(FLockClrVersionCallback hostCallback, FLockClrVersionCallback *pBeginHostSetup, FLockClrVersionCallback *pEndHostSetup)
430 FIXME("(%p %p %p): stub\n", hostCallback, pBeginHostSetup, pEndHostSetup);
431 return S_OK;
434 HRESULT WINAPI CoInitializeCor(DWORD fFlags)
436 FIXME("(0x%08x): stub\n", fFlags);
437 return S_OK;
440 HRESULT WINAPI GetAssemblyMDImport(LPCWSTR szFileName, REFIID riid, IUnknown **ppIUnk)
442 FIXME("(%p %s, %s, %p): stub\n", szFileName, debugstr_w(szFileName), debugstr_guid(riid), *ppIUnk);
443 return ERROR_CALL_NOT_IMPLEMENTED;
446 HRESULT WINAPI GetVersionFromProcess(HANDLE hProcess, LPWSTR pVersion, DWORD cchBuffer, DWORD *dwLength)
448 FIXME("(%p, %p, %d, %p): stub\n", hProcess, pVersion, cchBuffer, dwLength);
449 return E_NOTIMPL;
452 HRESULT WINAPI LoadStringRCEx(LCID culture, UINT resId, LPWSTR pBuffer, int iBufLen, int bQuiet, int* pBufLen)
454 HRESULT res = S_OK;
455 if ((iBufLen <= 0) || !pBuffer)
456 return E_INVALIDARG;
457 pBuffer[0] = 0;
458 if (resId) {
459 FIXME("(%d, %x, %p, %d, %d, %p): semi-stub\n", culture, resId, pBuffer, iBufLen, bQuiet, pBufLen);
460 res = E_NOTIMPL;
462 else
463 res = E_FAIL;
464 if (pBufLen)
465 *pBufLen = lstrlenW(pBuffer);
466 return res;
469 HRESULT WINAPI LoadStringRC(UINT resId, LPWSTR pBuffer, int iBufLen, int bQuiet)
471 return LoadStringRCEx(-1, resId, pBuffer, iBufLen, bQuiet, NULL);
474 HRESULT WINAPI CorBindToRuntimeEx(LPWSTR szVersion, LPWSTR szBuildFlavor, DWORD nflags, REFCLSID rslsid,
475 REFIID riid, LPVOID *ppv)
477 HRESULT ret;
478 ICLRRuntimeInfo *info;
480 TRACE("%s %s %d %s %s %p\n", debugstr_w(szVersion), debugstr_w(szBuildFlavor), nflags, debugstr_guid( rslsid ),
481 debugstr_guid( riid ), ppv);
483 *ppv = NULL;
485 ret = get_runtime_info(NULL, szVersion, NULL, nflags, RUNTIME_INFO_UPGRADE_VERSION, TRUE, &info);
487 if (SUCCEEDED(ret))
489 ret = ICLRRuntimeInfo_GetInterface(info, rslsid, riid, ppv);
491 ICLRRuntimeInfo_Release(info);
494 return ret;
497 HRESULT WINAPI CorBindToCurrentRuntime(LPCWSTR filename, REFCLSID rclsid, REFIID riid, LPVOID *ppv)
499 HRESULT ret;
500 ICLRRuntimeInfo *info;
502 TRACE("(%s, %s, %s, %p)\n", debugstr_w(filename), debugstr_guid(rclsid), debugstr_guid(riid), ppv);
504 *ppv = NULL;
506 ret = get_runtime_info(NULL, NULL, filename, 0, RUNTIME_INFO_UPGRADE_VERSION, TRUE, &info);
508 if (SUCCEEDED(ret))
510 ret = ICLRRuntimeInfo_GetInterface(info, rclsid, riid, ppv);
512 ICLRRuntimeInfo_Release(info);
515 return ret;
518 STDAPI ClrCreateManagedInstance(LPCWSTR pTypeName, REFIID riid, void **ppObject)
520 HRESULT ret;
521 ICLRRuntimeInfo *info;
522 RuntimeHost *host;
523 MonoObject *obj;
524 IUnknown *unk;
526 TRACE("(%s,%s,%p)\n", debugstr_w(pTypeName), debugstr_guid(riid), ppObject);
528 /* FIXME: How to determine which runtime version to use? */
529 ret = get_runtime_info(NULL, NULL, NULL, 0, RUNTIME_INFO_UPGRADE_VERSION, TRUE, &info);
531 if (SUCCEEDED(ret))
533 ret = ICLRRuntimeInfo_GetRuntimeHost(info, &host);
535 ICLRRuntimeInfo_Release(info);
538 if (SUCCEEDED(ret))
539 ret = RuntimeHost_CreateManagedInstance(host, pTypeName, NULL, &obj);
541 if (SUCCEEDED(ret))
542 ret = RuntimeHost_GetIUnknownForObject(host, obj, &unk);
544 if (SUCCEEDED(ret))
546 ret = IUnknown_QueryInterface(unk, riid, ppObject);
547 IUnknown_Release(unk);
550 return ret;
553 BOOL WINAPI StrongNameSignatureVerification(LPCWSTR filename, DWORD inFlags, DWORD* pOutFlags)
555 FIXME("(%s, 0x%X, %p): stub\n", debugstr_w(filename), inFlags, pOutFlags);
556 return FALSE;
559 BOOL WINAPI StrongNameSignatureVerificationEx(LPCWSTR filename, BOOL forceVerification, BOOL* pVerified)
561 FIXME("(%s, %u, %p): stub\n", debugstr_w(filename), forceVerification, pVerified);
562 return FALSE;
565 HRESULT WINAPI CreateDebuggingInterfaceFromVersion(int nDebugVersion, LPCWSTR version, IUnknown **ppv)
567 static const WCHAR v2_0[] = {'v','2','.','0','.','5','0','7','2','7',0};
568 HRESULT hr = E_FAIL;
569 ICLRRuntimeInfo *runtimeinfo;
571 if(nDebugVersion < 1 || nDebugVersion > 4)
572 return E_INVALIDARG;
574 TRACE("(%d %s, %p): stub\n", nDebugVersion, debugstr_w(version), ppv);
576 if(!ppv)
577 return E_INVALIDARG;
579 *ppv = NULL;
581 if(strcmpW(version, v2_0) != 0)
583 FIXME("Currently .NET Version '%s' not support.\n", debugstr_w(version));
584 return E_INVALIDARG;
587 if(nDebugVersion != 3)
588 return E_INVALIDARG;
590 hr = CLRMetaHost_GetRuntime(0, version, &IID_ICLRRuntimeInfo, (void**)&runtimeinfo);
591 if(hr == S_OK)
593 hr = ICLRRuntimeInfo_GetInterface(runtimeinfo, &CLSID_CLRDebuggingLegacy, &IID_ICorDebug, (void**)ppv);
595 ICLRRuntimeInfo_Release(runtimeinfo);
598 if(!*ppv)
599 return E_FAIL;
601 return hr;
604 HRESULT WINAPI CLRCreateInstance(REFCLSID clsid, REFIID riid, LPVOID *ppInterface)
606 TRACE("(%s,%s,%p)\n", debugstr_guid(clsid), debugstr_guid(riid), ppInterface);
608 if (IsEqualGUID(clsid, &CLSID_CLRMetaHost))
609 return CLRMetaHost_CreateInstance(riid, ppInterface);
610 if (IsEqualGUID(clsid, &CLSID_CLRMetaHostPolicy))
611 return CLRMetaHostPolicy_CreateInstance(riid, ppInterface);
613 FIXME("not implemented for class %s\n", debugstr_guid(clsid));
615 return CLASS_E_CLASSNOTAVAILABLE;
618 HRESULT WINAPI CreateInterface(REFCLSID clsid, REFIID riid, LPVOID *ppInterface)
620 TRACE("(%s,%s,%p)\n", debugstr_guid(clsid), debugstr_guid(riid), ppInterface);
622 return CLRCreateInstance(clsid, riid, ppInterface);
625 HRESULT WINAPI DllGetClassObject(REFCLSID rclsid, REFIID riid, LPVOID* ppv)
627 mscorecf *This;
628 HRESULT hr;
630 TRACE("(%s, %s, %p): stub\n", debugstr_guid(rclsid), debugstr_guid(riid), ppv);
632 if(!ppv)
633 return E_INVALIDARG;
635 This = HeapAlloc(GetProcessHeap(), 0, sizeof(mscorecf));
637 This->IClassFactory_iface.lpVtbl = &mscorecf_vtbl;
638 This->pfnCreateInstance = create_monodata;
639 This->ref = 1;
640 This->clsid = *rclsid;
642 hr = IClassFactory_QueryInterface( &This->IClassFactory_iface, riid, ppv );
643 IClassFactory_Release(&This->IClassFactory_iface);
645 return hr;
648 static void parse_msi_version_string(const char *version, int *parts)
650 const char *minor_start, *build_start;
652 parts[0] = atoi(version);
654 parts[1] = parts[2] = 0;
656 minor_start = strchr(version, '.');
657 if (minor_start)
659 minor_start++;
660 parts[1] = atoi(minor_start);
662 build_start = strchr(minor_start, '.');
663 if (build_start)
664 parts[2] = atoi(build_start+1);
668 static BOOL install_wine_mono(void)
670 BOOL is_wow64 = FALSE;
671 HMODULE hmsi;
672 UINT (WINAPI *pMsiEnumRelatedProductsA)(LPCSTR,DWORD,DWORD,LPSTR);
673 UINT (WINAPI *pMsiGetProductInfoA)(LPCSTR,LPCSTR,LPSTR,DWORD*);
674 char versionstringbuf[15];
675 char productcodebuf[39];
676 UINT res;
677 DWORD buffer_size;
678 PROCESS_INFORMATION pi;
679 STARTUPINFOW si;
680 WCHAR app[MAX_PATH];
681 WCHAR *args;
682 LONG len;
683 BOOL ret;
685 static const char* mono_version = "4.8.0";
686 static const char* mono_upgrade_code = "{DE624609-C6B5-486A-9274-EF0B854F6BC5}";
688 static const WCHAR controlW[] = {'\\','c','o','n','t','r','o','l','.','e','x','e',0};
689 static const WCHAR argsW[] =
690 {' ','a','p','p','w','i','z','.','c','p','l',' ','i','n','s','t','a','l','l','_','m','o','n','o',0};
692 IsWow64Process(GetCurrentProcess(), &is_wow64);
694 if (is_wow64)
696 TRACE("not installing mono in wow64 process\n");
697 return TRUE;
700 hmsi = LoadLibraryA("msi");
702 if (!hmsi)
704 ERR("couldn't load msi.dll\n");
705 return FALSE;
708 pMsiEnumRelatedProductsA = (void*)GetProcAddress(hmsi, "MsiEnumRelatedProductsA");
710 res = pMsiEnumRelatedProductsA(mono_upgrade_code, 0, 0, productcodebuf);
712 if (res == ERROR_SUCCESS)
714 pMsiGetProductInfoA = (void*)GetProcAddress(hmsi, "MsiGetProductInfoA");
716 buffer_size = sizeof(versionstringbuf);
718 res = pMsiGetProductInfoA(productcodebuf, "VersionString", versionstringbuf, &buffer_size);
720 else if (res != ERROR_NO_MORE_ITEMS)
722 ERR("MsiEnumRelatedProducts failed, err=%u\n", res);
725 FreeLibrary(hmsi);
727 if (res == ERROR_SUCCESS)
729 int current_version[3], wanted_version[3], i;
731 TRACE("found installed version %s\n", versionstringbuf);
733 parse_msi_version_string(versionstringbuf, current_version);
734 parse_msi_version_string(mono_version, wanted_version);
736 for (i=0; i<3; i++)
738 if (current_version[i] < wanted_version[i])
739 break;
740 else if (current_version[i] > wanted_version[i])
742 TRACE("installed version is newer than %s, quitting\n", mono_version);
743 return TRUE;
747 if (i == 3)
749 TRACE("version %s is already installed, quitting\n", mono_version);
750 return TRUE;
754 len = GetSystemDirectoryW(app, MAX_PATH - ARRAY_SIZE(controlW));
755 memcpy(app+len, controlW, sizeof(controlW));
757 args = HeapAlloc(GetProcessHeap(), 0, (len*sizeof(WCHAR) + sizeof(controlW) + sizeof(argsW)));
758 if(!args)
759 return FALSE;
761 memcpy(args, app, len*sizeof(WCHAR) + sizeof(controlW));
762 memcpy(args + len + ARRAY_SIZE(controlW) - 1, argsW, sizeof(argsW));
764 TRACE("starting %s\n", debugstr_w(args));
766 memset(&si, 0, sizeof(si));
767 si.cb = sizeof(si);
768 ret = CreateProcessW(app, args, NULL, NULL, FALSE, 0, NULL, NULL, &si, &pi);
769 HeapFree(GetProcessHeap(), 0, args);
770 if (ret) {
771 CloseHandle(pi.hThread);
772 WaitForSingleObject(pi.hProcess, INFINITE);
773 CloseHandle(pi.hProcess);
776 return ret;
779 HRESULT WINAPI DllRegisterServer(void)
781 install_wine_mono();
783 return __wine_register_resources( MSCOREE_hInstance );
786 HRESULT WINAPI DllUnregisterServer(void)
788 return __wine_unregister_resources( MSCOREE_hInstance );
791 HRESULT WINAPI DllCanUnloadNow(VOID)
793 return S_FALSE;
796 void WINAPI CoEEShutDownCOM(void)
798 FIXME("stub.\n");
801 INT WINAPI ND_RU1( const void *ptr, INT offset )
803 return *((const BYTE *)ptr + offset);
806 INT WINAPI ND_RI2( const void *ptr, INT offset )
808 return *(const SHORT *)((const BYTE *)ptr + offset);
811 INT WINAPI ND_RI4( const void *ptr, INT offset )
813 return *(const INT *)((const BYTE *)ptr + offset);
816 INT64 WINAPI ND_RI8( const void *ptr, INT offset )
818 return *(const INT64 *)((const BYTE *)ptr + offset);
821 void WINAPI ND_WU1( void *ptr, INT offset, BYTE val )
823 *((BYTE *)ptr + offset) = val;
826 void WINAPI ND_WI2( void *ptr, INT offset, SHORT val )
828 *(SHORT *)((BYTE *)ptr + offset) = val;
831 void WINAPI ND_WI4( void *ptr, INT offset, INT val )
833 *(INT *)((BYTE *)ptr + offset) = val;
836 void WINAPI ND_WI8( void *ptr, INT offset, INT64 val )
838 *(INT64 *)((BYTE *)ptr + offset) = val;
841 void WINAPI ND_CopyObjDst( const void *src, void *dst, INT offset, INT size )
843 memcpy( (BYTE *)dst + offset, src, size );
846 void WINAPI ND_CopyObjSrc( const void *src, INT offset, void *dst, INT size )
848 memcpy( dst, (const BYTE *)src + offset, size );