Branch data Line data Source code
1 : : /* GLIB - Library of useful routines for C programming
2 : : * Copyright (C) 1995-1997 Peter Mattis, Spencer Kimball and Josh MacDonald
3 : : *
4 : : * SPDX-License-Identifier: LGPL-2.1-or-later
5 : : *
6 : : * This library is free software; you can redistribute it and/or
7 : : * modify it under the terms of the GNU Lesser General Public
8 : : * License as published by the Free Software Foundation; either
9 : : * version 2.1 of the License, or (at your option) any later version.
10 : : *
11 : : * This library is distributed in the hope that it will be useful,
12 : : * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 : : * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14 : : * Lesser General Public License for more details.
15 : : *
16 : : * You should have received a copy of the GNU Lesser General Public
17 : : * License along with this library; if not, see <http://www.gnu.org/licenses/>.
18 : : */
19 : :
20 : : /*
21 : : * Modified by the GLib Team and others 1997-2000. See the AUTHORS
22 : : * file for a list of people on the GLib Team. See the ChangeLog
23 : : * files for a list of changes. These files are distributed with
24 : : * GLib at ftp://ftp.gtk.org/pub/gtk/.
25 : : */
26 : :
27 : : #ifndef __G_WIN32_H__
28 : : #define __G_WIN32_H__
29 : :
30 : : #if !defined (__GLIB_H_INSIDE__) && !defined (GLIB_COMPILATION)
31 : : #error "Only <glib.h> can be included directly."
32 : : #endif
33 : :
34 : : #include <glib/gtypes.h>
35 : :
36 : : #ifdef G_PLATFORM_WIN32
37 : :
38 : : G_BEGIN_DECLS
39 : :
40 : : #ifndef MAXPATHLEN
41 : : #define MAXPATHLEN 1024
42 : : #endif
43 : :
44 : : #ifdef G_OS_WIN32
45 : :
46 : : /*
47 : : * To get prototypes for the following POSIXish functions, you have to
48 : : * include the indicated non-POSIX headers. The functions are defined
49 : : * in OLDNAMES.LIB (MSVC) or -lmoldname-msvc (mingw32). But note that
50 : : * for POSIX functions that take or return file names in the system
51 : : * codepage, in many cases you would want to use the GLib wrappers in
52 : : * gstdio.h and UTF-8 instead.
53 : : *
54 : : * getcwd: <direct.h> (MSVC), <io.h> (mingw32)
55 : : * getpid: <process.h>
56 : : * access: <io.h>
57 : : * unlink: <stdio.h> or <io.h>
58 : : * open, read, write, lseek, close: <io.h>
59 : : * rmdir: <io.h>
60 : : * pipe: <io.h> (actually, _pipe())
61 : : */
62 : :
63 : : /* For some POSIX functions that are not provided by the MS runtime,
64 : : * we provide emulation functions in glib, which are prefixed with
65 : : * g_win32_. Or that was the idea at some time, but there is just one
66 : : * of those:
67 : : */
68 : : GLIB_AVAILABLE_IN_ALL
69 : : gint g_win32_ftruncate (gint f,
70 : : guint size);
71 : : #endif /* G_OS_WIN32 */
72 : :
73 : : /* The MS setlocale uses locale names of the form "English_United
74 : : * States.1252" etc. We want the Unixish standard form "en", "zh_TW"
75 : : * etc. This function gets the current thread locale from Windows and
76 : : * returns it as a string of the above form for use in forming file
77 : : * names etc. The returned string should be deallocated with g_free().
78 : : */
79 : : GLIB_AVAILABLE_IN_ALL
80 : : gchar* g_win32_getlocale (void);
81 : :
82 : : /* Translate a Win32 error code (as returned by GetLastError()) into
83 : : * the corresponding message. The returned string should be deallocated
84 : : * with g_free().
85 : : */
86 : : GLIB_AVAILABLE_IN_ALL
87 : : gchar* g_win32_error_message (gint error);
88 : :
89 : : GLIB_DEPRECATED
90 : : gchar* g_win32_get_package_installation_directory (const gchar *package,
91 : : const gchar *dll_name);
92 : :
93 : : GLIB_DEPRECATED
94 : : gchar* g_win32_get_package_installation_subdirectory (const gchar *package,
95 : : const gchar *dll_name,
96 : : const gchar *subdir);
97 : :
98 : : GLIB_AVAILABLE_IN_ALL
99 : : gchar* g_win32_get_package_installation_directory_of_module (gpointer hmodule);
100 : :
101 : : GLIB_DEPRECATED_IN_2_44_FOR(g_win32_check_windows_version)
102 : : guint g_win32_get_windows_version (void);
103 : :
104 : : GLIB_AVAILABLE_IN_ALL
105 : : gchar* g_win32_locale_filename_from_utf8 (const gchar *utf8filename);
106 : :
107 : : GLIB_AVAILABLE_IN_2_40
108 : : gchar ** g_win32_get_command_line (void);
109 : :
110 : : /* As of GLib 2.14 we only support NT-based Windows */
111 : : #define G_WIN32_IS_NT_BASED() TRUE
112 : : #define G_WIN32_HAVE_WIDECHAR_API() TRUE
113 : :
114 : : /**
115 : : * GWin32OSType:
116 : : * @G_WIN32_OS_ANY: The running system can be a workstation or a server edition of
117 : : * Windows. The type of the running system is therefore not checked.
118 : : * @G_WIN32_OS_WORKSTATION: The running system is a workstation edition of Windows,
119 : : * such as Windows 7 Professional.
120 : : * @G_WIN32_OS_SERVER: The running system is a server edition of Windows, such as
121 : : * Windows Server 2008 R2.
122 : : *
123 : : * Type of Windows edition to check for at run-time.
124 : : **/
125 : : typedef enum
126 : : {
127 : : G_WIN32_OS_ANY,
128 : : G_WIN32_OS_WORKSTATION,
129 : : G_WIN32_OS_SERVER,
130 : : } GWin32OSType;
131 : :
132 : : GLIB_AVAILABLE_IN_2_44
133 : : gboolean g_win32_check_windows_version (const gint major,
134 : : const gint minor,
135 : : const gint spver,
136 : : const GWin32OSType os_type);
137 : :
138 : : /**
139 : : * g_win32_clear_com:
140 : : * @com_obj: (not optional) (nullable): Pointer to COM object pointer to release and clear
141 : : *
142 : : * Releases the referenced COM object, and clears its pointer to `NULL`.
143 : : *
144 : : * The @com_obj pointer must not be `NULL`.
145 : : *
146 : : * If @com_obj references a `NULL` COM object, this function is a no-op.
147 : : *
148 : : * This is equivalent to `g_clear_object()` for dealing with
149 : : * Windows COM objects.
150 : : *
151 : : * Since: 2.84
152 : : */
153 : :
154 : : #ifndef __cplusplus
155 : :
156 : : #define g_win32_clear_com(com_obj) \
157 : : G_STMT_START {\
158 : : IUnknown **unknown_com_obj = (IUnknown **)(com_obj); \
159 : : \
160 : : if (*unknown_com_obj) \
161 : : { \
162 : : (*unknown_com_obj)->lpVtbl->Release (*unknown_com_obj); \
163 : : *unknown_com_obj = NULL; \
164 : : } \
165 : : } G_STMT_END \
166 : : GLIB_AVAILABLE_MACRO_IN_2_84
167 : :
168 : : #endif
169 : :
170 : : G_END_DECLS
171 : :
172 : : #ifdef __cplusplus
173 : : /*
174 : : * There are COM objects that only have C++-style definitions, such as DirectWrite
175 : : * from the Windows SDK (albeit a C interface is provided for the mingw-w64 toolchain),
176 : : * so we need to have a C++ version for this
177 : : */
178 : : template <typename com_interface>
179 : : static inline void
180 : 27 : g_win32_clear_com (com_interface **com_obj)
181 : : {
182 : 27 : if (*com_obj != NULL)
183 : : {
184 : 18 : (*com_obj)->Release ();
185 : 18 : *com_obj = NULL;
186 : 18 : }
187 : 27 : }
188 : : #endif
189 : :
190 : : #endif /* G_PLATFORM_WIN32 */
191 : :
192 : : #endif /* __G_WIN32_H__ */
|