1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
use crate;
use slice;
/// Converts a null-terminated UTF-16 wide string pointer to a Rust `String`.
///
/// # Parameters
///
/// - `ptr`: Pointer to a null-terminated UTF-16 string. A null pointer is
/// treated as an empty string.
///
/// # Returns
///
/// A `String` containing the decoded UTF-16 data. Invalid surrogate pairs
/// are replaced with `U+FFFD` (REPLACEMENT CHARACTER).
///
/// # Safety
///
/// The caller must ensure that `ptr` points to a valid null-terminated UTF-16
/// string, or is null. The string must not be mutated while this function
/// is reading from it.
/// Displays a custom Windows message box from C or C++ code.
///
/// This is the FFI-friendly entry point for native callers. The message and
/// title must be passed as null-terminated UTF-16 strings. A null pointer is
/// treated as an empty string.
///
/// # Parameters
///
/// - `msg`: Pointer to a null-terminated UTF-16 message string.
/// - `title`: Pointer to a null-terminated UTF-16 title string.
/// - `msgbox_type`: The message box icon style.
/// - `msgboxbtn_type`: The message box button combination.
/// - `timeout_ms`: Auto-close timeout in milliseconds. Use `0` for no timeout.
///
/// # Returns
///
/// - Returns the Windows API button result code when the user closes the dialog
/// by clicking a button, for example `1` for OK, `2` for Cancel, `6` for Yes,
/// and `7` for No.
/// - Returns `-1` when the dialog is closed automatically by the timeout
/// mechanism.
///
/// # C/C++ Declaration
///
/// ```c
/// // Link with the generated .dll/.lib
/// typedef enum {
/// MsgBoxType_Error = 0x0010,
/// MsgBoxType_Info = 0x0040,
/// MsgBoxType_Quest = 0x0020,
/// MsgBoxType_Warn = 0x0030,
/// } MsgBoxType;
///
/// typedef enum {
/// MsgBtnType_Ok = 0x0000,
/// MsgBtnType_OkCancel = 0x0001,
/// MsgBtnType_YesNo = 0x0004,
/// } MsgBtnType;
///
/// __declspec(dllimport) int __stdcall custom_msgbox_w(
/// const wchar_t* msg,
/// const wchar_t* title,
/// MsgBoxType msgbox_type,
/// MsgBtnType msgboxbtn_type,
/// unsigned long long timeout_ms
/// );
/// ```
///
/// # Example (C++)
///
/// ```cpp
/// #include <iostream>
///
/// extern "C" int custom_msgbox_w(
/// const wchar_t* msg, const wchar_t* title,
/// int msgbox_type, int msgboxbtn_type,
/// unsigned long long timeout_ms
/// );
///
/// int main() {
/// int result = custom_msgbox_w(
/// L"Hello from C++!",
/// L"FFI Demo",
/// 0x0040, // Info
/// 0x0000, // OK
/// 5000 // 5-second timeout
/// );
/// std::cout << "Result: " << result << std::endl;
/// return 0;
/// }
/// ```
pub extern "C"