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 (MonoError *error)
54 MonoStringHandle result;
56 len = MAX_COMPUTERNAME_LENGTH + 1;
57 buf = g_new (gunichar2, len);
60 if (GetComputerName (buf, (PDWORD) &len)) {
61 result = mono_string_new_utf16_handle (mono_domain_get (), buf, len, error);
63 result = MONO_HANDLE_NEW (MonoString, NULL);
68 #endif /* G_HAVE_API_SUPPORT(HAVE_CLASSIC_WINAPI_SUPPORT) */
71 mono_icall_get_platform (void)
78 mono_icall_get_new_line (MonoError *error)
81 return mono_string_new_handle (mono_domain_get (), "\r\n", error);
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 (MonoError *error)
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 return_val_if_nok (error, NULL);
130 env_string = env_strings;
131 while (*env_string != '\0') {
132 /* weird case that MS seems to skip */
133 if (*env_string != '=') {
134 equal_str = wcschr(env_string, '=');
136 str = mono_string_new_utf16_checked (domain, env_string, (gint32)(equal_str - env_string), error);
140 mono_array_setref (names, n, str);
143 while (*env_string != '\0')
152 FreeEnvironmentStrings (env_strings);
159 mono_icall_set_environment_variable (MonoString *name, MonoString *value)
161 gunichar2 *utf16_name, *utf16_value;
163 utf16_name = mono_string_to_utf16 (name);
164 if ((value == NULL) || (mono_string_length (value) == 0) || (mono_string_chars (value)[0] == 0)) {
165 SetEnvironmentVariable (utf16_name, NULL);
170 utf16_value = mono_string_to_utf16 (value);
172 SetEnvironmentVariable (utf16_name, utf16_value);
175 g_free (utf16_value);
178 #if G_HAVE_API_SUPPORT(HAVE_CLASSIC_WINAPI_SUPPORT)
180 mono_icall_get_windows_folder_path (int folder, MonoError *error)
183 #ifndef CSIDL_FLAG_CREATE
184 #define CSIDL_FLAG_CREATE 0x8000
187 WCHAR path [MAX_PATH];
188 /* Create directory if no existing */
189 if (SUCCEEDED (SHGetFolderPathW (NULL, folder | CSIDL_FLAG_CREATE, NULL, 0, path))) {
193 return mono_string_new_utf16_handle (mono_domain_get (), path, len, error);
195 return mono_string_new_handle (mono_domain_get (), "", error);
197 #endif /* G_HAVE_API_SUPPORT(HAVE_CLASSIC_WINAPI_SUPPORT) */
199 #if G_HAVE_API_SUPPORT(HAVE_CLASSIC_WINAPI_SUPPORT)
201 mono_icall_broadcast_setting_change (void)
203 SendMessageTimeout (HWND_BROADCAST, WM_SETTINGCHANGE, (WPARAM)NULL, (LPARAM)L"Environment", SMTO_ABORTIFHUNG, 2000, 0);
207 mono_icall_wait_for_input_idle (gpointer handle, gint32 milliseconds)
209 return WaitForInputIdle (handle, milliseconds);
211 #endif /* G_HAVE_API_SUPPORT(HAVE_CLASSIC_WINAPI_SUPPORT) */
214 mono_icall_write_windows_debug_string (MonoString *message)
216 OutputDebugString (mono_string_chars (message));
219 #endif /* HOST_WIN32 */