[gspell/wip/gspell-init2: 2/2] win32: have only one DllMain()



commit eb6127199ea8288c6fb68faf3b03851035f72731
Author: Sébastien Wilmet <swilmet gnome org>
Date:   Sat Mar 26 18:08:58 2016 +0100

    win32: have only one DllMain()
    
    To fix the build.
    
    Add a getter function to get the HMODULE.
    
    Reported by and initial patch by Ignacio Casal Quinteiro.

 docs/reference/Makefile.am |    1 +
 gspell/Makefile.am         |    1 +
 gspell/gspell-init.c       |    6 ++++++
 gspell/gspell-init.h       |   35 +++++++++++++++++++++++++++++++++++
 gspell/gspell-language.c   |   37 +++++--------------------------------
 5 files changed, 48 insertions(+), 32 deletions(-)
---
diff --git a/docs/reference/Makefile.am b/docs/reference/Makefile.am
index 2dfab5d..947ca7b 100644
--- a/docs/reference/Makefile.am
+++ b/docs/reference/Makefile.am
@@ -24,6 +24,7 @@ CFILE_GLOB = $(top_srcdir)/gspell/*.c
 # Header files or dirs to ignore when scanning. Use base file/dir names
 # e.g. IGNORE_HFILES=gtkdebug.h gtkintl.h private_code
 IGNORE_HFILES =                                        \
+       gspell-init.h                           \
        gspell-inline-checker-text-buffer.h     \
        gspell-osx.h                            \
        gspell-text-iter.h                      \
diff --git a/gspell/Makefile.am b/gspell/Makefile.am
index f025b4d..5752db7 100644
--- a/gspell/Makefile.am
+++ b/gspell/Makefile.am
@@ -43,6 +43,7 @@ gspell_public_c_files =                               \
 
 gspell_private_headers =                       \
        gconstructor.h                          \
+       gspell-init.h                           \
        gspell-inline-checker-text-buffer.h     \
        gspell-text-iter.h                      \
        gspell-text-region.h                    \
diff --git a/gspell/gspell-init.c b/gspell/gspell-init.c
index 4fdfa8b..ba97ee8 100644
--- a/gspell/gspell-init.c
+++ b/gspell/gspell-init.c
@@ -149,6 +149,12 @@ DllMain (HINSTANCE hinstDLL,
        return TRUE;
 }
 
+HMODULE
+_gspell_init_get_dll (void)
+{
+       return gspell_dll;
+}
+
 #elif defined (G_HAS_CONSTRUCTORS)
 
 #  ifdef G_DEFINE_CONSTRUCTOR_NEEDS_PRAGMA
diff --git a/gspell/gspell-init.h b/gspell/gspell-init.h
new file mode 100644
index 0000000..f387a79
--- /dev/null
+++ b/gspell/gspell-init.h
@@ -0,0 +1,35 @@
+/*
+ * This file is part of gspell, a spell-checking library.
+ *
+ * Copyright 2016 - Ignacio Casal Quinteiro <icq gnome org>
+ * Copyright 2016 - Sébastien Wilmet <swilmet gnome org>
+ *
+ * This library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; either
+ * version 2.1 of the License, or (at your option) any later version.
+ *
+ * This library is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public License
+ * along with this library; if not, see <http://www.gnu.org/licenses/>.
+ */
+
+#ifndef __GSPELL_INIT_H__
+#define __GSPELL_INIT_H__
+
+#ifdef G_OS_WIN32
+#define WIN32_LEAN_AND_MEAN
+#include <windows.h>
+
+G_GNUC_INTERNAL
+HMODULE _gspell_init_get_dll (void);
+
+#endif /* G_OS_WIN32 */
+
+#endif /* __GSPELL_INIT_H__ */
+
+/* ex:set ts=8 noet: */
diff --git a/gspell/gspell-language.c b/gspell/gspell-language.c
index 42ecc95..290eea3 100644
--- a/gspell/gspell-language.c
+++ b/gspell/gspell-language.c
@@ -24,6 +24,7 @@
 #include <string.h>
 #include <glib/gi18n-lib.h>
 #include <enchant.h>
+#include "gspell-init.h"
 
 #ifdef OS_OSX
 #include "gspell-osx.h"
@@ -62,44 +63,16 @@ G_DEFINE_BOXED_TYPE (GspellLanguage,
                     gspell_language_copy,
                     gspell_language_free)
 
-#ifdef G_OS_WIN32
-
-#ifdef DATADIR
-#undef DATADIR
-#endif
-
-#include <shlobj.h>
-static HMODULE hmodule;
-
-BOOL WINAPI
-DllMain (HINSTANCE hinstDLL,
-         DWORD     fdwReason,
-         LPVOID    lpvReserved);
-
-BOOL WINAPI
-DllMain (HINSTANCE hinstDLL,
-        DWORD     fdwReason,
-        LPVOID    lpvReserved)
-{
-       switch (fdwReason)
-       {
-               case DLL_PROCESS_ATTACH:
-                       hmodule = hinstDLL;
-                       break;
-       }
-
-       return TRUE;
-}
-
-#endif /* G_OS_WIN32 */
-
 static gchar *
 get_iso_codes_prefix (void)
 {
        gchar *prefix = NULL;
 
 #ifdef G_OS_WIN32
-       prefix = g_win32_get_package_installation_directory_of_module ((gpointer) hmodule);
+       HMODULE gspell_dll;
+
+       gspell_dll = _gspell_init_get_dll ();
+       prefix = g_win32_get_package_installation_directory_of_module ((gpointer) gspell_dll);
 #endif
 
        if (prefix == NULL)


[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]