📄 windows.sgml
字号:
<refentry id="glib-Windows-Compatability-Functions"><refmeta><refentrytitle>Windows Compatibility Functions</refentrytitle><manvolnum>3</manvolnum><refmiscinfo>GLIB Library</refmiscinfo></refmeta><refnamediv><refname>Windows Compatibility Functions</refname><refpurpose>UNIX emulation on Windows.</refpurpose></refnamediv><refsynopsisdiv><title>Synopsis</title><synopsis>#include <glib.h>#define <link linkend="MAXPATHLEN-CAPS">MAXPATHLEN</link>typedef <link linkend="pid-t">pid_t</link>;#define <link linkend="pipe">pipe</link> (phandles)#define <link linkend="ftruncate">ftruncate</link> (fd, size)<link linkend="gchar">gchar</link>* <link linkend="g-win32-error-message">g_win32_error_message</link> (<link linkend="gint">gint</link> error);<link linkend="gchar">gchar</link>* <link linkend="g-win32-getlocale">g_win32_getlocale</link> (void);<link linkend="gchar">gchar</link>* <link linkend="g-win32-get-package-installation-directory">g_win32_get_package_installation_directory</link> (<link linkend="gchar">gchar</link> *package, <link linkend="gchar">gchar</link> *dll_name);<link linkend="gchar">gchar</link>* <link linkend="g-win32-get-package-installation-subdirectory">g_win32_get_package_installation_subdirectory</link> (<link linkend="gchar">gchar</link> *package, <link linkend="gchar">gchar</link> *dll_name, <link linkend="gchar">gchar</link> *subdir);#define <link linkend="G-WIN32-DLLMAIN-FOR-DLL-NAME-CAPS">G_WIN32_DLLMAIN_FOR_DLL_NAME</link> (static, dll_name)</synopsis></refsynopsisdiv><refsect1><title>Description</title><para></para></refsect1><refsect1><title>Details</title><refsect2><title><anchor id="MAXPATHLEN-CAPS">MAXPATHLEN</title><programlisting>#define MAXPATHLEN 1024</programlisting><para>Provided for UNIX emulation on Windows; equivalent to UNIX macro <literal>MAXPATHLEN</literal>, which is the maximum length of a filename(including full path).</para></refsect2><refsect2><title><anchor id="pid-t">pid_t</title><programlisting>typedef int pid_t;</programlisting><para>Provided for UNIX emulation on Windows; process ID type.</para></refsect2><refsect2><title><anchor id="pipe">pipe()</title><programlisting>#define pipe(phandles) _pipe (phandles, 4096, _O_BINARY)</programlisting><para>Provided for UNIX emulation on Windows; see documentation for <function><link linkend="pipe">pipe</link>()</function>in any UNIX manual.</para><informaltable pgwide="1" frame="none" role="params"><tgroup cols="2"><colspec colwidth="2*"><colspec colwidth="8*"><tbody><row><entry align="right"><parameter>phandles</parameter> :</entry><entry></entry></row></tbody></tgroup></informaltable></refsect2><refsect2><title><anchor id="ftruncate">ftruncate()</title><programlisting># define ftruncate(fd, size) g_win32_ftruncate (fd, size)</programlisting><para>Provided for UNIX emulation on Windows; see documentation for <function><link linkend="ftruncate">ftruncate</link>()</function>in any UNIX manual.</para><informaltable pgwide="1" frame="none" role="params"><tgroup cols="2"><colspec colwidth="2*"><colspec colwidth="8*"><tbody><row><entry align="right"><parameter>fd</parameter> :</entry><entry></entry></row><row><entry align="right"><parameter>size</parameter> :</entry><entry></entry></row></tbody></tgroup></informaltable></refsect2><refsect2><title><anchor id="g-win32-error-message">g_win32_error_message ()</title><programlisting><link linkend="gchar">gchar</link>* g_win32_error_message (<link linkend="gint">gint</link> error);</programlisting><para>Translate a Win32 error code (as returned by <link linkend="GetLastError">GetLastError</link>()) intothe corresponding message. The message is either language neutral,or in the thread's language, or the user's language, the system'slanguage, or US English (see docs for <function><link linkend="FormatMessage">FormatMessage</link>()</function>). *The returned string should be deallocated with <link linkend="g-free">g_free</link>().</para><para></para><informaltable pgwide="1" frame="none" role="params"><tgroup cols="2"><colspec colwidth="2*"><colspec colwidth="8*"><tbody><row><entry align="right"><parameter>error</parameter> :</entry><entry> error code.</entry></row><row><entry align="right"><emphasis>Returns</emphasis> :</entry><entry> newly-allocated error message</entry></row></tbody></tgroup></informaltable></refsect2><refsect2><title><anchor id="g-win32-getlocale">g_win32_getlocale ()</title><programlisting><link linkend="gchar">gchar</link>* g_win32_getlocale (void);</programlisting><para>The setlocale in the Microsoft C library uses locale names of theform "English_United States.1252" etc. We want the UNIXish standardform "en_US", "zh_TW" etc. This function gets the current threadlocale from Windows - without any encoding info - and returns it asa string of the above form for use in forming file names etc. Thereturned string should be deallocated with <link linkend="g-free">g_free</link>().</para><para></para><informaltable pgwide="1" frame="none" role="params"><tgroup cols="2"><colspec colwidth="2*"><colspec colwidth="8*"><tbody><row><entry align="right"><emphasis>Returns</emphasis> :</entry><entry> newly-allocated locale name.</entry></row></tbody></tgroup></informaltable></refsect2><refsect2><title><anchor id="g-win32-get-package-installation-directory">g_win32_get_package_installation_directory ()</title><programlisting><link linkend="gchar">gchar</link>* g_win32_get_package_installation_directory (<link linkend="gchar">gchar</link> *package, <link linkend="gchar">gchar</link> *dll_name);</programlisting><para>Try to determine the installation directory for a software package.Typically used by GNU software packages.</para><para><parameter>package</parameter> should be a short identifier for the package. Typically itis the same identifier as used for<literal>GETTEXT_PACKAGE</literal> in software configured accordingto GNU standards. The function first looks in the Windows Registryfor the value <literal><link linkend="InstallationDirectory">InstallationDirectory</link></literal> in the key<literal><link linkend="HKLM-CAPS">HKLM</link>\Software\<parameter>package</parameter></literal>, and if that valueexists and is a string, returns that.</para><para>If <parameter>package</parameter> is <literal>NULL</literal>, or the above value isn't found in theRegistry, but <parameter>dll_name</parameter> is non-<literal>NULL</literal>, it should name a DLL loadedinto the current process. Typically that would be the name of theDLL calling this function, looking for its installationdirectory. The function then asks Windows what directory that DLLwas loaded from. If that directory's last component is "bin" or"lib", the parent directory is returned, otherwise the directoryitself. If that DLL isn't loaded, the function proceeds as if<parameter>dll_name</parameter> was <literal>NULL</literal>.</para><para>If both <parameter>package</parameter> and <parameter>dll_name</parameter> are <literal>NULL</literal>, the directory from wherethe main executable of the process was loaded is uses instead inthe same way as above.</para><para></para><informaltable pgwide="1" frame="none" role="params"><tgroup cols="2"><colspec colwidth="2*"><colspec colwidth="8*"><tbody><row><entry align="right"><parameter>package</parameter> :</entry><entry> An identifier for a software package, or <literal>NULL</literal></entry></row><row><entry align="right"><parameter>dll_name</parameter> :</entry><entry> The name of a DLL that a package provides, or <literal>NULL</literal>.</entry></row><row><entry align="right"><emphasis>Returns</emphasis> :</entry><entry> a string containing the installation directory for <parameter>package</parameter>.The return value should be freed with <link linkend="g-free">g_free</link>() when not needed any longer.</entry></row></tbody></tgroup></informaltable></refsect2><refsect2><title><anchor id="g-win32-get-package-installation-subdirectory">g_win32_get_package_installation_subdirectory ()</title><programlisting><link linkend="gchar">gchar</link>* g_win32_get_package_installation_subdirectory (<link linkend="gchar">gchar</link> *package, <link linkend="gchar">gchar</link> *dll_name, <link linkend="gchar">gchar</link> *subdir);</programlisting><para>Returns a newly-allocated string containing the path of thesubdirectory <parameter>subdir</parameter> in the return value from calling<link linkend="g-win32-get-package-installation-directory">g_win32_get_package_installation_directory</link>() with the <parameter>package</parameter> and<parameter>dll_name</parameter> parameters.</para><para></para><informaltable pgwide="1" frame="none" role="params"><tgroup cols="2"><colspec colwidth="2*"><colspec colwidth="8*"><tbody><row><entry align="right"><parameter>package</parameter> :</entry><entry> An identifier for a software package, or <literal>NULL</literal>.</entry></row><row><entry align="right"><parameter>dll_name</parameter> :</entry><entry> The name of a DLL that a package provides, or <literal>NULL</literal>.</entry></row><row><entry align="right"><parameter>subdir</parameter> :</entry><entry> A subdirectory of the package installation directory.</entry></row><row><entry align="right"><emphasis>Returns</emphasis> :</entry><entry> a string containing the complete path to <parameter>subdir</parameter> inside the installation directory of <parameter>package</parameter>. The return value should be freed with<link linkend="g-free">g_free</link>() when no longer needed.</entry></row></tbody></tgroup></informaltable></refsect2><refsect2><title><anchor id="G-WIN32-DLLMAIN-FOR-DLL-NAME-CAPS">G_WIN32_DLLMAIN_FOR_DLL_NAME()</title><programlisting>#define G_WIN32_DLLMAIN_FOR_DLL_NAME(static, dll_name)</programlisting><para>On Windows, this macro defines a <function><link linkend="DllMain">DllMain</link>()</function> function that stores the actual DLL name that the code being compiled will be included in.</para><para>On non-Windows platforms, expands to nothing.</para><informaltable pgwide="1" frame="none" role="params"><tgroup cols="2"><colspec colwidth="2*"><colspec colwidth="8*"><tbody><row><entry align="right"><parameter>static</parameter> :</entry><entry>empty or "static".</entry></row><row><entry align="right"><parameter>dll_name</parameter> :</entry><entry>the name of the (pointer to the) char array where the DLL name will be stored. If this is used, you must also include <filename>windows.h</filename>. If you need a more complex DLL entry point function, you cannot use this.</entry></row></tbody></tgroup></informaltable></refsect2></refsect1></refentry>
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -