1 /* 2 * This file is part of gtkD. 3 * 4 * gtkD is free software; you can redistribute it and/or modify 5 * it under the terms of the GNU Lesser General Public License 6 * as published by the Free Software Foundation; either version 3 7 * of the License, or (at your option) any later version, with 8 * some exceptions, please read the COPYING file. 9 * 10 * gtkD is distributed in the hope that it will be useful, 11 * but WITHOUT ANY WARRANTY; without even the implied warranty of 12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 13 * GNU Lesser General Public License for more details. 14 * 15 * You should have received a copy of the GNU Lesser General Public License 16 * along with gtkD; if not, write to the Free Software 17 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110, USA 18 */ 19 20 // generated automatically - do not change 21 // find conversion definition on APILookup.txt 22 // implement new conversion functionalities on the wrap.utils pakage 23 24 /* 25 * Conversion parameters: 26 * inFile = glib-Windows-Compatibility-Functions.html 27 * outPack = glib 28 * outFile = WindowsUtils 29 * strct = 30 * realStrct= 31 * ctorStrct= 32 * clss = WindowsUtils 33 * interf = 34 * class Code: No 35 * interface Code: No 36 * template for: 37 * extend = 38 * implements: 39 * prefixes: 40 * - g_win32_ 41 * omit structs: 42 * omit prefixes: 43 * omit code: 44 * omit signals: 45 * imports: 46 * - glib.Str 47 * structWrap: 48 * module aliases: 49 * local aliases: 50 * overrides: 51 */ 52 53 module glib.WindowsUtils; 54 55 public import gtkc.glibtypes; 56 57 private import gtkc.glib; 58 private import glib.ConstructionException; 59 60 61 private import glib.Str; 62 63 64 65 66 /** 67 * These functions provide some level of UNIX emulation on the 68 * Windows platform. If your application really needs the POSIX 69 * APIs, we suggest you try the Cygwin project. 70 */ 71 public class WindowsUtils 72 { 73 74 /** 75 */ 76 77 /** 78 * Translate a Win32 error code (as returned by GetLastError()) into 79 * the corresponding message. The message is either language neutral, 80 * or in the thread's language, or the user's language, the system's 81 * language, or US English (see docs for FormatMessage()). The 82 * returned string is in UTF-8. It should be deallocated with 83 * g_free(). 84 * Params: 85 * error = error code. 86 * Returns: newly-allocated error message 87 */ 88 public static string errorMessage(int error) 89 { 90 // gchar * g_win32_error_message (gint error); 91 return Str.toString(g_win32_error_message(error)); 92 } 93 94 /** 95 * The setlocale() function in the Microsoft C library uses locale 96 * names of the form "English_United States.1252" etc. We want the 97 * UNIXish standard form "en_US", "zh_TW" etc. This function gets the 98 * current thread locale from Windows - without any encoding info - 99 * and returns it as a string of the above form for use in forming 100 * file names etc. The returned string should be deallocated with 101 * g_free(). 102 * Returns: newly-allocated locale name. 103 */ 104 public static string getlocale() 105 { 106 // gchar * g_win32_getlocale (void); 107 return Str.toString(g_win32_getlocale()); 108 } 109 110 /** 111 * Warning 112 * g_win32_get_package_installation_directory has been deprecated since version 2.18 and should not be used in newly-written code. Pass the HMODULE of a DLL or EXE to 113 * g_win32_get_package_installation_directory_of_module() instead. 114 * Try to determine the installation directory for a software package. 115 * This function is deprecated. Use 116 * g_win32_get_package_installation_directory_of_module() instead. 117 * The use of package is deprecated. You should always pass NULL. A 118 * warning is printed if non-NULL is passed as package. 119 * The original intended use of package was for a short identifier of 120 * the package, typically the same identifier as used for 121 * GETTEXT_PACKAGE in software configured using GNU 122 * autotools. The function first looks in the Windows Registry for the 123 * value #InstallationDirectory in the key 124 * #HKLM\Software@package, and if that value 125 * exists and is a string, returns that. 126 * It is strongly recommended that packagers of GLib-using libraries 127 * for Windows do not store installation paths in the Registry to be 128 * used by this function as that interfers with having several 129 * parallel installations of the library. Enabling multiple 130 * installations of different versions of some GLib-using library, or 131 * GLib itself, is desirable for various reasons. 132 * For this reason it is recommeded to always pass NULL as 133 * package to this function, to avoid the temptation to use the 134 * Registry. In version 2.20 of GLib the package parameter 135 * will be ignored and this function won't look in the Registry at all. 136 * If package is NULL, or the above value isn't found in the 137 * Registry, but dll_name is non-NULL, it should name a DLL loaded 138 * into the current process. Typically that would be the name of the 139 * DLL calling this function, looking for its installation 140 * directory. The function then asks Windows what directory that DLL 141 * was loaded from. If that directory's last component is "bin" or 142 * "lib", the parent directory is returned, otherwise the directory 143 * itself. If that DLL isn't loaded, the function proceeds as if 144 * dll_name was NULL. 145 * If both package and dll_name are NULL, the directory from where 146 * the main executable of the process was loaded is used instead in 147 * the same way as above. 148 * Params: 149 * dllName = The name of a DLL that a package provides in UTF-8, or NULL. [allow-none] 150 * Returns: a string containing the installation directory for package. The string is in the GLib file name encoding, i.e. UTF-8. The return value should be freed with g_free() when not needed any longer. If the function fails NULL is returned. 151 */ 152 public static string getPackageInstallationDirectory(string p, string dllName) 153 { 154 // gchar * g_win32_get_package_installation_directory (const gchar *package, const gchar *dll_name); 155 return Str.toString(g_win32_get_package_installation_directory(Str.toStringz(p), Str.toStringz(dllName))); 156 } 157 158 /** 159 * This function tries to determine the installation directory of a 160 * software package based on the location of a DLL of the software 161 * package. 162 * hmodule should be the handle of a loaded DLL or NULL. The 163 * function looks up the directory that DLL was loaded from. If 164 * hmodule is NULL, the directory the main executable of the current 165 * process is looked up. If that directory's last component is "bin" 166 * or "lib", its parent directory is returned, otherwise the directory 167 * itself. 168 * It thus makes sense to pass only the handle to a "public" DLL of a 169 * software package to this function, as such DLLs typically are known 170 * to be installed in a "bin" or occasionally "lib" subfolder of the 171 * installation folder. DLLs that are of the dynamically loaded module 172 * or plugin variety are often located in more private locations 173 * deeper down in the tree, from which it is impossible for GLib to 174 * deduce the root of the package installation. 175 * The typical use case for this function is to have a DllMain() that 176 * saves the handle for the DLL. Then when code in the DLL needs to 177 * construct names of files in the installation tree it calls this 178 * function passing the DLL handle. 179 * Since 2.16 180 * Params: 181 * hmodule = The Win32 handle for a DLL loaded into the current process, or NULL. [allow-none] 182 * Returns: a string containing the guessed installation directory for the software package hmodule is from. The string is in the GLib file name encoding, i.e. UTF-8. The return value should be freed with g_free() when not needed any longer. If the function fails NULL is returned. 183 */ 184 public static string getPackageInstallationDirectoryOfModule(void* hmodule) 185 { 186 // gchar * g_win32_get_package_installation_directory_of_module (gpointer hmodule); 187 return Str.toString(g_win32_get_package_installation_directory_of_module(hmodule)); 188 } 189 190 /** 191 * Warning 192 * g_win32_get_package_installation_subdirectory has been deprecated since version 2.18 and should not be used in newly-written code. Pass the HMODULE of a DLL or EXE to 193 * g_win32_get_package_installation_directory_of_module() instead, and 194 * then construct a subdirectory pathname with g_build_filename(). 195 * This function is deprecated. Use 196 * g_win32_get_package_installation_directory_of_module() and 197 * g_build_filename() instead. 198 * Returns a newly-allocated string containing the path of the 199 * subdirectory subdir in the return value from calling 200 * g_win32_get_package_installation_directory() with the package and 201 * dll_name parameters. See the documentation for 202 * g_win32_get_package_installation_directory() for more details. In 203 * particular, note that it is deprecated to pass anything except NULL 204 * as package. 205 * Params: 206 * dllName = The name of a DLL that a package provides, in UTF-8, or NULL. [allow-none] 207 * subdir = A subdirectory of the package installation directory, also in UTF-8 208 * Returns: a string containing the complete path to subdir inside the installation directory of package. The returned string is in the GLib file name encoding, i.e. UTF-8. The return value should be freed with g_free() when no longer needed. If something goes wrong, NULL is returned. 209 */ 210 public static string getPackageInstallationSubdirectory(string p, string dllName, string subdir) 211 { 212 // gchar * g_win32_get_package_installation_subdirectory (const gchar *package, const gchar *dll_name, const gchar *subdir); 213 return Str.toString(g_win32_get_package_installation_subdirectory(Str.toStringz(p), Str.toStringz(dllName), Str.toStringz(subdir))); 214 } 215 216 /** 217 * Returns version information for the Windows operating system the 218 * code is running on. See MSDN documentation for the GetVersion() 219 * function. To summarize, the most significant bit is one on Win9x, 220 * and zero on NT-based systems. Since version 2.14, GLib works only 221 * on NT-based systems, so checking whether your are running on Win9x 222 * in your own software is moot. The least significant byte is 4 on 223 * Windows NT 4, and 5 on Windows XP. Software that needs really 224 * detailed version and feature information should use Win32 API like 225 * GetVersionEx() and VerifyVersionInfo(). 226 * Since 2.6 227 * Returns: The version information. 228 */ 229 public static uint getWindowsVersion() 230 { 231 // guint g_win32_get_windows_version (void); 232 return g_win32_get_windows_version(); 233 } 234 235 /** 236 * Converts a filename from UTF-8 to the system codepage. 237 * On NT-based Windows, on NTFS file systems, file names are in 238 * Unicode. It is quite possible that Unicode file names contain 239 * characters not representable in the system codepage. (For instance, 240 * Greek or Cyrillic characters on Western European or US Windows 241 * installations, or various less common CJK characters on CJK Windows 242 * installations.) 243 * In such a case, and if the filename refers to an existing file, and 244 * the file system stores alternate short (8.3) names for directory 245 * entries, the short form of the filename is returned. Note that the 246 * "short" name might in fact be longer than the Unicode name if the 247 * Unicode name has very short pathname components containing 248 * non-ASCII characters. If no system codepage name for the file is 249 * possible, NULL is returned. 250 * The return value is dynamically allocated and should be freed with 251 * g_free() when no longer needed. 252 * Since 2.8 253 * Params: 254 * utf8filename = a UTF-8 encoded filename. 255 * Returns: The converted filename, or NULL on conversion failure and lack of short names. 256 */ 257 public static string localeFilenameFromUtf8(string utf8filename) 258 { 259 // gchar * g_win32_locale_filename_from_utf8 (const gchar *utf8filename); 260 return Str.toString(g_win32_locale_filename_from_utf8(Str.toStringz(utf8filename))); 261 } 262 }