Windows Compatibility Functions

Windows Compatibility Functions — UNIX emulation on Windows.

Synopsis


#include <glib.h>


#define     MAXPATHLEN
typedef     pid_t;
#define     pipe                            (phandles)
#define     ftruncate                       (fd, size)
gchar*      g_win32_error_message           (gint error);
gchar*      g_win32_getlocale               (void);
gchar*      g_win32_get_package_installation_directory
                                            (gchar *package,
                                             gchar *dll_name);
gchar*      g_win32_get_package_installation_subdirectory
                                            (gchar *package,
                                             gchar *dll_name,
                                             gchar *subdir);
#define     G_WIN32_DLLMAIN_FOR_DLL_NAME    (static, dll_name)

Description

Details

MAXPATHLEN

#define MAXPATHLEN 1024

Provided for UNIX emulation on Windows; equivalent to UNIX macro MAXPATHLEN, which is the maximum length of a filename (including full path).


pid_t

typedef int pid_t;

Provided for UNIX emulation on Windows; process ID type.


pipe()

#define pipe(phandles)	_pipe (phandles, 4096, _O_BINARY)

Provided for UNIX emulation on Windows; see documentation for pipe() in any UNIX manual.

phandles :

ftruncate()

#    define ftruncate(fd, size)	g_win32_ftruncate (fd, size)

Provided for UNIX emulation on Windows; see documentation for ftruncate() in any UNIX manual.

fd :
size :

g_win32_error_message ()

gchar*      g_win32_error_message           (gint error);

Translate a Win32 error code (as returned by GetLastError()) into the corresponding message. The message is either language neutral, or in the thread's language, or the user's language, the system's language, or US English (see docs for FormatMessage()). * The returned string should be deallocated with g_free().

error : error code.
Returns : newly-allocated error message

g_win32_getlocale ()

gchar*      g_win32_getlocale               (void);

The setlocale in the Microsoft C library uses locale names of the form "English_United States.1252" etc. We want the UNIXish standard form "en_US", "zh_TW" etc. This function gets the current thread locale from Windows - without any encoding info - and returns it as a string of the above form for use in forming file names etc. The returned string should be deallocated with g_free().

Returns : newly-allocated locale name.

g_win32_get_package_installation_directory ()

gchar*      g_win32_get_package_installation_directory
                                            (gchar *package,
                                             gchar *dll_name);

Try to determine the installation directory for a software package. Typically used by GNU software packages.

package should be a short identifier for the package. Typically it is the same identifier as used for GETTEXT_PACKAGE in software configured according to GNU standards. The function first looks in the Windows Registry for the value #InstallationDirectory in the key #HKLM\Software\package, and if that value exists and is a string, returns that.

If package is NULL, or the above value isn't found in the Registry, but dll_name is non-NULL, it should name a DLL loaded into the current process. Typically that would be the name of the DLL calling this function, looking for its installation directory. The function then asks Windows what directory that DLL was loaded from. If that directory's last component is "bin" or "lib", the parent directory is returned, otherwise the directory itself. If that DLL isn't loaded, the function proceeds as if dll_name was NULL.

If both package and dll_name are NULL, the directory from where the main executable of the process was loaded is uses instead in the same way as above.

package : An identifier for a software package, or NULL
dll_name : The name of a DLL that a package provides, or NULL.
Returns : a string containing the installation directory for package. The return value should be freed with g_free() when not needed any longer.

g_win32_get_package_installation_subdirectory ()

gchar*      g_win32_get_package_installation_subdirectory
                                            (gchar *package,
                                             gchar *dll_name,
                                             gchar *subdir);

Returns a newly-allocated string containing the path of the subdirectory subdir in the return value from calling g_win32_get_package_installation_directory() with the package and dll_name parameters.

package : An identifier for a software package, or NULL.
dll_name : The name of a DLL that a package provides, or NULL.
subdir : A subdirectory of the package installation directory.
Returns : a string containing the complete path to subdir inside the installation directory of package. The return value should be freed with g_free() when no longer needed.

G_WIN32_DLLMAIN_FOR_DLL_NAME()

#define     G_WIN32_DLLMAIN_FOR_DLL_NAME(static, dll_name)

On Windows, this macro defines a DllMain() function that stores the actual DLL name that the code being compiled will be included in.

On non-Windows platforms, expands to nothing.

static :empty or "static".
dll_name :the name of the (pointer to the) char array where the DLL name will be stored. If this is used, you must also include windows.h. If you need a more complex DLL entry point function, you cannot use this.