Merge pull request #3626 from lateralusX/jlorenss/win-api-family-support-eglib
authorJohan Lorensson <lateralusx.github@gmail.com>
Wed, 28 Sep 2016 06:40:30 +0000 (08:40 +0200)
committerGitHub <noreply@github.com>
Wed, 28 Sep 2016 06:40:30 +0000 (08:40 +0200)
Build eglib under none desktop Windows API family.

configure.ac
eglib/configure.ac
eglib/src/glib.h
eglib/src/gmisc-win32.c
eglib/src/gmodule-win32.c
eglib/src/gunicode.c
eglib/winconfig.h
winconfig.h

index 9a10f6d4917d3143ac993bd5f0f59e26fdd941cf..a169b26fdfddee11a89bbb685e31cf87893052c9 100644 (file)
@@ -345,6 +345,10 @@ if test x$target_win32 = xyes; then
    AC_DEFINE(TARGET_WIN32, 1, [Target Platform is Win32])
 fi
 
+# Defined for all targets/platforms using classic Windows API support.
+AC_DEFINE(HAVE_CLASSIC_WINAPI_SUPPORT, 1, [Use classic Windows API support])
+AC_DEFINE(HAVE_UWP_WINAPI_SUPPORT, 0, [Don't use UWP Windows API support])
+
 AC_SUBST(extra_runtime_ldflags)
 AM_CONDITIONAL(HOST_WIN32, test x$host_win32 = xyes)
 AM_CONDITIONAL(TARGET_WIN32, test x$target_win32 = xyes)
index a33dcb846b2746e4f47275e54c43280cfa982e1c..89f85d18e590434088b672fc593b3f2012052ead 100644 (file)
@@ -130,6 +130,10 @@ AM_CONDITIONAL(TARGET_WIN32, test x$OS = xWIN32)
 AM_CONDITIONAL(PLATFORM_DARWIN, test x$platform_darwin = xyes)
 AM_CONDITIONAL(PLATFORM_ANDROID, test x$platform_android = xyes)
 
+# Defined for all targets/platforms using classic Windows API support.
+AC_DEFINE(HAVE_CLASSIC_WINAPI_SUPPORT, 1, [Use classic Windows API support])
+AC_DEFINE(HAVE_UWP_WINAPI_SUPPORT, 0, [Don't use UWP Windows API support])
+
 AC_CHECK_SIZEOF(int)
 AC_CHECK_SIZEOF(void *)
 AC_CHECK_SIZEOF(long)
index d7173264c1b580ee1b65a47a21a7b8977f614005..1bc8506310edfa9ea570c94ccbed620266ead00c 100644 (file)
@@ -1068,6 +1068,10 @@ glong     g_utf8_pointer_to_offset (const gchar *str, const gchar *pos);
 #define _EGLIB_MINOR  0
  
 #define GLIB_CHECK_VERSION(a,b,c) ((a < _EGLIB_MAJOR) || (a == _EGLIB_MAJOR && (b < _EGLIB_MIDDLE || (b == _EGLIB_MIDDLE && c <= _EGLIB_MINOR))))
+
+#define G_HAVE_API_SUPPORT(x) (x)
+#define G_UNSUPPORTED_API "%s:%d: '%s' not supported.", __FILE__, __LINE__
+#define g_unsupported_api(name) G_STMT_START { g_warning (G_UNSUPPORTED_API, name); } G_STMT_END
  
 G_END_DECLS
 
index 5baec653c336451d8c9075dd76f69c233d4f9da3..f9fdb668f2d89d842c411e7af76d9d4a410ccfb9 100644 (file)
  * WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
  */
 
+#include <config.h>
+
 #include <stdlib.h>
 #include <glib.h>
 
 #include <windows.h>
-#ifdef _MSC_VER
+#if _MSC_VER && G_HAVE_API_SUPPORT(HAVE_CLASSIC_WINAPI_SUPPORT)
 #include <shlobj.h>
 #endif
 #include <direct.h>
 #include <io.h>
+#include <assert.h>
 
 const gchar *
 g_getenv(const gchar *variable)
@@ -87,6 +90,7 @@ g_unsetenv(const gchar *variable)
        g_free(var);
 }
 
+#if G_HAVE_API_SUPPORT(HAVE_CLASSIC_WINAPI_SUPPORT)
 gchar*
 g_win32_getlocale(void)
 {
@@ -98,6 +102,28 @@ g_win32_getlocale(void)
        return g_strdup (buf);
 }
 
+#else /* G_HAVE_API_SUPPORT(HAVE_CLASSIC_WINAPI_SUPPORT) */
+
+gchar*
+g_win32_getlocale(void)
+{
+       gunichar2 buf[19];
+       gint ccBuf = GetLocaleInfoEx (LOCALE_NAME_USER_DEFAULT, LOCALE_SISO639LANGNAME, buf, 9);
+       assert (ccBuf <= 9);
+       if (ccBuf != 0) {
+               buf[ccBuf - 1] = L'-';
+               ccBuf = GetLocaleInfoEx (LOCALE_NAME_USER_DEFAULT, LOCALE_SISO3166CTRYNAME, buf + ccBuf, 9);
+               assert (ccBuf <= 9);
+       }
+
+       // Check for GetLocaleInfoEx failure.
+       if (ccBuf == 0)
+               buf[0] = L'\0';
+
+       return u16to8 (buf);
+}
+#endif /* G_HAVE_API_SUPPORT(HAVE_CLASSIC_WINAPI_SUPPORT) */
+
 gboolean
 g_path_is_absolute (const char *filename)
 {
@@ -121,7 +147,7 @@ g_get_home_dir (void)
 {
        gchar *home_dir = NULL;
 
-#ifdef _MSC_VER
+#if _MSC_VER && G_HAVE_API_SUPPORT(HAVE_CLASSIC_WINAPI_SUPPORT)
        PWSTR profile_path = NULL;
        HRESULT hr = SHGetKnownFolderPath (&FOLDERID_Profile, KF_FLAG_DEFAULT, NULL, &profile_path);
        if (SUCCEEDED(hr)) {
@@ -180,4 +206,3 @@ g_get_tmp_dir (void)
        }
        return tmp_dir;
 }
-
index 24010b58915e367699e1581e9431eeefbfff310c..d1dca5303eb7d174fa98c154a35901844105dd5b 100644 (file)
@@ -28,6 +28,7 @@
  * OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
  * WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
  */
+#include <config.h>
 #include <glib.h>
 #include <gmodule.h>
 #include <windows.h>
@@ -68,6 +69,7 @@ g_module_open (const gchar *file, GModuleFlags flags)
        return module;
 }
 
+#if G_HAVE_API_SUPPORT(HAVE_CLASSIC_WINAPI_SUPPORT)
 static gpointer
 w32_find_symbol (const gchar *symbol_name)
 {
@@ -115,6 +117,17 @@ w32_find_symbol (const gchar *symbol_name)
        return NULL;
 }
 
+#else /* G_HAVE_API_SUPPORT(HAVE_CLASSIC_WINAPI_SUPPORT) */
+
+static gpointer
+w32_find_symbol (const gchar *symbol_name)
+{
+       g_unsupported_api ("EnumProcessModules");
+       SetLastError (ERROR_NOT_SUPPORTED);
+       return NULL;
+}
+#endif /* G_HAVE_API_SUPPORT(HAVE_CLASSIC_WINAPI_SUPPORT) */
+
 gboolean
 g_module_symbol (GModule *module, const gchar *symbol_name, gpointer *symbol)
 {
@@ -134,6 +147,7 @@ g_module_symbol (GModule *module, const gchar *symbol_name, gpointer *symbol)
        }
 }
 
+#if G_HAVE_API_SUPPORT(HAVE_CLASSIC_WINAPI_SUPPORT)
 const gchar *
 g_module_error (void)
 {
@@ -151,6 +165,35 @@ g_module_error (void)
        return ret;
 }
 
+#elif G_HAVE_API_SUPPORT(HAVE_UWP_WINAPI_SUPPORT)   /* G_HAVE_API_SUPPORT(HAVE_CLASSIC_WINAPI_SUPPORT) */
+
+const gchar *
+g_module_error (void)
+{
+       gchar* ret = NULL;
+       TCHAR buf[1024];
+       DWORD code = GetLastError ();
+
+       if (!FormatMessage (FORMAT_MESSAGE_FROM_SYSTEM | FORMAT_MESSAGE_IGNORE_INSERTS, NULL,
+               code, MAKELANGID(LANG_NEUTRAL, SUBLANG_DEFAULT), buf, G_N_ELEMENTS(buf) - 1, NULL) )
+               buf[0] = TEXT('\0');
+
+       ret = u16to8 (buf);
+       return ret;
+}
+
+#else
+
+const gchar *
+g_module_error (void)
+{
+       g_unsupported_api ("FormatMessage");
+       SetLastError (ERROR_NOT_SUPPORTED);
+       return NULL;
+}
+
+#endif /* G_HAVE_API_SUPPORT(HAVE_CLASSIC_WINAPI_SUPPORT) */
+
 gboolean
 g_module_close (GModule *module)
 {
index 36d6d4acfb76ad52a1bca0da47bbcd6def49b9cd..f979f429ff7d4306c3b4a826c2c45712d2f37af4 100644 (file)
@@ -205,16 +205,36 @@ g_filename_from_utf8 (const gchar *utf8string, gssize len, gsize *bytes_read, gs
        return res;
 }
 
+#ifdef G_OS_WIN32
+extern WINBASEAPI UINT WINAPI GetACP(void);
 gboolean
 g_get_charset (G_CONST_RETURN char **charset)
 {
        if (my_charset == NULL) {
-#ifdef G_OS_WIN32
                static char buf [14];
+#if G_HAVE_API_SUPPORT(HAVE_UWP_WINAPI_SUPPORT)
+               CPINFOEXA cp_info;
+               GetCPInfoExA (CP_ACP, 0, &cp_info);
+               sprintf (buf, "CP%u", cp_info.CodePage);
+#else
                sprintf (buf, "CP%u", GetACP ());
+#endif
                my_charset = buf;
                is_utf8 = FALSE;
-#else
+       }
+       
+       if (charset != NULL)
+               *charset = my_charset;
+
+       return is_utf8;
+}
+
+#else /* G_OS_WIN32 */
+
+gboolean
+g_get_charset (G_CONST_RETURN char **charset)
+{
+       if (my_charset == NULL) {
                /* These shouldn't be heap allocated */
 #if defined(HAVE_LOCALCHARSET_H)
                my_charset = locale_charset ();
@@ -222,7 +242,6 @@ g_get_charset (G_CONST_RETURN char **charset)
                my_charset = "UTF-8";
 #endif
                is_utf8 = strcmp (my_charset, "UTF-8") == 0;
-#endif
        }
        
        if (charset != NULL)
@@ -230,6 +249,7 @@ g_get_charset (G_CONST_RETURN char **charset)
 
        return is_utf8;
 }
+#endif /* G_OS_WIN32 */
 
 gchar *
 g_locale_to_utf8 (const gchar *opsysstring, gssize len, gsize *bytes_read, gsize *bytes_written, GError **error)
index 04e8d4075ce134087eb22387b8b0da242f4ab482..3a64e217ef0c7a82c260e789a8ece0c13d41cc5d 100755 (executable)
 #define VERSION "0.1"
 
 #define HAVE_STRTOK_R 1
+
+#ifndef HAVE_WINAPI_FAMILY_SUPPORT
+
+#define HAVE_WINAPI_FAMILY_SUPPORT
+
+/* WIN API Family support */
+#include <winapifamily.h>
+
+#if WINAPI_FAMILY_PARTITION(WINAPI_PARTITION_DESKTOP)
+       #define HAVE_CLASSIC_WINAPI_SUPPORT 1
+       #define HAVE_UWP_WINAPI_SUPPORT 0
+#elif WINAPI_FAMILY_PARTITION(WINAPI_PARTITION_APP)
+       #define HAVE_CLASSIC_WINAPI_SUPPORT 0
+       #define HAVE_UWP_WINAPI_SUPPORT 1
+#else
+       #define HAVE_CLASSIC_WINAPI_SUPPORT 0
+       #define HAVE_UWP_WINAPI_SUPPORT 0
+#endif
+
+#endif
 #endif
index a6daf8b05286c8b10b8dabe416649fee9906b609..d15685302eb4ca05c6a649ecba90f9911b7e6131 100644 (file)
 
 /* Version number of package */
 #define VERSION "#MONO_VERSION#"
+
+#ifndef HAVE_WINAPI_FAMILY_SUPPORT
+
+#define HAVE_WINAPI_FAMILY_SUPPORT
+
+/* WIN API Family support */
+#include <winapifamily.h>
+
+#if WINAPI_FAMILY_PARTITION(WINAPI_PARTITION_DESKTOP)
+       #define HAVE_CLASSIC_WINAPI_SUPPORT 1
+       #define HAVE_UWP_WINAPI_SUPPORT 0
+#elif WINAPI_FAMILY_PARTITION(WINAPI_PARTITION_APP)
+       #define HAVE_CLASSIC_WINAPI_SUPPORT 0
+       #define HAVE_UWP_WINAPI_SUPPORT 1
+#else
+       #define HAVE_CLASSIC_WINAPI_SUPPORT 0
+       #define HAVE_UWP_WINAPI_SUPPORT 0
+#endif
+
+#endif
 #endif