[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
do not use GetModuleHandle when built for Windows Store apps
From: |
Bruno Haible |
Subject: |
do not use GetModuleHandle when built for Windows Store apps |
Date: |
Fri, 29 May 2020 22:29:19 +0200 |
User-agent: |
KMail/5.1.3 (Linux/4.4.0-177-generic; KDE/5.18.0; x86_64; ; ) |
GetModuleHandle is like LoadLibrary: it is used for dynamic lookup of
Windows API functions. And Windows Store apps can't use it.
This patch fixes some of the issues. The other ones, in poll.c and select.c,
are harder to fix, because it's not easy to link directly against ntdll.dll [1].
[1]
https://stackoverflow.com/questions/35509388/link-to-ntdll-lib-and-call-functions-inside-ntdll-dll
2020-05-29 Bruno Haible <bruno@clisp.org>
Avoid dynamic lookup of Windows API functions when possible.
* lib/getaddrinfo.c (GetProcAddress, getaddrinfo_func,
freeaddrinfo_func, getnameinfo_func, getaddrinfo_ptr, freeaddrinfo_ptr,
getnameinfo_ptr): Don't define in a build for Windows XP or higher.
(use_win32_p): Define differently.
* lib/link.c (GetProcAddress, CreateHardLinkFuncType,
CreateHardLinkFunc, initialized, initialize): Don't define in a build
for Windows XP or higher.
diff --git a/lib/getaddrinfo.c b/lib/getaddrinfo.c
index 99cb709..1db9be8 100644
--- a/lib/getaddrinfo.c
+++ b/lib/getaddrinfo.c
@@ -86,9 +86,11 @@ freeaddrinfo (struct addrinfo *ai)
# ifdef WINDOWS_NATIVE
+# if !(_WIN32_WINNT >= _WIN32_WINNT_WINXP)
+
/* Avoid warnings from gcc -Wcast-function-type. */
-# define GetProcAddress \
- (void *) GetProcAddress
+# define GetProcAddress \
+ (void *) GetProcAddress
typedef int (WSAAPI *getaddrinfo_func) (const char*, const char*,
const struct addrinfo*,
@@ -135,6 +137,29 @@ use_win32_p (void)
return 1;
}
+
+# else
+
+static int
+use_win32_p (void)
+{
+ static int done = 0;
+
+ if (!done)
+ {
+ done = 1;
+
+ gl_sockets_startup (SOCKETS_1_1);
+ }
+
+ return 1;
+}
+
+# define getaddrinfo_ptr getaddrinfo
+# define freeaddrinfo_ptr freeaddrinfo
+# define getnameinfo_ptr getnameinfo
+
+# endif
# endif
static bool
@@ -161,6 +186,7 @@ getaddrinfo (const char *restrict nodename,
const char *restrict servname,
const struct addrinfo *restrict hints,
struct addrinfo **restrict res)
+#undef getaddrinfo
{
struct addrinfo *tmp;
int port = 0;
@@ -362,6 +388,7 @@ getaddrinfo (const char *restrict nodename,
/* Free 'addrinfo' structure AI including associated storage. */
void
freeaddrinfo (struct addrinfo *ai)
+#undef freeaddrinfo
{
# ifdef WINDOWS_NATIVE
if (use_win32_p ())
@@ -388,6 +415,7 @@ getnameinfo (const struct sockaddr *restrict sa, socklen_t
salen,
char *restrict node, socklen_t nodelen,
char *restrict service, socklen_t servicelen,
int flags)
+#undef getnameinfo
{
# ifdef WINDOWS_NATIVE
if (use_win32_p ())
diff --git a/lib/link.c b/lib/link.c
index 8e079d2..8680e3e 100644
--- a/lib/link.c
+++ b/lib/link.c
@@ -30,9 +30,11 @@
# define WIN32_LEAN_AND_MEAN
# include <windows.h>
+# if !(_WIN32_WINNT >= _WIN32_WINNT_WINXP)
+
/* Avoid warnings from gcc -Wcast-function-type. */
-# define GetProcAddress \
- (void *) GetProcAddress
+# define GetProcAddress \
+ (void *) GetProcAddress
/* CreateHardLink was introduced only in Windows 2000. */
typedef BOOL (WINAPI * CreateHardLinkFuncType) (LPCSTR lpFileName,
@@ -53,14 +55,24 @@ initialize (void)
initialized = TRUE;
}
+# else
+
+# define CreateHardLinkFunc CreateHardLink
+
+# endif
+
int
link (const char *file1, const char *file2)
{
char *dir;
size_t len1 = strlen (file1);
size_t len2 = strlen (file2);
+
+# if !(_WIN32_WINNT >= _WIN32_WINNT_WINXP)
if (!initialized)
initialize ();
+# endif
+
if (CreateHardLinkFunc == NULL)
{
/* System does not support hard links. */