3 * Windows icall support.
5 * Copyright 2016 Microsoft
6 * Licensed under the MIT license. See LICENSE file in the project root for full license information.
11 #if defined(HOST_WIN32)
14 #include "mono/metadata/icall-windows-internals.h"
16 #if G_HAVE_API_SUPPORT(HAVE_CLASSIC_WINAPI_SUPPORT)
21 mono_icall_make_platform_path (gchar *path)
23 for (size_t i = strlen (path); i > 0; i--)
24 if (path [i-1] == '\\')
29 mono_icall_get_file_path_prefix (const gchar *path)
31 if (*path == '/' && *(path + 1) == '/') {
39 mono_icall_module_get_hinstance (MonoReflectionModuleHandle module)
41 MonoImage *image = MONO_HANDLE_GETVAL (module, image);
42 if (image && image->is_module_handle)
43 return image->raw_data;
45 return (gpointer) (-1);
48 #if G_HAVE_API_SUPPORT(HAVE_CLASSIC_WINAPI_SUPPORT)
50 mono_icall_get_machine_name (void)
56 len = MAX_COMPUTERNAME_LENGTH + 1;
57 buf = g_new (gunichar2, len);
60 if (GetComputerName (buf, (PDWORD) &len)) {
62 result = mono_string_new_utf16_checked (mono_domain_get (), buf, len, &error);
63 mono_error_set_pending_exception (&error);
69 #endif /* G_HAVE_API_SUPPORT(HAVE_CLASSIC_WINAPI_SUPPORT) */
72 mono_icall_get_platform (void)
79 mono_icall_get_new_line (void)
81 return mono_string_new (mono_domain_get (), "\r\n");
85 mono_icall_is_64bit_os (void)
87 #if SIZEOF_VOID_P == 8
90 gboolean isWow64Process = FALSE;
91 if (IsWow64Process (GetCurrentProcess (), &isWow64Process)) {
92 return (MonoBoolean)isWow64Process;
99 mono_icall_get_environment_variable_names (void)
110 env_strings = GetEnvironmentStrings();
113 env_string = env_strings;
114 while (*env_string != '\0') {
115 /* weird case that MS seems to skip */
116 if (*env_string != '=')
118 while (*env_string != '\0')
124 domain = mono_domain_get ();
125 names = mono_array_new_checked (domain, mono_defaults.string_class, n, &error);
126 if (mono_error_set_pending_exception (&error))
131 env_string = env_strings;
132 while (*env_string != '\0') {
133 /* weird case that MS seems to skip */
134 if (*env_string != '=') {
135 equal_str = wcschr(env_string, '=');
137 str = mono_string_new_utf16_checked (domain, env_string, (gint32)(equal_str - env_string), &error);
138 if (mono_error_set_pending_exception (&error))
141 mono_array_setref (names, n, str);
144 while (*env_string != '\0')
149 FreeEnvironmentStrings (env_strings);
156 mono_icall_set_environment_variable (MonoString *name, MonoString *value)
158 gunichar2 *utf16_name, *utf16_value;
160 utf16_name = mono_string_to_utf16 (name);
161 if ((value == NULL) || (mono_string_length (value) == 0) || (mono_string_chars (value)[0] == 0)) {
162 SetEnvironmentVariable (utf16_name, NULL);
167 utf16_value = mono_string_to_utf16 (value);
169 SetEnvironmentVariable (utf16_name, utf16_value);
172 g_free (utf16_value);
175 #if G_HAVE_API_SUPPORT(HAVE_CLASSIC_WINAPI_SUPPORT)
177 mono_icall_get_windows_folder_path (int folder)
179 #ifndef CSIDL_FLAG_CREATE
180 #define CSIDL_FLAG_CREATE 0x8000
183 WCHAR path [MAX_PATH];
184 /* Create directory if no existing */
185 if (SUCCEEDED (SHGetFolderPathW (NULL, folder | CSIDL_FLAG_CREATE, NULL, 0, path))) {
190 MonoString *res = mono_string_new_utf16_checked (mono_domain_get (), path, len, &error);
191 mono_error_set_pending_exception (&error);
194 return mono_string_new (mono_domain_get (), "");
196 #endif /* G_HAVE_API_SUPPORT(HAVE_CLASSIC_WINAPI_SUPPORT) */
198 #if G_HAVE_API_SUPPORT(HAVE_CLASSIC_WINAPI_SUPPORT)
200 mono_icall_broadcast_setting_change (void)
202 SendMessageTimeout (HWND_BROADCAST, WM_SETTINGCHANGE, (WPARAM)NULL, (LPARAM)L"Environment", SMTO_ABORTIFHUNG, 2000, 0);
206 mono_icall_wait_for_input_idle (gpointer handle, gint32 milliseconds)
208 return WaitForInputIdle (handle, milliseconds);
210 #endif /* G_HAVE_API_SUPPORT(HAVE_CLASSIC_WINAPI_SUPPORT) */
213 mono_icall_write_windows_debug_string (MonoString *message)
215 OutputDebugString (mono_string_chars (message));
218 #endif /* HOST_WIN32 */