winebus.sys: Add missing keyboard free_device callback.
[wine.git] / dlls / mscoree / mscoree_main.c
bloba4567e96de2efb726f23f54c1b1624bf7010dda5
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 "windef.h"
26 #include "winbase.h"
27 #include "winuser.h"
28 #include "winnls.h"
29 #include "winreg.h"
30 #include "ole2.h"
31 #include "ocidl.h"
32 #include "shellapi.h"
33 #include "strongname.h"
35 #include "initguid.h"
36 #include "msxml2.h"
37 #include "corerror.h"
38 #include "cor.h"
39 #include "mscoree.h"
40 #include "corhdr.h"
41 #include "cordebug.h"
42 #include "metahost.h"
43 #include "fusion.h"
44 #include "wine/list.h"
45 #include "mscoree_private.h"
46 #include "rpcproxy.h"
48 #include "wine/debug.h"
50 WINE_DEFAULT_DEBUG_CHANNEL( mscoree );
51 WINE_DECLARE_DEBUG_CHANNEL(winediag);
53 typedef HRESULT (*fnCreateInstance)(REFIID riid, LPVOID *ppObj);
55 char *WtoA(LPCWSTR wstr)
57 int length;
58 char *result;
60 length = WideCharToMultiByte(CP_UTF8, 0, wstr, -1, NULL, 0, NULL, NULL);
62 result = HeapAlloc(GetProcessHeap(), 0, length);
64 if (result)
65 WideCharToMultiByte(CP_UTF8, 0, wstr, -1, result, length, NULL, NULL);
67 return result;
70 static BOOL get_install_root(LPWSTR install_dir)
72 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};
73 static const WCHAR install_root[] = {'I','n','s','t','a','l','l','R','o','o','t',0};
75 DWORD len;
76 HKEY key;
78 if (RegOpenKeyExW(HKEY_LOCAL_MACHINE, dotnet_key, 0, KEY_READ, &key))
79 return FALSE;
81 len = MAX_PATH * sizeof(WCHAR);
82 if (RegQueryValueExW(key, install_root, 0, NULL, (LPBYTE)install_dir, &len))
84 RegCloseKey(key);
85 return FALSE;
87 RegCloseKey(key);
89 return TRUE;
92 typedef struct mscorecf
94 IClassFactory IClassFactory_iface;
95 LONG ref;
97 fnCreateInstance pfnCreateInstance;
99 CLSID clsid;
100 } mscorecf;
102 static inline mscorecf *impl_from_IClassFactory( IClassFactory *iface )
104 return CONTAINING_RECORD(iface, mscorecf, IClassFactory_iface);
107 static HRESULT WINAPI mscorecf_QueryInterface(IClassFactory *iface, REFIID riid, LPVOID *ppobj )
109 TRACE("%s %p\n", debugstr_guid(riid), ppobj);
111 if (IsEqualGUID(riid, &IID_IUnknown) ||
112 IsEqualGUID(riid, &IID_IClassFactory))
114 IClassFactory_AddRef( iface );
115 *ppobj = iface;
116 return S_OK;
119 ERR("interface %s not implemented\n", debugstr_guid(riid));
120 return E_NOINTERFACE;
123 static ULONG WINAPI mscorecf_AddRef(IClassFactory *iface )
125 mscorecf *This = impl_from_IClassFactory(iface);
126 ULONG ref = InterlockedIncrement(&This->ref);
128 TRACE("%p ref=%u\n", This, ref);
130 return ref;
133 static ULONG WINAPI mscorecf_Release(IClassFactory *iface )
135 mscorecf *This = impl_from_IClassFactory(iface);
136 ULONG ref = InterlockedDecrement(&This->ref);
138 TRACE("%p ref=%u\n", This, ref);
140 if (ref == 0)
142 HeapFree(GetProcessHeap(), 0, This);
145 return ref;
148 static HRESULT WINAPI mscorecf_CreateInstance(IClassFactory *iface,LPUNKNOWN pOuter,
149 REFIID riid, LPVOID *ppobj )
151 mscorecf *This = impl_from_IClassFactory( iface );
152 HRESULT hr;
153 IUnknown *punk;
155 TRACE("%p %s %p\n", pOuter, debugstr_guid(riid), ppobj );
157 *ppobj = NULL;
159 if (pOuter)
160 return CLASS_E_NOAGGREGATION;
162 hr = This->pfnCreateInstance( &This->clsid, (LPVOID*) &punk );
163 if (SUCCEEDED(hr))
165 hr = IUnknown_QueryInterface( punk, riid, ppobj );
167 IUnknown_Release( punk );
169 else
171 WARN("Cannot create an instance object. 0x%08x\n", hr);
173 return hr;
176 static HRESULT WINAPI mscorecf_LockServer(IClassFactory *iface, BOOL dolock)
178 FIXME("(%p)->(%d),stub!\n",iface,dolock);
179 return S_OK;
182 static const struct IClassFactoryVtbl mscorecf_vtbl =
184 mscorecf_QueryInterface,
185 mscorecf_AddRef,
186 mscorecf_Release,
187 mscorecf_CreateInstance,
188 mscorecf_LockServer
191 HRESULT WINAPI CorBindToRuntimeHost(LPCWSTR pwszVersion, LPCWSTR pwszBuildFlavor,
192 LPCWSTR pwszHostConfigFile, VOID *pReserved,
193 DWORD startupFlags, REFCLSID rclsid,
194 REFIID riid, LPVOID *ppv)
196 HRESULT ret;
197 ICLRRuntimeInfo *info;
199 TRACE("(%s, %s, %s, %p, %d, %s, %s, %p)\n", debugstr_w(pwszVersion),
200 debugstr_w(pwszBuildFlavor), debugstr_w(pwszHostConfigFile), pReserved,
201 startupFlags, debugstr_guid(rclsid), debugstr_guid(riid), ppv);
203 *ppv = NULL;
205 ret = get_runtime_info(NULL, pwszVersion, pwszHostConfigFile, NULL, startupFlags, 0, TRUE, &info);
207 if (SUCCEEDED(ret))
209 ret = ICLRRuntimeInfo_GetInterface(info, rclsid, riid, ppv);
211 ICLRRuntimeInfo_Release(info);
214 return ret;
217 BOOL WINAPI DllMain(HINSTANCE hinstDLL, DWORD fdwReason, LPVOID lpvReserved)
219 TRACE("(%p, %d, %p)\n", hinstDLL, fdwReason, lpvReserved);
221 switch (fdwReason)
223 case DLL_PROCESS_ATTACH:
224 runtimehost_init();
225 DisableThreadLibraryCalls(hinstDLL);
226 break;
227 case DLL_PROCESS_DETACH:
228 expect_no_runtimes();
229 if (lpvReserved) break; /* process is terminating */
230 runtimehost_uninit();
231 break;
233 return TRUE;
236 __int32 WINAPI _CorExeMain2(PBYTE ptrMemory, DWORD cntMemory, LPWSTR imageName, LPWSTR loaderName, LPWSTR cmdLine)
238 TRACE("(%p, %u, %s, %s, %s)\n", ptrMemory, cntMemory, debugstr_w(imageName), debugstr_w(loaderName), debugstr_w(cmdLine));
239 FIXME("Directly running .NET applications not supported.\n");
240 return -1;
243 void WINAPI CorExitProcess(int exitCode)
245 TRACE("(%x)\n", exitCode);
246 CLRMetaHost_ExitProcess(0, exitCode);
249 VOID WINAPI _CorImageUnloading(PVOID imageBase)
251 TRACE("(%p): stub\n", imageBase);
254 HRESULT WINAPI _CorValidateImage(PVOID* imageBase, LPCWSTR imageName)
256 TRACE("(%p, %s): stub\n", imageBase, debugstr_w(imageName));
257 return E_FAIL;
260 HRESULT WINAPI GetCORSystemDirectory(LPWSTR pbuffer, DWORD cchBuffer, DWORD *dwLength)
262 ICLRRuntimeInfo *info;
263 HRESULT ret;
265 TRACE("(%p, %d, %p)!\n", pbuffer, cchBuffer, dwLength);
267 if (!dwLength || !pbuffer)
268 return E_POINTER;
270 ret = get_runtime_info(NULL, NULL, NULL, NULL, 0, RUNTIME_INFO_UPGRADE_VERSION, TRUE, &info);
272 if (SUCCEEDED(ret))
274 *dwLength = cchBuffer;
275 ret = ICLRRuntimeInfo_GetRuntimeDirectory(info, pbuffer, dwLength);
277 ICLRRuntimeInfo_Release(info);
280 return ret;
283 HRESULT WINAPI GetCORVersion(LPWSTR pbuffer, DWORD cchBuffer, DWORD *dwLength)
285 ICLRRuntimeInfo *info;
286 HRESULT ret;
288 TRACE("(%p, %d, %p)!\n", pbuffer, cchBuffer, dwLength);
290 if (!dwLength || !pbuffer)
291 return E_POINTER;
293 ret = get_runtime_info(NULL, NULL, NULL, NULL, 0, RUNTIME_INFO_UPGRADE_VERSION, TRUE, &info);
295 if (SUCCEEDED(ret))
297 *dwLength = cchBuffer;
298 ret = ICLRRuntimeInfo_GetVersionString(info, pbuffer, dwLength);
300 ICLRRuntimeInfo_Release(info);
303 return ret;
306 HRESULT WINAPI CorIsLatestSvc(int *unk1, int *unk2)
308 ERR_(winediag)("If this function is called, it is likely the result of a broken .NET installation\n");
310 if (!unk1 || !unk2)
311 return E_POINTER;
313 return S_OK;
316 HRESULT WINAPI CorGetSvc(void *unk)
318 ERR_(winediag)("If this function is called, it is likely the result of a broken .NET installation\n");
320 return E_NOTIMPL;
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, NULL, 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 lstrcatW(dll_filename, szVersion);
418 lstrcatW(dll_filename, slash);
421 lstrcatW(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, 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, NULL, 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, 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 BOOLEAN 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 BOOLEAN WINAPI StrongNameSignatureVerificationEx(LPCWSTR filename, BOOLEAN forceVerification, BOOLEAN *pVerified)
561 FIXME("(%s, %u, %p): stub\n", debugstr_w(filename), forceVerification, pVerified);
562 *pVerified = TRUE;
563 return TRUE;
566 HRESULT WINAPI CreateDebuggingInterfaceFromVersion(int nDebugVersion, LPCWSTR version, IUnknown **ppv)
568 static const WCHAR v2_0[] = {'v','2','.','0','.','5','0','7','2','7',0};
569 HRESULT hr = E_FAIL;
570 ICLRRuntimeInfo *runtimeinfo;
572 if(nDebugVersion < 1 || nDebugVersion > 4)
573 return E_INVALIDARG;
575 TRACE("(%d %s, %p): stub\n", nDebugVersion, debugstr_w(version), ppv);
577 if(!ppv)
578 return E_INVALIDARG;
580 *ppv = NULL;
582 if(wcscmp(version, v2_0) != 0)
584 FIXME("Currently .NET Version '%s' not support.\n", debugstr_w(version));
585 return E_INVALIDARG;
588 if(nDebugVersion != 3)
589 return E_INVALIDARG;
591 hr = CLRMetaHost_GetRuntime(0, version, &IID_ICLRRuntimeInfo, (void**)&runtimeinfo);
592 if(hr == S_OK)
594 hr = ICLRRuntimeInfo_GetInterface(runtimeinfo, &CLSID_CLRDebuggingLegacy, &IID_ICorDebug, (void**)ppv);
596 ICLRRuntimeInfo_Release(runtimeinfo);
599 if(!*ppv)
600 return E_FAIL;
602 return hr;
605 HRESULT WINAPI CLRCreateInstance(REFCLSID clsid, REFIID riid, LPVOID *ppInterface)
607 TRACE("(%s,%s,%p)\n", debugstr_guid(clsid), debugstr_guid(riid), ppInterface);
609 if (IsEqualGUID(clsid, &CLSID_CLRMetaHost))
610 return CLRMetaHost_CreateInstance(riid, ppInterface);
611 if (IsEqualGUID(clsid, &CLSID_CLRMetaHostPolicy))
612 return CLRMetaHostPolicy_CreateInstance(riid, ppInterface);
614 FIXME("not implemented for class %s\n", debugstr_guid(clsid));
616 return CLASS_E_CLASSNOTAVAILABLE;
619 HRESULT WINAPI CreateInterface(REFCLSID clsid, REFIID riid, LPVOID *ppInterface)
621 TRACE("(%s,%s,%p)\n", debugstr_guid(clsid), debugstr_guid(riid), ppInterface);
623 return CLRCreateInstance(clsid, riid, ppInterface);
626 HRESULT WINAPI DllGetClassObject(REFCLSID rclsid, REFIID riid, LPVOID* ppv)
628 mscorecf *This;
629 HRESULT hr;
631 TRACE("(%s, %s, %p): stub\n", debugstr_guid(rclsid), debugstr_guid(riid), ppv);
633 if(!ppv)
634 return E_INVALIDARG;
636 This = HeapAlloc(GetProcessHeap(), 0, sizeof(mscorecf));
638 This->IClassFactory_iface.lpVtbl = &mscorecf_vtbl;
639 This->pfnCreateInstance = create_monodata;
640 This->ref = 1;
641 This->clsid = *rclsid;
643 hr = IClassFactory_QueryInterface( &This->IClassFactory_iface, riid, ppv );
644 IClassFactory_Release(&This->IClassFactory_iface);
646 return hr;
649 static void parse_msi_version_string(const char *version, int *parts)
651 const char *minor_start, *build_start;
653 parts[0] = atoi(version);
655 parts[1] = parts[2] = 0;
657 minor_start = strchr(version, '.');
658 if (minor_start)
660 minor_start++;
661 parts[1] = atoi(minor_start);
663 build_start = strchr(minor_start, '.');
664 if (build_start)
665 parts[2] = atoi(build_start+1);
669 static int compare_versions(const char *a, const char *b)
671 int a_parts[3], b_parts[3], i;
673 parse_msi_version_string(a, a_parts);
674 parse_msi_version_string(b, b_parts);
676 for (i=0; i<3; i++)
677 if (a_parts[i] != b_parts[i])
678 return a_parts[i] - b_parts[i];
680 return 0;
683 static BOOL invoke_appwiz(void)
685 PROCESS_INFORMATION pi;
686 STARTUPINFOW si;
687 WCHAR app[MAX_PATH];
688 WCHAR *args;
689 LONG len;
690 BOOL ret;
692 static const WCHAR controlW[] = {'\\','c','o','n','t','r','o','l','.','e','x','e',0};
693 static const WCHAR argsW[] =
694 {' ','a','p','p','w','i','z','.','c','p','l',' ','i','n','s','t','a','l','l','_','m','o','n','o',0};
696 len = GetSystemDirectoryW(app, MAX_PATH - ARRAY_SIZE(controlW));
697 memcpy(app+len, controlW, sizeof(controlW));
699 args = HeapAlloc(GetProcessHeap(), 0, (len*sizeof(WCHAR) + sizeof(controlW) + sizeof(argsW)));
700 if(!args)
701 return FALSE;
703 memcpy(args, app, len*sizeof(WCHAR) + sizeof(controlW));
704 memcpy(args + len + ARRAY_SIZE(controlW) - 1, argsW, sizeof(argsW));
706 TRACE("starting %s\n", debugstr_w(args));
708 memset(&si, 0, sizeof(si));
709 si.cb = sizeof(si);
710 ret = CreateProcessW(app, args, NULL, NULL, FALSE, 0, NULL, NULL, &si, &pi);
711 HeapFree(GetProcessHeap(), 0, args);
712 if (ret) {
713 CloseHandle(pi.hThread);
714 WaitForSingleObject(pi.hProcess, INFINITE);
715 CloseHandle(pi.hProcess);
718 return ret;
721 static BOOL get_support_msi(LPCWSTR mono_path, LPWSTR msi_path)
723 static const WCHAR support_msi_relative[] = {'\\','s','u','p','p','o','r','t','\\','w','i','n','e','m','o','n','o','-','s','u','p','p','o','r','t','.','m','s','i',0};
724 UINT (WINAPI *pMsiOpenPackageW)(LPCWSTR,ULONG*);
725 UINT (WINAPI *pMsiGetProductPropertyA)(ULONG,LPCSTR,LPSTR,LPDWORD);
726 UINT (WINAPI *pMsiCloseHandle)(ULONG);
727 HMODULE hmsi = NULL;
728 char versionstringbuf[15];
729 UINT res;
730 DWORD buffer_size;
731 ULONG msiproduct;
732 BOOL ret=FALSE;
734 hmsi = GetModuleHandleA("msi");
736 lstrcpyW(msi_path, mono_path);
737 lstrcatW(msi_path, support_msi_relative);
739 pMsiOpenPackageW = (void*)GetProcAddress(hmsi, "MsiOpenPackageW");
741 res = pMsiOpenPackageW(msi_path, &msiproduct);
743 if (res == ERROR_SUCCESS)
745 buffer_size = sizeof(versionstringbuf);
747 pMsiGetProductPropertyA = (void*)GetProcAddress(hmsi, "MsiGetProductPropertyA");
749 res = pMsiGetProductPropertyA(msiproduct, "ProductVersion", versionstringbuf, &buffer_size);
751 pMsiCloseHandle = (void*)GetProcAddress(hmsi, "MsiCloseHandle");
753 pMsiCloseHandle(msiproduct);
756 if (res == ERROR_SUCCESS) {
757 TRACE("found support msi version %s at %s\n", versionstringbuf, debugstr_w(msi_path));
759 if (compare_versions(WINE_MONO_VERSION, versionstringbuf) <= 0)
761 ret = TRUE;
765 return ret;
768 static BOOL install_wine_mono(void)
770 BOOL is_wow64 = FALSE;
771 HMODULE hmsi = NULL;
772 HRESULT initresult = E_FAIL;
773 UINT (WINAPI *pMsiEnumRelatedProductsA)(LPCSTR,DWORD,DWORD,LPSTR);
774 UINT (WINAPI *pMsiGetProductInfoA)(LPCSTR,LPCSTR,LPSTR,DWORD*);
775 UINT (WINAPI *pMsiInstallProductW)(LPCWSTR,LPCWSTR);
776 char versionstringbuf[15];
777 char productcodebuf[39];
778 UINT res;
779 DWORD buffer_size;
780 BOOL ret;
781 WCHAR mono_path[MAX_PATH];
782 WCHAR support_msi_path[MAX_PATH];
784 static const char* mono_upgrade_code = "{DE624609-C6B5-486A-9274-EF0B854F6BC5}";
786 IsWow64Process(GetCurrentProcess(), &is_wow64);
788 if (is_wow64)
790 TRACE("not installing mono in wow64 process\n");
791 return TRUE;
794 TRACE("searching for mono runtime\n");
796 if (!get_mono_path(mono_path, FALSE))
798 TRACE("mono runtime not found\n");
799 return invoke_appwiz();
802 TRACE("mono runtime is at %s\n", debugstr_w(mono_path));
804 hmsi = LoadLibraryA("msi");
806 if (!hmsi)
808 ERR("couldn't load msi.dll\n");
809 return FALSE;
812 pMsiEnumRelatedProductsA = (void*)GetProcAddress(hmsi, "MsiEnumRelatedProductsA");
814 res = pMsiEnumRelatedProductsA(mono_upgrade_code, 0, 0, productcodebuf);
816 if (res == ERROR_SUCCESS)
818 pMsiGetProductInfoA = (void*)GetProcAddress(hmsi, "MsiGetProductInfoA");
820 buffer_size = sizeof(versionstringbuf);
822 res = pMsiGetProductInfoA(productcodebuf, "VersionString", versionstringbuf, &buffer_size);
824 else if (res != ERROR_NO_MORE_ITEMS)
826 ERR("MsiEnumRelatedProducts failed, err=%u\n", res);
829 if (res == ERROR_SUCCESS)
831 TRACE("found installed support package %s\n", versionstringbuf);
833 if (compare_versions(WINE_MONO_VERSION, versionstringbuf) <= 0)
835 TRACE("support package is at least %s, quitting\n", WINE_MONO_VERSION);
836 ret = TRUE;
837 goto end;
841 initresult = CoInitialize(NULL);
843 ret = get_support_msi(mono_path, support_msi_path);
844 if (!ret)
846 /* Try looking outside c:\windows\mono */
847 ret = (get_mono_path(mono_path, TRUE) &&
848 get_support_msi(mono_path, support_msi_path));
851 if (ret)
853 TRACE("installing support msi\n");
855 pMsiInstallProductW = (void*)GetProcAddress(hmsi, "MsiInstallProductW");
857 res = pMsiInstallProductW(support_msi_path, NULL);
859 if (res == ERROR_SUCCESS)
861 ret = TRUE;
862 goto end;
864 else
865 ERR("MsiInstallProduct failed, err=%i\n", res);
868 ret = invoke_appwiz();
870 end:
871 if (hmsi)
872 FreeLibrary(hmsi);
873 if (SUCCEEDED(initresult))
874 CoUninitialize();
875 return ret;
878 HRESULT WINAPI DllRegisterServer(void)
880 install_wine_mono();
882 return __wine_register_resources();
885 HRESULT WINAPI DllUnregisterServer(void)
887 return __wine_unregister_resources();
890 void WINAPI CoEEShutDownCOM(void)
892 FIXME("stub.\n");
895 INT WINAPI ND_RU1( const void *ptr, INT offset )
897 return *((const BYTE *)ptr + offset);
900 INT WINAPI ND_RI2( const void *ptr, INT offset )
902 return *(const SHORT *)((const BYTE *)ptr + offset);
905 INT WINAPI ND_RI4( const void *ptr, INT offset )
907 return *(const INT *)((const BYTE *)ptr + offset);
910 INT64 WINAPI ND_RI8( const void *ptr, INT offset )
912 return *(const INT64 *)((const BYTE *)ptr + offset);
915 void WINAPI ND_WU1( void *ptr, INT offset, BYTE val )
917 *((BYTE *)ptr + offset) = val;
920 void WINAPI ND_WI2( void *ptr, INT offset, SHORT val )
922 *(SHORT *)((BYTE *)ptr + offset) = val;
925 void WINAPI ND_WI4( void *ptr, INT offset, INT val )
927 *(INT *)((BYTE *)ptr + offset) = val;
930 void WINAPI ND_WI8( void *ptr, INT offset, INT64 val )
932 *(INT64 *)((BYTE *)ptr + offset) = val;
935 void WINAPI ND_CopyObjDst( const void *src, void *dst, INT offset, INT size )
937 memcpy( (BYTE *)dst + offset, src, size );
940 void WINAPI ND_CopyObjSrc( const void *src, INT offset, void *dst, INT size )
942 memcpy( dst, (const BYTE *)src + offset, size );