mscoree: Add stubs for DllCanUnloadNow and DllGetClassObject.
[wine.git] / dlls / mscoree / mscoree_main.c
blobecefc2704ca14c4d4136b318df3e666e6562debd
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 return S_OK;
105 BOOL WINAPI DllMain(HINSTANCE hinstDLL, DWORD fdwReason, LPVOID lpvReserved)
107 TRACE("(%p, %d, %p)\n", hinstDLL, fdwReason, lpvReserved);
109 switch (fdwReason)
111 case DLL_WINE_PREATTACH:
112 return FALSE; /* prefer native version */
113 case DLL_PROCESS_ATTACH:
114 DisableThreadLibraryCalls(hinstDLL);
115 break;
116 case DLL_PROCESS_DETACH:
117 break;
119 return TRUE;
122 BOOL WINAPI _CorDllMain(HINSTANCE hinstDLL, DWORD fdwReason, LPVOID lpvReserved)
124 FIXME("(%p, %d, %p): stub\n", hinstDLL, fdwReason, lpvReserved);
126 switch (fdwReason)
128 case DLL_PROCESS_ATTACH:
129 DisableThreadLibraryCalls(hinstDLL);
130 break;
131 case DLL_PROCESS_DETACH:
132 break;
134 return TRUE;
137 __int32 WINAPI _CorExeMain(void)
139 STARTUPINFOW si;
140 PROCESS_INFORMATION pi;
141 WCHAR *mono_exe, *cmd_line;
142 DWORD size, exit_code;
144 if (!(mono_exe = get_mono_exe()))
146 MESSAGE("install the Windows version of Mono to run .NET executables\n");
147 return -1;
150 size = (lstrlenW(mono_exe) + lstrlenW(GetCommandLineW()) + 1) * sizeof(WCHAR);
151 if (!(cmd_line = HeapAlloc(GetProcessHeap(), 0, size)))
153 HeapFree(GetProcessHeap(), 0, mono_exe);
154 return -1;
157 lstrcpyW(cmd_line, mono_exe);
158 HeapFree(GetProcessHeap(), 0, mono_exe);
159 lstrcatW(cmd_line, GetCommandLineW());
161 TRACE("new command line: %s\n", debugstr_w(cmd_line));
163 memset(&si, 0, sizeof(si));
164 si.cb = sizeof(si);
165 if (!CreateProcessW(NULL, cmd_line, NULL, NULL, FALSE, 0, NULL, NULL, &si, &pi))
167 HeapFree(GetProcessHeap(), 0, cmd_line);
168 return -1;
170 HeapFree(GetProcessHeap(), 0, cmd_line);
172 /* wait for the process to exit */
173 WaitForSingleObject(pi.hProcess, INFINITE);
174 GetExitCodeProcess(pi.hProcess, &exit_code);
176 CloseHandle(pi.hThread);
177 CloseHandle(pi.hProcess);
179 return (int)exit_code;
182 __int32 WINAPI _CorExeMain2(PBYTE ptrMemory, DWORD cntMemory, LPWSTR imageName, LPWSTR loaderName, LPWSTR cmdLine)
184 TRACE("(%p, %u, %s, %s, %s)\n", ptrMemory, cntMemory, debugstr_w(imageName), debugstr_w(loaderName), debugstr_w(cmdLine));
185 FIXME("Directly running .NET applications not supported.\n");
186 return -1;
189 void WINAPI CorExitProcess(int exitCode)
191 FIXME("(%x) stub\n", exitCode);
192 ExitProcess(exitCode);
195 VOID WINAPI _CorImageUnloading(PVOID imageBase)
197 TRACE("(%p): stub\n", imageBase);
200 HRESULT WINAPI _CorValidateImage(PVOID* imageBase, LPCWSTR imageName)
202 TRACE("(%p, %s): stub\n", imageBase, debugstr_w(imageName));
203 return E_FAIL;
206 HRESULT WINAPI GetCORSystemDirectory(LPWSTR pbuffer, DWORD cchBuffer, DWORD *dwLength)
208 FIXME("(%p, %d, %p): stub!\n", pbuffer, cchBuffer, dwLength);
210 if (!dwLength)
211 return E_POINTER;
213 *dwLength = 0;
215 return S_OK;
218 HRESULT WINAPI GetCORVersion(LPWSTR pbuffer, DWORD cchBuffer, DWORD *dwLength)
220 static const WCHAR version[] = {'v','1','.','1','.','4','3','2','2',0};
222 FIXME("(%p, %d, %p): semi-stub!\n", pbuffer, cchBuffer, dwLength);
224 if (!dwLength)
225 return E_POINTER;
227 *dwLength = lstrlenW(version);
229 if (cchBuffer < *dwLength)
230 return ERROR_INSUFFICIENT_BUFFER;
232 if (pbuffer)
233 lstrcpyW(pbuffer, version);
235 return S_OK;
238 HRESULT WINAPI GetRequestedRuntimeInfo(LPCWSTR pExe, LPCWSTR pwszVersion, LPCWSTR pConfigurationFile,
239 DWORD startupFlags, DWORD runtimeInfoFlags, LPWSTR pDirectory, DWORD dwDirectory, DWORD *dwDirectoryLength,
240 LPWSTR pVersion, DWORD cchBuffer, DWORD *dwlength)
242 FIXME("(%s, %s, %s, 0x%08x, 0x%08x, %p, 0x%08x, %p, %p, 0x%08x, %p) stub\n", debugstr_w(pExe),
243 debugstr_w(pwszVersion), debugstr_w(pConfigurationFile), startupFlags, runtimeInfoFlags, pDirectory,
244 dwDirectory, dwDirectoryLength, pVersion, cchBuffer, dwlength);
245 return GetCORVersion(pVersion, cchBuffer, dwlength);
248 HRESULT WINAPI LoadLibraryShim( LPCWSTR szDllName, LPCWSTR szVersion, LPVOID pvReserved, HMODULE * phModDll)
250 FIXME("(%p %s, %p, %p, %p): semi-stub\n", szDllName, debugstr_w(szDllName), szVersion, pvReserved, phModDll);
252 if (phModDll) *phModDll = LoadLibraryW(szDllName);
253 return S_OK;
256 HRESULT WINAPI CoInitializeCor(DWORD fFlags)
258 FIXME("(0x%08x): stub\n", fFlags);
259 return S_OK;
262 HRESULT WINAPI GetAssemblyMDImport(LPCWSTR szFileName, REFIID riid, IUnknown **ppIUnk)
264 FIXME("(%p %s, %p, %p): stub\n", szFileName, debugstr_w(szFileName), riid, *ppIUnk);
265 return ERROR_CALL_NOT_IMPLEMENTED;
268 HRESULT WINAPI GetVersionFromProcess(HANDLE hProcess, LPWSTR pVersion, DWORD cchBuffer, DWORD *dwLength)
270 FIXME("(%p, %p, %d, %p): stub\n", hProcess, pVersion, cchBuffer, dwLength);
271 return E_NOTIMPL;
274 HRESULT WINAPI DllGetClassObject(REFCLSID rclsid, REFIID riid, LPVOID* ppv)
276 FIXME("(%p, %p, %p): stub\n", rclsid, riid, ppv);
277 if(!ppv)
278 return E_INVALIDARG;
280 return E_NOTIMPL;
283 HRESULT WINAPI DllCanUnloadNow(VOID)
285 FIXME("stub\n");
286 return S_OK;