msi: Add more tests for MsiSourceListGetInfo.
[wine.git] / dlls / mscoree / mscoree_main.c
blobb60d4d31ac8b85030774904bc3d6498150242770
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 #include "windef.h"
25 #include "winbase.h"
26 #include "winuser.h"
27 #include "winreg.h"
28 #include "ole2.h"
30 #include "cor.h"
31 #include "mscoree.h"
33 #include "wine/debug.h"
35 WINE_DEFAULT_DEBUG_CHANNEL( mscoree );
37 static LPWSTR get_mono_exe(void)
39 static const WCHAR mono_exe[] = {'b','i','n','\\','m','o','n','o','.','e','x','e',' ',0};
40 static const WCHAR mono_key[] = {'S','o','f','t','w','a','r','e','\\','N','o','v','e','l','l','\\','M','o','n','o',0};
41 static const WCHAR defaul_clr[] = {'D','e','f','a','u','l','t','C','L','R',0};
42 static const WCHAR install_root[] = {'S','d','k','I','n','s','t','a','l','l','R','o','o','t',0};
43 static const WCHAR slash[] = {'\\',0};
45 WCHAR version[64], version_key[MAX_PATH], root[MAX_PATH], *ret;
46 DWORD len, size;
47 HKEY key;
49 if (RegOpenKeyExW(HKEY_LOCAL_MACHINE, mono_key, 0, KEY_READ, &key))
50 return NULL;
52 len = sizeof(version);
53 if (RegQueryValueExW(key, defaul_clr, 0, NULL, (LPBYTE)version, &len))
55 RegCloseKey(key);
56 return NULL;
58 RegCloseKey(key);
60 lstrcpyW(version_key, mono_key);
61 lstrcatW(version_key, slash);
62 lstrcatW(version_key, version);
64 if (RegOpenKeyExW(HKEY_LOCAL_MACHINE, version_key, 0, KEY_READ, &key))
65 return NULL;
67 len = sizeof(root);
68 if (RegQueryValueExW(key, install_root, 0, NULL, (LPBYTE)root, &len))
70 RegCloseKey(key);
71 return NULL;
73 RegCloseKey(key);
75 size = len + sizeof(slash) + sizeof(mono_exe);
76 if (!(ret = HeapAlloc(GetProcessHeap(), 0, size))) return NULL;
78 lstrcpyW(ret, root);
79 lstrcatW(ret, slash);
80 lstrcatW(ret, mono_exe);
82 return ret;
85 HRESULT WINAPI CorBindToRuntimeHost(LPCWSTR pwszVersion, LPCWSTR pwszBuildFlavor,
86 LPCWSTR pwszHostConfigFile, VOID *pReserved,
87 DWORD startupFlags, REFCLSID rclsid,
88 REFIID riid, LPVOID *ppv)
90 WCHAR *mono_exe;
92 FIXME("(%s, %s, %s, %p, %d, %p, %p, %p): semi-stub!\n", debugstr_w(pwszVersion),
93 debugstr_w(pwszBuildFlavor), debugstr_w(pwszHostConfigFile), pReserved,
94 startupFlags, rclsid, riid, ppv);
96 if (!(mono_exe = get_mono_exe()))
98 MESSAGE("wine: Install the Windows version of Mono to run .NET executables\n");
99 return E_FAIL;
102 HeapFree(GetProcessHeap(), 0, mono_exe);
104 return S_OK;
107 BOOL WINAPI DllMain(HINSTANCE hinstDLL, DWORD fdwReason, LPVOID lpvReserved)
109 TRACE("(%p, %d, %p)\n", hinstDLL, fdwReason, lpvReserved);
111 switch (fdwReason)
113 case DLL_WINE_PREATTACH:
114 return FALSE; /* prefer native version */
115 case DLL_PROCESS_ATTACH:
116 DisableThreadLibraryCalls(hinstDLL);
117 break;
118 case DLL_PROCESS_DETACH:
119 break;
121 return TRUE;
124 BOOL WINAPI _CorDllMain(HINSTANCE hinstDLL, DWORD fdwReason, LPVOID lpvReserved)
126 FIXME("(%p, %d, %p): stub\n", hinstDLL, fdwReason, lpvReserved);
128 switch (fdwReason)
130 case DLL_PROCESS_ATTACH:
131 DisableThreadLibraryCalls(hinstDLL);
132 break;
133 case DLL_PROCESS_DETACH:
134 break;
136 return TRUE;
139 __int32 WINAPI _CorExeMain(void)
141 STARTUPINFOW si;
142 PROCESS_INFORMATION pi;
143 WCHAR *mono_exe, *cmd_line;
144 DWORD size, exit_code;
146 if (!(mono_exe = get_mono_exe()))
148 MESSAGE("install the Windows version of Mono to run .NET executables\n");
149 return -1;
152 size = (lstrlenW(mono_exe) + lstrlenW(GetCommandLineW()) + 1) * sizeof(WCHAR);
153 if (!(cmd_line = HeapAlloc(GetProcessHeap(), 0, size)))
155 HeapFree(GetProcessHeap(), 0, mono_exe);
156 return -1;
159 lstrcpyW(cmd_line, mono_exe);
160 HeapFree(GetProcessHeap(), 0, mono_exe);
161 lstrcatW(cmd_line, GetCommandLineW());
163 TRACE("new command line: %s\n", debugstr_w(cmd_line));
165 memset(&si, 0, sizeof(si));
166 si.cb = sizeof(si);
167 if (!CreateProcessW(NULL, cmd_line, NULL, NULL, FALSE, 0, NULL, NULL, &si, &pi))
169 HeapFree(GetProcessHeap(), 0, cmd_line);
170 return -1;
172 HeapFree(GetProcessHeap(), 0, cmd_line);
174 /* wait for the process to exit */
175 WaitForSingleObject(pi.hProcess, INFINITE);
176 GetExitCodeProcess(pi.hProcess, &exit_code);
178 CloseHandle(pi.hThread);
179 CloseHandle(pi.hProcess);
181 return (int)exit_code;
184 __int32 WINAPI _CorExeMain2(PBYTE ptrMemory, DWORD cntMemory, LPWSTR imageName, LPWSTR loaderName, LPWSTR cmdLine)
186 TRACE("(%p, %u, %s, %s, %s)\n", ptrMemory, cntMemory, debugstr_w(imageName), debugstr_w(loaderName), debugstr_w(cmdLine));
187 FIXME("Directly running .NET applications not supported.\n");
188 return -1;
191 void WINAPI CorExitProcess(int exitCode)
193 FIXME("(%x) stub\n", exitCode);
194 ExitProcess(exitCode);
197 VOID WINAPI _CorImageUnloading(PVOID imageBase)
199 TRACE("(%p): stub\n", imageBase);
202 HRESULT WINAPI _CorValidateImage(PVOID* imageBase, LPCWSTR imageName)
204 TRACE("(%p, %s): stub\n", imageBase, debugstr_w(imageName));
205 return E_FAIL;
208 HRESULT WINAPI GetCORSystemDirectory(LPWSTR pbuffer, DWORD cchBuffer, DWORD *dwLength)
210 FIXME("(%p, %d, %p): stub!\n", pbuffer, cchBuffer, dwLength);
212 if (!dwLength)
213 return E_POINTER;
215 *dwLength = 0;
217 return S_OK;
220 HRESULT WINAPI GetCORVersion(LPWSTR pbuffer, DWORD cchBuffer, DWORD *dwLength)
222 static const WCHAR version[] = {'v','1','.','1','.','4','3','2','2',0};
224 FIXME("(%p, %d, %p): semi-stub!\n", pbuffer, cchBuffer, dwLength);
226 if (!dwLength)
227 return E_POINTER;
229 *dwLength = lstrlenW(version);
231 if (cchBuffer < *dwLength)
232 return ERROR_INSUFFICIENT_BUFFER;
234 if (pbuffer)
235 lstrcpyW(pbuffer, version);
237 return S_OK;
240 HRESULT WINAPI GetRequestedRuntimeInfo(LPCWSTR pExe, LPCWSTR pwszVersion, LPCWSTR pConfigurationFile,
241 DWORD startupFlags, DWORD runtimeInfoFlags, LPWSTR pDirectory, DWORD dwDirectory, DWORD *dwDirectoryLength,
242 LPWSTR pVersion, DWORD cchBuffer, DWORD *dwlength)
244 FIXME("(%s, %s, %s, 0x%08x, 0x%08x, %p, 0x%08x, %p, %p, 0x%08x, %p) stub\n", debugstr_w(pExe),
245 debugstr_w(pwszVersion), debugstr_w(pConfigurationFile), startupFlags, runtimeInfoFlags, pDirectory,
246 dwDirectory, dwDirectoryLength, pVersion, cchBuffer, dwlength);
247 return GetCORVersion(pVersion, cchBuffer, dwlength);
250 HRESULT WINAPI LoadLibraryShim( LPCWSTR szDllName, LPCWSTR szVersion, LPVOID pvReserved, HMODULE * phModDll)
252 FIXME("(%p %s, %p, %p, %p): semi-stub\n", szDllName, debugstr_w(szDllName), szVersion, pvReserved, phModDll);
254 if (phModDll) *phModDll = LoadLibraryW(szDllName);
255 return S_OK;
258 HRESULT WINAPI CoInitializeCor(DWORD fFlags)
260 FIXME("(0x%08x): stub\n", fFlags);
261 return S_OK;
264 HRESULT WINAPI GetAssemblyMDImport(LPCWSTR szFileName, REFIID riid, IUnknown **ppIUnk)
266 FIXME("(%p %s, %p, %p): stub\n", szFileName, debugstr_w(szFileName), riid, *ppIUnk);
267 return ERROR_CALL_NOT_IMPLEMENTED;
270 HRESULT WINAPI GetVersionFromProcess(HANDLE hProcess, LPWSTR pVersion, DWORD cchBuffer, DWORD *dwLength)
272 FIXME("(%p, %p, %d, %p): stub\n", hProcess, pVersion, cchBuffer, dwLength);
273 return E_NOTIMPL;
276 HRESULT WINAPI LoadStringRCEx(LCID culture, UINT resId, LPWSTR pBuffer, int iBufLen, int bQuiet, int* pBufLen)
278 HRESULT res = S_OK;
279 if ((iBufLen <= 0) || !pBuffer)
280 return E_INVALIDARG;
281 pBuffer[0] = 0;
282 if (resId) {
283 FIXME("(%d, %x, %p, %d, %d, %p): semi-stub\n", culture, resId, pBuffer, iBufLen, bQuiet, pBufLen);
284 res = E_NOTIMPL;
286 else
287 res = E_FAIL;
288 if (pBufLen)
289 *pBufLen = lstrlenW(pBuffer);
290 return res;
293 HRESULT WINAPI LoadStringRC(UINT resId, LPWSTR pBuffer, int iBufLen, int bQuiet)
295 return LoadStringRCEx(-1, resId, pBuffer, iBufLen, bQuiet, NULL);
298 HRESULT WINAPI DllGetClassObject(REFCLSID rclsid, REFIID riid, LPVOID* ppv)
300 FIXME("(%p, %p, %p): stub\n", rclsid, riid, ppv);
301 if(!ppv)
302 return E_INVALIDARG;
304 return E_NOTIMPL;
307 HRESULT WINAPI DllCanUnloadNow(VOID)
309 FIXME("stub\n");
310 return S_OK;