mshtml/htmltextcont: Initialize value (Coverity).
[wine] / dlls / mscoree / mscoree_main.c
1 /*
2  * Implementation of mscoree.dll
3  * Microsoft Component Object Runtime Execution Engine
4  *
5  * Copyright 2006 Paul Chitescu
6  *
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.
11  *
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.
16  *
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
20  */
21
22 #include <stdarg.h>
23
24 #include "windef.h"
25 #include "winbase.h"
26 #include "winuser.h"
27 #include "winreg.h"
28 #include "ole2.h"
29
30 #include "cor.h"
31 #include "mscoree.h"
32
33 #include "wine/debug.h"
34
35 WINE_DEFAULT_DEBUG_CHANNEL( mscoree );
36
37 HRESULT WINAPI CorBindToRuntimeHost(LPCWSTR pwszVersion, LPCWSTR pwszBuildFlavor,
38                                     LPCWSTR pwszHostConfigFile, VOID *pReserved,
39                                     DWORD startupFlags, REFCLSID rclsid,
40                                     REFIID riid, LPVOID *ppv)
41 {
42     FIXME("(%s, %s, %s, %p, %d, %p, %p, %p): stub!\n", debugstr_w(pwszVersion),
43           debugstr_w(pwszBuildFlavor), debugstr_w(pwszHostConfigFile), pReserved,
44           startupFlags, rclsid, riid, ppv);
45
46     return E_FAIL;
47 }
48
49 BOOL WINAPI DllMain(HINSTANCE hinstDLL, DWORD fdwReason, LPVOID lpvReserved)
50 {
51     TRACE("(%p, %d, %p)\n", hinstDLL, fdwReason, lpvReserved);
52
53     switch (fdwReason)
54     {
55     case DLL_WINE_PREATTACH:
56         return FALSE;  /* prefer native version */
57     case DLL_PROCESS_ATTACH:
58         DisableThreadLibraryCalls(hinstDLL);
59         break;
60     case DLL_PROCESS_DETACH:
61         break;
62     }
63     return TRUE;
64 }
65
66 BOOL WINAPI _CorDllMain(HINSTANCE hinstDLL, DWORD fdwReason, LPVOID lpvReserved)
67 {
68     FIXME("(%p, %d, %p): stub\n", hinstDLL, fdwReason, lpvReserved);
69
70     switch (fdwReason)
71     {
72     case DLL_PROCESS_ATTACH:
73         DisableThreadLibraryCalls(hinstDLL);
74         break;
75     case DLL_PROCESS_DETACH:
76         break;
77     }
78     return TRUE;
79 }
80
81 static LPWSTR get_mono_exe(void)
82 {
83     static const WCHAR mono_exe[] = {'b','i','n','\\','m','o','n','o','.','e','x','e',' ',0};
84     static const WCHAR mono_key[] = {'S','o','f','t','w','a','r','e','\\','N','o','v','e','l','l','\\','M','o','n','o',0};
85     static const WCHAR defaul_clr[] = {'D','e','f','a','u','l','t','C','L','R',0};
86     static const WCHAR install_root[] = {'S','d','k','I','n','s','t','a','l','l','R','o','o','t',0};
87     static const WCHAR slash[] = {'\\',0};
88
89     WCHAR version[64], version_key[MAX_PATH], root[MAX_PATH], *ret;
90     DWORD len, size;
91     HKEY key;
92
93     if (RegOpenKeyExW(HKEY_LOCAL_MACHINE, mono_key, 0, KEY_READ, &key))
94         return NULL;
95
96     len = sizeof(version);
97     if (RegQueryValueExW(key, defaul_clr, 0, NULL, (LPBYTE)version, &len))
98     {
99         RegCloseKey(key);
100         return NULL;
101     }
102     RegCloseKey(key);
103
104     lstrcpyW(version_key, mono_key);
105     lstrcatW(version_key, slash);
106     lstrcatW(version_key, version);
107
108     if (RegOpenKeyExW(HKEY_LOCAL_MACHINE, version_key, 0, KEY_READ, &key))
109         return NULL;
110
111     len = sizeof(root);
112     if (RegQueryValueExW(key, install_root, 0, NULL, (LPBYTE)root, &len))
113     {
114         RegCloseKey(key);
115         return NULL;
116     }
117     RegCloseKey(key);
118
119     size = len + sizeof(slash) + sizeof(mono_exe);
120     if (!(ret = HeapAlloc(GetProcessHeap(), 0, size))) return NULL;
121
122     lstrcpyW(ret, root);
123     lstrcatW(ret, slash);
124     lstrcatW(ret, mono_exe);
125
126     return ret;
127 }
128
129 __int32 WINAPI _CorExeMain(void)
130 {
131     STARTUPINFOW si;
132     PROCESS_INFORMATION pi;
133     WCHAR *mono_exe, *cmd_line;
134     DWORD size, exit_code;
135
136     if (!(mono_exe = get_mono_exe()))
137     {
138         MESSAGE("install the Windows version of Mono to run .NET executables\n");
139         return -1;
140     }
141
142     size = (lstrlenW(mono_exe) + lstrlenW(GetCommandLineW()) + 1) * sizeof(WCHAR);
143     if (!(cmd_line = HeapAlloc(GetProcessHeap(), 0, size)))
144     {
145         HeapFree(GetProcessHeap(), 0, mono_exe);
146         return -1;
147     }
148
149     lstrcpyW(cmd_line, mono_exe);
150     HeapFree(GetProcessHeap(), 0, mono_exe);
151     lstrcatW(cmd_line, GetCommandLineW());
152
153     TRACE("new command line: %s\n", debugstr_w(cmd_line));
154
155     memset(&si, 0, sizeof(si));
156     si.cb = sizeof(si);
157     if (!CreateProcessW(NULL, cmd_line, NULL, NULL, FALSE, 0, NULL, NULL, &si, &pi))
158     {
159         HeapFree(GetProcessHeap(), 0, cmd_line);
160         return -1;
161     }
162     HeapFree(GetProcessHeap(), 0, cmd_line);
163
164     /* wait for the process to exit */
165     WaitForSingleObject(pi.hProcess, INFINITE);
166     GetExitCodeProcess(pi.hProcess, &exit_code);
167
168     CloseHandle(pi.hThread);
169     CloseHandle(pi.hProcess);
170
171     return (int)exit_code;
172 }
173
174 __int32 WINAPI _CorExeMain2(PBYTE ptrMemory, DWORD cntMemory, LPWSTR imageName, LPWSTR loaderName, LPWSTR cmdLine)
175 {
176     TRACE("(%p, %u, %s, %s, %s)\n", ptrMemory, cntMemory, debugstr_w(imageName), debugstr_w(loaderName), debugstr_w(cmdLine));
177     FIXME("Directly running .NET applications not supported.\n");
178     return -1;
179 }
180
181 void WINAPI CorExitProcess(int exitCode)
182 {
183     FIXME("(%x) stub\n", exitCode);
184     ExitProcess(exitCode);
185 }
186
187 VOID WINAPI _CorImageUnloading(PVOID imageBase)
188 {
189     TRACE("(%p): stub\n", imageBase);
190 }
191
192 HRESULT WINAPI _CorValidateImage(PVOID* imageBase, LPCWSTR imageName)
193 {
194     TRACE("(%p, %s): stub\n", imageBase, debugstr_w(imageName));
195     return E_FAIL;
196 }
197
198 HRESULT WINAPI GetCORSystemDirectory(LPWSTR pbuffer, DWORD cchBuffer, DWORD *dwLength)
199 {
200     FIXME("(%p, %d, %p): stub!\n", pbuffer, cchBuffer, dwLength);
201
202     if (!dwLength)
203         return E_POINTER;
204
205     *dwLength = 0;
206
207     return S_OK;
208 }
209
210 HRESULT WINAPI GetCORVersion(LPWSTR pbuffer, DWORD cchBuffer, DWORD *dwLength)
211 {
212     static const WCHAR version[] = {'v','1','.','1','.','4','3','2','2',0};
213
214     FIXME("(%p, %d, %p): semi-stub!\n", pbuffer, cchBuffer, dwLength);
215
216     if (!dwLength)
217         return E_POINTER;
218
219     *dwLength = lstrlenW(version);
220
221     if (cchBuffer < *dwLength)
222         return ERROR_INSUFFICIENT_BUFFER;
223
224     if (pbuffer)
225         lstrcpyW(pbuffer, version);
226
227     return S_OK;
228 }
229
230 HRESULT WINAPI GetRequestedRuntimeInfo(LPCWSTR pExe, LPCWSTR pwszVersion, LPCWSTR pConfigurationFile,
231     DWORD startupFlags, DWORD runtimeInfoFlags, LPWSTR pDirectory, DWORD dwDirectory, DWORD *dwDirectoryLength,
232     LPWSTR pVersion, DWORD cchBuffer, DWORD *dwlength)
233 {
234     FIXME("(%s, %s, %s, 0x%08x, 0x%08x, %p, 0x%08x, %p, %p, 0x%08x, %p) stub\n", debugstr_w(pExe),
235           debugstr_w(pwszVersion), debugstr_w(pConfigurationFile), startupFlags, runtimeInfoFlags, pDirectory,
236           dwDirectory, dwDirectoryLength, pVersion, cchBuffer, dwlength);
237     return GetCORVersion(pVersion, cchBuffer, dwlength);
238 }
239
240 HRESULT WINAPI LoadLibraryShim( LPCWSTR szDllName, LPCWSTR szVersion, LPVOID pvReserved, HMODULE * phModDll)
241 {
242     FIXME("(%p %s, %p, %p, %p): semi-stub\n", szDllName, debugstr_w(szDllName), szVersion, pvReserved, phModDll);
243
244     if (phModDll) *phModDll = LoadLibraryW(szDllName);
245     return S_OK;
246 }
247
248 HRESULT WINAPI CoInitializeCor(DWORD fFlags)
249 {
250     FIXME("(0x%08x): stub\n", fFlags);
251     return S_OK;
252 }
253
254 HRESULT WINAPI GetAssemblyMDImport(LPCWSTR szFileName, REFIID riid, IUnknown **ppIUnk)
255 {
256     FIXME("(%p %s, %p, %p): stub\n", szFileName, debugstr_w(szFileName), riid, *ppIUnk);
257     return ERROR_CALL_NOT_IMPLEMENTED;
258 }