2 * icall-windows.c: Windows icall support.
4 * Copyright 2016 Microsoft
5 * Licensed under the MIT license. See LICENSE file in the project root for full license information.
10 #if defined(HOST_WIN32)
13 #include "mono/metadata/icall-windows-internals.h"
15 #if G_HAVE_API_SUPPORT(HAVE_CLASSIC_WINAPI_SUPPORT)
20 mono_icall_make_platform_path (gchar *path)
22 for (size_t i = strlen (path); i > 0; i--)
23 if (path [i-1] == '\\')
28 mono_icall_get_file_path_prefix (const gchar *path)
30 if (*path == '/' && *(path + 1) == '/') {
38 mono_icall_module_get_hinstance (MonoReflectionModule *module)
40 if (module->image && module->image->is_module_handle)
41 return module->image->raw_data;
43 return (gpointer) (-1);
46 #if G_HAVE_API_SUPPORT(HAVE_CLASSIC_WINAPI_SUPPORT)
48 mono_icall_get_machine_name (void)
54 len = MAX_COMPUTERNAME_LENGTH + 1;
55 buf = g_new (gunichar2, len);
58 if (GetComputerName (buf, (PDWORD) &len)) {
60 result = mono_string_new_utf16_checked (mono_domain_get (), buf, len, &error);
61 mono_error_set_pending_exception (&error);
67 #endif /* G_HAVE_API_SUPPORT(HAVE_CLASSIC_WINAPI_SUPPORT) */
70 mono_icall_get_platform (void)
77 mono_icall_get_new_line (void)
79 return mono_string_new (mono_domain_get (), "\r\n");
83 mono_icall_is_64bit_os (void)
85 #if SIZEOF_VOID_P == 8
88 gboolean isWow64Process = FALSE;
89 if (IsWow64Process (GetCurrentProcess (), &isWow64Process)) {
90 return (MonoBoolean)isWow64Process;
97 mono_icall_get_environment_variable_names (void)
108 env_strings = GetEnvironmentStrings();
111 env_string = env_strings;
112 while (*env_string != '\0') {
113 /* weird case that MS seems to skip */
114 if (*env_string != '=')
116 while (*env_string != '\0')
122 domain = mono_domain_get ();
123 names = mono_array_new_checked (domain, mono_defaults.string_class, n, &error);
124 if (mono_error_set_pending_exception (&error))
129 env_string = env_strings;
130 while (*env_string != '\0') {
131 /* weird case that MS seems to skip */
132 if (*env_string != '=') {
133 equal_str = wcschr(env_string, '=');
135 str = mono_string_new_utf16_checked (domain, env_string, (gint32)(equal_str - env_string), &error);
136 if (mono_error_set_pending_exception (&error))
139 mono_array_setref (names, n, str);
142 while (*env_string != '\0')
147 FreeEnvironmentStrings (env_strings);
154 mono_icall_set_environment_variable (MonoString *name, MonoString *value)
156 gunichar2 *utf16_name, *utf16_value;
158 utf16_name = mono_string_to_utf16 (name);
159 if ((value == NULL) || (mono_string_length (value) == 0) || (mono_string_chars (value)[0] == 0)) {
160 SetEnvironmentVariable (utf16_name, NULL);
165 utf16_value = mono_string_to_utf16 (value);
167 SetEnvironmentVariable (utf16_name, utf16_value);
170 g_free (utf16_value);
173 #if G_HAVE_API_SUPPORT(HAVE_CLASSIC_WINAPI_SUPPORT)
175 mono_icall_get_windows_folder_path (int folder)
177 #ifndef CSIDL_FLAG_CREATE
178 #define CSIDL_FLAG_CREATE 0x8000
181 WCHAR path [MAX_PATH];
182 /* Create directory if no existing */
183 if (SUCCEEDED (SHGetFolderPathW (NULL, folder | CSIDL_FLAG_CREATE, NULL, 0, path))) {
188 MonoString *res = mono_string_new_utf16_checked (mono_domain_get (), path, len, &error);
189 mono_error_set_pending_exception (&error);
192 return mono_string_new (mono_domain_get (), "");
194 #endif /* G_HAVE_API_SUPPORT(HAVE_CLASSIC_WINAPI_SUPPORT) */
196 #if G_HAVE_API_SUPPORT(HAVE_CLASSIC_WINAPI_SUPPORT)
198 mono_icall_broadcast_setting_change (void)
200 SendMessageTimeout (HWND_BROADCAST, WM_SETTINGCHANGE, (WPARAM)NULL, (LPARAM)L"Environment", SMTO_ABORTIFHUNG, 2000, 0);
204 mono_icall_wait_for_input_idle (gpointer handle, gint32 milliseconds)
206 return WaitForInputIdle (handle, milliseconds);
208 #endif /* G_HAVE_API_SUPPORT(HAVE_CLASSIC_WINAPI_SUPPORT) */
211 mono_icall_write_windows_debug_string (MonoString *message)
213 OutputDebugString (mono_string_chars (message));
217 mono_icall_close_process (gpointer handle)
219 return (MonoBoolean)(CloseHandle (handle));
221 #endif /* HOST_WIN32 */