2005-11-09 Miguel de Icaza <miguel@novell.com>
[mono.git] / mono / os / win32 / util.c
1 /*
2  * util.c: Simple runtime tools for the Win32 platform
3  *
4  * Author:
5  *   Miguel de Icaza
6  *
7  * (C) 2002 Ximian, Inc. (http://www.ximian.com)
8  */
9 #include <config.h>
10 #include <windows.h>
11 #include <mono/metadata/metadata.h>
12 #include <mono/metadata/assembly.h>
13 #include <mono/os/util.h>
14
15 #ifdef UNDER_CE
16 #undef GetModuleFileName
17 #define GetModuleFileName ceGetModuleFileNameA
18
19 DWORD ceGetModuleFileNameA(HMODULE hModule, char* lpFilename, DWORD nSize)
20 {
21         DWORD res = 0;
22         wchar_t* wbuff = (wchar_t*)LocalAlloc(LPTR, nSize*2);
23         res = GetModuleFileNameW(hModule, wbuff, nSize);
24         if (res) {
25                 int len = wcslen(wbuff);
26                 WideCharToMultiByte(CP_ACP, 0, wbuff, len, lpFilename, len, NULL, NULL);
27         }
28         LocalFree(wbuff);
29         return res;
30 }
31 #endif
32
33 /*
34  * mono_set_rootdir:
35  *
36  * Informs the runtime of the root directory for the Mono installation,
37  * the vm_file
38  */
39 void
40 mono_set_rootdir (void)
41 {
42         gunichar2 moddir [MAXPATHLEN];
43         gchar *bindir, *installdir, *root, *utf8name, *config;
44
45         GetModuleFileNameW (NULL, moddir, MAXPATHLEN);
46         utf8name = g_utf16_to_utf8 (moddir, -1, NULL, NULL, NULL);
47         bindir = g_path_get_dirname (utf8name);
48         installdir = g_path_get_dirname (bindir);
49         root = g_build_path (G_DIR_SEPARATOR_S, installdir, "lib", NULL);
50
51         config = g_build_filename (root, "..", "etc", NULL);
52         mono_set_dirs (root, config);
53
54         g_free (config);
55         g_free (root);
56         g_free (installdir);
57         g_free (bindir);
58         g_free (utf8name);
59
60 }
61
62