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 (MonoReflectionModuleHandle module
)
40 MonoImage
*image
= MONO_HANDLE_GETVAL (module
, image
);
41 if (image
&& image
->is_module_handle
)
42 return image
->raw_data
;
44 return (gpointer
) (-1);
47 #if G_HAVE_API_SUPPORT(HAVE_CLASSIC_WINAPI_SUPPORT)
49 mono_icall_get_machine_name (void)
55 len
= MAX_COMPUTERNAME_LENGTH
+ 1;
56 buf
= g_new (gunichar2
, len
);
59 if (GetComputerName (buf
, (PDWORD
) &len
)) {
61 result
= mono_string_new_utf16_checked (mono_domain_get (), buf
, len
, &error
);
62 mono_error_set_pending_exception (&error
);
68 #endif /* G_HAVE_API_SUPPORT(HAVE_CLASSIC_WINAPI_SUPPORT) */
71 mono_icall_get_platform (void)
78 mono_icall_get_new_line (void)
80 return mono_string_new (mono_domain_get (), "\r\n");
84 mono_icall_is_64bit_os (void)
86 #if SIZEOF_VOID_P == 8
89 gboolean isWow64Process
= FALSE
;
90 if (IsWow64Process (GetCurrentProcess (), &isWow64Process
)) {
91 return (MonoBoolean
)isWow64Process
;
98 mono_icall_get_environment_variable_names (void)
109 env_strings
= GetEnvironmentStrings();
112 env_string
= env_strings
;
113 while (*env_string
!= '\0') {
114 /* weird case that MS seems to skip */
115 if (*env_string
!= '=')
117 while (*env_string
!= '\0')
123 domain
= mono_domain_get ();
124 names
= mono_array_new_checked (domain
, mono_defaults
.string_class
, n
, &error
);
125 if (mono_error_set_pending_exception (&error
))
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
);
137 if (mono_error_set_pending_exception (&error
))
140 mono_array_setref (names
, n
, str
);
143 while (*env_string
!= '\0')
148 FreeEnvironmentStrings (env_strings
);
155 mono_icall_set_environment_variable (MonoString
*name
, MonoString
*value
)
157 gunichar2
*utf16_name
, *utf16_value
;
159 utf16_name
= mono_string_to_utf16 (name
);
160 if ((value
== NULL
) || (mono_string_length (value
) == 0) || (mono_string_chars (value
)[0] == 0)) {
161 SetEnvironmentVariable (utf16_name
, NULL
);
166 utf16_value
= mono_string_to_utf16 (value
);
168 SetEnvironmentVariable (utf16_name
, utf16_value
);
171 g_free (utf16_value
);
174 #if G_HAVE_API_SUPPORT(HAVE_CLASSIC_WINAPI_SUPPORT)
176 mono_icall_get_windows_folder_path (int folder
)
178 #ifndef CSIDL_FLAG_CREATE
179 #define CSIDL_FLAG_CREATE 0x8000
182 WCHAR path
[MAX_PATH
];
183 /* Create directory if no existing */
184 if (SUCCEEDED (SHGetFolderPathW (NULL
, folder
| CSIDL_FLAG_CREATE
, NULL
, 0, path
))) {
189 MonoString
*res
= mono_string_new_utf16_checked (mono_domain_get (), path
, len
, &error
);
190 mono_error_set_pending_exception (&error
);
193 return mono_string_new (mono_domain_get (), "");
195 #endif /* G_HAVE_API_SUPPORT(HAVE_CLASSIC_WINAPI_SUPPORT) */
197 #if G_HAVE_API_SUPPORT(HAVE_CLASSIC_WINAPI_SUPPORT)
199 mono_icall_broadcast_setting_change (void)
201 SendMessageTimeout (HWND_BROADCAST
, WM_SETTINGCHANGE
, (WPARAM
)NULL
, (LPARAM
)L
"Environment", SMTO_ABORTIFHUNG
, 2000, 0);
205 mono_icall_wait_for_input_idle (gpointer handle
, gint32 milliseconds
)
207 return WaitForInputIdle (handle
, milliseconds
);
209 #endif /* G_HAVE_API_SUPPORT(HAVE_CLASSIC_WINAPI_SUPPORT) */
212 mono_icall_write_windows_debug_string (MonoString
*message
)
214 OutputDebugString (mono_string_chars (message
));
217 #endif /* HOST_WIN32 */