1 /* GMODULE - GLIB wrapper code for dynamic module loading
2 * Copyright (C) 1998, 2000 Tim Janik
4 * Win32 GMODULE implementation
5 * Copyright (C) 1998 Tor Lillqvist
7 * This library is free software; you can redistribute it and/or
8 * modify it under the terms of the GNU Lesser General Public
9 * License as published by the Free Software Foundation; either
10 * version 2.1 of the License, or (at your option) any later version.
12 * This library is distributed in the hope that it will be useful,
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
15 * Lesser General Public License for more details.
17 * You should have received a copy of the GNU Lesser General Public
18 * License along with this library; if not, see <http://www.gnu.org/licenses/>.
22 * Modified by the GLib Team and others 1997-2000. See the AUTHORS
23 * file for a list of people on the GLib Team. See the ChangeLog
24 * files for a list of changes. These files are distributed with
25 * GLib at ftp://ftp.gtk.org/pub/gtk/.
39 #include <sys/cygwin.h>
43 set_error (const gchar
*format
,
51 error
= g_win32_error_message (GetLastError ());
53 va_start (args
, format
);
54 detail
= g_strdup_vprintf (format
, args
);
57 message
= g_strconcat (detail
, error
, NULL
);
59 g_module_set_error (message
);
65 /* --- functions --- */
67 _g_module_open (const gchar
*file_name
,
78 cygwin_conv_to_win32_path(file_name
, tmp
);
81 wfilename
= g_utf8_to_utf16 (file_name
, -1, NULL
, NULL
, NULL
);
83 /* suppress error dialog */
84 success
= SetThreadErrorMode (SEM_NOOPENFILEERRORBOX
| SEM_FAILCRITICALERRORS
, &old_mode
);
87 handle
= LoadLibraryW (wfilename
);
89 SetThreadErrorMode (old_mode
, NULL
);
93 set_error ("'%s': ", file_name
);
99 static gpointer null_module_handle
= &dummy
;
102 _g_module_self (void)
104 return null_module_handle
;
108 _g_module_close (gpointer handle
,
111 if (handle
!= null_module_handle
)
112 if (!FreeLibrary (handle
))
117 find_in_any_module_using_toolhelp (const gchar
*symbol_name
)
124 if ((snapshot
= CreateToolhelp32Snapshot (TH32CS_SNAPMODULE
, 0)) == (HANDLE
) -1)
127 me32
.dwSize
= sizeof (me32
);
129 if (Module32First (snapshot
, &me32
))
132 if ((p
= GetProcAddress (me32
.hModule
, symbol_name
)) != NULL
)
134 } while (Module32Next (snapshot
, &me32
));
137 CloseHandle (snapshot
);
143 find_in_any_module (const gchar
*symbol_name
)
147 if ((result
= find_in_any_module_using_toolhelp (symbol_name
)) == NULL
)
154 _g_module_symbol (gpointer handle
,
155 const gchar
*symbol_name
)
159 if (handle
== null_module_handle
)
161 if ((p
= GetProcAddress (GetModuleHandle (NULL
), symbol_name
)) == NULL
)
162 p
= find_in_any_module (symbol_name
);
165 p
= GetProcAddress (handle
, symbol_name
);
174 _g_module_build_path (const gchar
*directory
,
175 const gchar
*module_name
)
179 k
= strlen (module_name
);
181 if (directory
&& *directory
)
182 if (k
> 4 && g_ascii_strcasecmp (module_name
+ k
- 4, ".dll") == 0)
183 return g_strconcat (directory
, G_DIR_SEPARATOR_S
, module_name
, NULL
);
185 else if (strncmp (module_name
, "lib", 3) == 0 || strncmp (module_name
, "cyg", 3) == 0)
186 return g_strconcat (directory
, G_DIR_SEPARATOR_S
, module_name
, ".dll", NULL
);
188 return g_strconcat (directory
, G_DIR_SEPARATOR_S
, "cyg", module_name
, ".dll", NULL
);
190 else if (strncmp (module_name
, "lib", 3) == 0)
191 return g_strconcat (directory
, G_DIR_SEPARATOR_S
, module_name
, ".dll", NULL
);
193 return g_strconcat (directory
, G_DIR_SEPARATOR_S
, "lib", module_name
, ".dll", NULL
);
195 else if (k
> 4 && g_ascii_strcasecmp (module_name
+ k
- 4, ".dll") == 0)
196 return g_strdup (module_name
);
198 else if (strncmp (module_name
, "lib", 3) == 0 || strncmp (module_name
, "cyg", 3) == 0)
199 return g_strconcat (module_name
, ".dll", NULL
);
201 return g_strconcat ("cyg", module_name
, ".dll", NULL
);
203 else if (strncmp (module_name
, "lib", 3) == 0)
204 return g_strconcat (module_name
, ".dll", NULL
);
206 return g_strconcat ("lib", module_name
, ".dll", NULL
);