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"
15 #include "mono/metadata/w32subset.h"
16 #if HAVE_API_SUPPORT_WIN32_SH_GET_FOLDER_PATH
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 (MonoImage
*image
)
41 if (image
&& m_image_is_module_handle (image
))
42 return image
->raw_data
;
44 return (gpointer
) (-1);
47 #if HAVE_API_SUPPORT_WIN32_GET_COMPUTER_NAME
48 // Support older UWP SDK?
58 mono_icall_get_machine_name (MonoError
*error
)
60 gunichar2 buf
[MAX_COMPUTERNAME_LENGTH
+ 1];
61 DWORD len
= G_N_ELEMENTS (buf
);
63 if (GetComputerNameW (buf
, &len
))
64 return mono_string_new_utf16_handle (mono_domain_get (), buf
, len
, error
);
65 return MONO_HANDLE_NEW (MonoString
, NULL
);
70 mono_icall_get_platform (void)
77 mono_icall_get_new_line (MonoError
*error
)
79 return mono_string_new_handle (mono_domain_get (), "\r\n", error
);
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 (MonoError
*error
)
99 MonoArrayHandle names
;
101 MonoStringHandle str
;
107 env_strings
= GetEnvironmentStrings();
110 env_string
= env_strings
;
111 while (*env_string
!= '\0') {
112 /* weird case that MS seems to skip */
113 if (*env_string
!= '=')
115 while (*env_string
!= '\0')
121 domain
= mono_domain_get ();
122 names
= mono_array_new_handle (domain
, mono_defaults
.string_class
, n
, error
);
123 return_val_if_nok (error
, NULL_HANDLE_ARRAY
);
127 str
= MONO_HANDLE_NEW (MonoString
, NULL
);
128 env_string
= env_strings
;
129 while (*env_string
!= '\0') {
130 /* weird case that MS seems to skip */
131 if (*env_string
!= '=') {
132 equal_str
= wcschr(env_string
, '=');
134 MonoString
*s
= mono_string_new_utf16_checked (domain
, env_string
, (gint32
)(equal_str
- env_string
), error
);
135 goto_if_nok (error
, cleanup
);
136 MONO_HANDLE_ASSIGN_RAW (str
, s
);
138 mono_array_handle_setref (names
, n
, str
);
141 while (*env_string
!= '\0')
150 FreeEnvironmentStrings (env_strings
);
152 return NULL_HANDLE_ARRAY
;
156 #if HAVE_API_SUPPORT_WIN32_SH_GET_FOLDER_PATH
158 mono_icall_get_windows_folder_path (int folder
, MonoError
*error
)
161 #ifndef CSIDL_FLAG_CREATE
162 #define CSIDL_FLAG_CREATE 0x8000
165 WCHAR path
[MAX_PATH
];
166 /* Create directory if no existing */
167 if (SUCCEEDED (SHGetFolderPathW (NULL
, folder
| CSIDL_FLAG_CREATE
, NULL
, 0, path
))) {
171 return mono_string_new_utf16_handle (mono_domain_get (), path
, len
, error
);
173 return mono_string_new_handle (mono_domain_get (), "", error
);
177 #if HAVE_API_SUPPORT_WIN32_SEND_MESSAGE_TIMEOUT
179 ves_icall_System_Environment_BroadcastSettingChange (MonoError
*error
)
181 SendMessageTimeout (HWND_BROADCAST
, WM_SETTINGCHANGE
, (WPARAM
)NULL
, (LPARAM
)L
"Environment", SMTO_ABORTIFHUNG
, 2000, 0);
185 #if HAVE_API_SUPPORT_WIN32_WAIT_FOR_INPUT_IDLE
187 mono_icall_wait_for_input_idle (gpointer handle
, gint32 milliseconds
)
189 return WaitForInputIdle (handle
, milliseconds
);
194 mono_icall_write_windows_debug_string (const gunichar2
*message
)
196 OutputDebugString (message
);
199 #endif /* HOST_WIN32 */