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



commit bdf8f271f7dd7350126d18bd6fe49d888283b485
Author: Sébastien Wilmet <swilmet gnome org>
Date:   Sat Mar 26 18:13:43 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       |   14 +++++++++-----
 gspell/gspell-init.h       |   35 +++++++++++++++++++++++++++++++++++
 gspell/gspell-language.c   |   37 +++++--------------------------------
 5 files changed, 51 insertions(+), 37 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 0631cdb..6856663 100644
--- a/gspell/gspell-init.c
+++ b/gspell/gspell-init.c
@@ -24,16 +24,14 @@
  */
 
 #include "config.h"
+#include "gspell-init.h"
 #include <glib.h>
 #include <glib/gi18n-lib.h>
 #include "gconstructor.h"
 
 #ifdef G_OS_WIN32
-#define WIN32_LEAN_AND_MEAN
-#include <windows.h>
-
-HMODULE gspell_dll;
-#endif /* G_OS_WIN32 */
+static HMODULE gspell_dll;
+#endif
 
 #ifdef OS_OSX
 #include <Cocoa/Cocoa.h>
@@ -149,6 +147,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]