aboutsummaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
authorAndy Moreton2018-08-14 13:59:08 +0100
committerEli Zaretskii2018-08-17 17:29:10 +0300
commitcc5325b0bea13bd93478fcee0b035877b3a72290 (patch)
treeac22ceea567bc70e836b61ade04de644473267cb /src
parent58e5f10f884f70faea2dc577e890ccc9e8c5d0f5 (diff)
downloademacs-cc5325b0bea13bd93478fcee0b035877b3a72290.tar.gz
emacs-cc5325b0bea13bd93478fcee0b035877b3a72290.zip
Pacify -Wcast-function-type warnings in GCC 8.1
* src/image.c: Move attributes into DEF_DLL_FN call. * src/dynlib.c (dynlib_addr): Use get_proc_addr. * src/w32.h: (get_proc_addr): New function. (LOAD_DLL_FN): Use it. (DEF_DLL_FN): Allow function attributes after argument list. Add function pointer type used by LOAD_DLL_FN. * src/w32.c (open_process_token, get_token_information) (lookup_account_sid, get_sid_sub_authority) (get_sid_sub_authority_count, get_security_info) (get_file_security, set_file_security) (set_named_security_info) (get_security_descriptor_owner, get_security_descriptor_group) (get_security_descriptor_dacl, is_valid_sid, equal_sid) (get_length_sid, copy_sid, get_native_system_info) (get_system_times, create_symbolic_link) (is_valid_security_descriptor, convert_sd_to_sddl) (convert_sddl_to_sd, get_adapters_info, reg_open_key_ex_w) (reg_query_value_ex_w, expand_environment_strings_w) (init_environment, create_toolhelp32_snapshot) (process32_first, process32_next, open_thread_token) (impersonate_self, revert_to_self, get_process_memory_info) (get_process_working_set_size, global_memory_status) (global_memory_status_ex, init_winsock) (maybe_load_unicows_dll, globals_of_w32): Use get_proc_addr. * src/w32fns.c (setup_w32_kbdhook, Ffile_system_info) (get_dll_version, w32_reset_stack_overflow_guard) (w32_backtrace, globals_of_w32fns): Use get_proc_addr. * src/w32font.c (get_outline_metrics_w, get_text_metrics_w) (get_glyph_outline_w, get_char_width_32_w): Use get_proc_addr. * src/w32heap.c (init_heap): Use get_proc_addr. * src/w32menu.c (globals_of_w32menu): Use get_proc_addr. * src/w32proc.c (init_timers, sys_kill, w32_compare_strings): Use get_proc_addr. * src/w32uniscribe.c (syms_of_w32uniscribe): Use get_proc_addr.
Diffstat (limited to 'src')
-rw-r--r--src/dynlib.c5
-rw-r--r--src/image.c2
-rw-r--r--src/w32.c211
-rw-r--r--src/w32.h26
-rw-r--r--src/w32fns.c42
-rw-r--r--src/w32font.c8
-rw-r--r--src/w32heap.c6
-rw-r--r--src/w32menu.c12
-rw-r--r--src/w32proc.c15
-rw-r--r--src/w32uniscribe.c6
10 files changed, 172 insertions, 161 deletions
diff --git a/src/dynlib.c b/src/dynlib.c
index 53afdafa2dc..d40aa67f416 100644
--- a/src/dynlib.c
+++ b/src/dynlib.c
@@ -156,9 +156,8 @@ dynlib_addr (void *addr, const char **fname, const char **symname)
156 address we pass to it is not an address of a string, but 156 address we pass to it is not an address of a string, but
157 an address of a function. So we don't care about the 157 an address of a function. So we don't care about the
158 Unicode version. */ 158 Unicode version. */
159 s_pfn_Get_Module_HandleExA = 159 s_pfn_Get_Module_HandleExA = (GetModuleHandleExA_Proc)
160 (GetModuleHandleExA_Proc) GetProcAddress (hm_kernel32, 160 get_proc_addr (hm_kernel32, "GetModuleHandleExA");
161 "GetModuleHandleExA");
162 } 161 }
163 if (s_pfn_Get_Module_HandleExA) 162 if (s_pfn_Get_Module_HandleExA)
164 { 163 {
diff --git a/src/image.c b/src/image.c
index 499c1b6aed8..7866b9cc463 100644
--- a/src/image.c
+++ b/src/image.c
@@ -5734,7 +5734,7 @@ DEF_DLL_FN (void, png_read_end, (png_structp, png_infop));
5734DEF_DLL_FN (void, png_error, (png_structp, png_const_charp)); 5734DEF_DLL_FN (void, png_error, (png_structp, png_const_charp));
5735 5735
5736# if (PNG_LIBPNG_VER >= 10500) 5736# if (PNG_LIBPNG_VER >= 10500)
5737DEF_DLL_FN (void, png_longjmp, (png_structp, int)) PNG_NORETURN; 5737DEF_DLL_FN (void, png_longjmp, (png_structp, int) PNG_NORETURN);
5738DEF_DLL_FN (jmp_buf *, png_set_longjmp_fn, 5738DEF_DLL_FN (jmp_buf *, png_set_longjmp_fn,
5739 (png_structp, png_longjmp_ptr, size_t)); 5739 (png_structp, png_longjmp_ptr, size_t));
5740# endif /* libpng version >= 1.5 */ 5740# endif /* libpng version >= 1.5 */
diff --git a/src/w32.c b/src/w32.c
index ef6047580e6..78f946c6341 100644
--- a/src/w32.c
+++ b/src/w32.c
@@ -576,8 +576,8 @@ open_process_token (HANDLE ProcessHandle,
576 { 576 {
577 g_b_init_open_process_token = 1; 577 g_b_init_open_process_token = 1;
578 hm_advapi32 = LoadLibrary ("Advapi32.dll"); 578 hm_advapi32 = LoadLibrary ("Advapi32.dll");
579 s_pfn_Open_Process_Token = 579 s_pfn_Open_Process_Token = (OpenProcessToken_Proc)
580 (OpenProcessToken_Proc) GetProcAddress (hm_advapi32, "OpenProcessToken"); 580 get_proc_addr (hm_advapi32, "OpenProcessToken");
581 } 581 }
582 if (s_pfn_Open_Process_Token == NULL) 582 if (s_pfn_Open_Process_Token == NULL)
583 { 583 {
@@ -608,8 +608,8 @@ get_token_information (HANDLE TokenHandle,
608 { 608 {
609 g_b_init_get_token_information = 1; 609 g_b_init_get_token_information = 1;
610 hm_advapi32 = LoadLibrary ("Advapi32.dll"); 610 hm_advapi32 = LoadLibrary ("Advapi32.dll");
611 s_pfn_Get_Token_Information = 611 s_pfn_Get_Token_Information = (GetTokenInformation_Proc)
612 (GetTokenInformation_Proc) GetProcAddress (hm_advapi32, "GetTokenInformation"); 612 get_proc_addr (hm_advapi32, "GetTokenInformation");
613 } 613 }
614 if (s_pfn_Get_Token_Information == NULL) 614 if (s_pfn_Get_Token_Information == NULL)
615 { 615 {
@@ -644,8 +644,8 @@ lookup_account_sid (LPCTSTR lpSystemName,
644 { 644 {
645 g_b_init_lookup_account_sid = 1; 645 g_b_init_lookup_account_sid = 1;
646 hm_advapi32 = LoadLibrary ("Advapi32.dll"); 646 hm_advapi32 = LoadLibrary ("Advapi32.dll");
647 s_pfn_Lookup_Account_Sid = 647 s_pfn_Lookup_Account_Sid = (LookupAccountSid_Proc)
648 (LookupAccountSid_Proc) GetProcAddress (hm_advapi32, LookupAccountSid_Name); 648 get_proc_addr (hm_advapi32, LookupAccountSid_Name);
649 } 649 }
650 if (s_pfn_Lookup_Account_Sid == NULL) 650 if (s_pfn_Lookup_Account_Sid == NULL)
651 { 651 {
@@ -677,9 +677,8 @@ get_sid_sub_authority (PSID pSid, DWORD n)
677 { 677 {
678 g_b_init_get_sid_sub_authority = 1; 678 g_b_init_get_sid_sub_authority = 1;
679 hm_advapi32 = LoadLibrary ("Advapi32.dll"); 679 hm_advapi32 = LoadLibrary ("Advapi32.dll");
680 s_pfn_Get_Sid_Sub_Authority = 680 s_pfn_Get_Sid_Sub_Authority = (GetSidSubAuthority_Proc)
681 (GetSidSubAuthority_Proc) GetProcAddress ( 681 get_proc_addr (hm_advapi32, "GetSidSubAuthority");
682 hm_advapi32, "GetSidSubAuthority");
683 } 682 }
684 if (s_pfn_Get_Sid_Sub_Authority == NULL) 683 if (s_pfn_Get_Sid_Sub_Authority == NULL)
685 { 684 {
@@ -702,9 +701,8 @@ get_sid_sub_authority_count (PSID pSid)
702 { 701 {
703 g_b_init_get_sid_sub_authority_count = 1; 702 g_b_init_get_sid_sub_authority_count = 1;
704 hm_advapi32 = LoadLibrary ("Advapi32.dll"); 703 hm_advapi32 = LoadLibrary ("Advapi32.dll");
705 s_pfn_Get_Sid_Sub_Authority_Count = 704 s_pfn_Get_Sid_Sub_Authority_Count = (GetSidSubAuthorityCount_Proc)
706 (GetSidSubAuthorityCount_Proc) GetProcAddress ( 705 get_proc_addr (hm_advapi32, "GetSidSubAuthorityCount");
707 hm_advapi32, "GetSidSubAuthorityCount");
708 } 706 }
709 if (s_pfn_Get_Sid_Sub_Authority_Count == NULL) 707 if (s_pfn_Get_Sid_Sub_Authority_Count == NULL)
710 { 708 {
@@ -733,9 +731,8 @@ get_security_info (HANDLE handle,
733 { 731 {
734 g_b_init_get_security_info = 1; 732 g_b_init_get_security_info = 1;
735 hm_advapi32 = LoadLibrary ("Advapi32.dll"); 733 hm_advapi32 = LoadLibrary ("Advapi32.dll");
736 s_pfn_Get_Security_Info = 734 s_pfn_Get_Security_Info = (GetSecurityInfo_Proc)
737 (GetSecurityInfo_Proc) GetProcAddress ( 735 get_proc_addr (hm_advapi32, "GetSecurityInfo");
738 hm_advapi32, "GetSecurityInfo");
739 } 736 }
740 if (s_pfn_Get_Security_Info == NULL) 737 if (s_pfn_Get_Security_Info == NULL)
741 { 738 {
@@ -769,9 +766,8 @@ get_file_security (const char *lpFileName,
769 { 766 {
770 g_b_init_get_file_security_w = 1; 767 g_b_init_get_file_security_w = 1;
771 hm_advapi32 = LoadLibrary ("Advapi32.dll"); 768 hm_advapi32 = LoadLibrary ("Advapi32.dll");
772 s_pfn_Get_File_SecurityW = 769 s_pfn_Get_File_SecurityW = (GetFileSecurityW_Proc)
773 (GetFileSecurityW_Proc) GetProcAddress (hm_advapi32, 770 get_proc_addr (hm_advapi32, "GetFileSecurityW");
774 "GetFileSecurityW");
775 } 771 }
776 if (s_pfn_Get_File_SecurityW == NULL) 772 if (s_pfn_Get_File_SecurityW == NULL)
777 { 773 {
@@ -791,9 +787,8 @@ get_file_security (const char *lpFileName,
791 { 787 {
792 g_b_init_get_file_security_a = 1; 788 g_b_init_get_file_security_a = 1;
793 hm_advapi32 = LoadLibrary ("Advapi32.dll"); 789 hm_advapi32 = LoadLibrary ("Advapi32.dll");
794 s_pfn_Get_File_SecurityA = 790 s_pfn_Get_File_SecurityA = (GetFileSecurityA_Proc)
795 (GetFileSecurityA_Proc) GetProcAddress (hm_advapi32, 791 get_proc_addr (hm_advapi32, "GetFileSecurityA");
796 "GetFileSecurityA");
797 } 792 }
798 if (s_pfn_Get_File_SecurityA == NULL) 793 if (s_pfn_Get_File_SecurityA == NULL)
799 { 794 {
@@ -828,9 +823,8 @@ set_file_security (const char *lpFileName,
828 { 823 {
829 g_b_init_set_file_security_w = 1; 824 g_b_init_set_file_security_w = 1;
830 hm_advapi32 = LoadLibrary ("Advapi32.dll"); 825 hm_advapi32 = LoadLibrary ("Advapi32.dll");
831 s_pfn_Set_File_SecurityW = 826 s_pfn_Set_File_SecurityW = (SetFileSecurityW_Proc)
832 (SetFileSecurityW_Proc) GetProcAddress (hm_advapi32, 827 get_proc_addr (hm_advapi32, "SetFileSecurityW");
833 "SetFileSecurityW");
834 } 828 }
835 if (s_pfn_Set_File_SecurityW == NULL) 829 if (s_pfn_Set_File_SecurityW == NULL)
836 { 830 {
@@ -849,9 +843,8 @@ set_file_security (const char *lpFileName,
849 { 843 {
850 g_b_init_set_file_security_a = 1; 844 g_b_init_set_file_security_a = 1;
851 hm_advapi32 = LoadLibrary ("Advapi32.dll"); 845 hm_advapi32 = LoadLibrary ("Advapi32.dll");
852 s_pfn_Set_File_SecurityA = 846 s_pfn_Set_File_SecurityA = (SetFileSecurityA_Proc)
853 (SetFileSecurityA_Proc) GetProcAddress (hm_advapi32, 847 get_proc_addr (hm_advapi32, "SetFileSecurityA");
854 "SetFileSecurityA");
855 } 848 }
856 if (s_pfn_Set_File_SecurityA == NULL) 849 if (s_pfn_Set_File_SecurityA == NULL)
857 { 850 {
@@ -889,9 +882,8 @@ set_named_security_info (LPCTSTR lpObjectName,
889 { 882 {
890 g_b_init_set_named_security_info_w = 1; 883 g_b_init_set_named_security_info_w = 1;
891 hm_advapi32 = LoadLibrary ("Advapi32.dll"); 884 hm_advapi32 = LoadLibrary ("Advapi32.dll");
892 s_pfn_Set_Named_Security_InfoW = 885 s_pfn_Set_Named_Security_InfoW = (SetNamedSecurityInfoW_Proc)
893 (SetNamedSecurityInfoW_Proc) GetProcAddress (hm_advapi32, 886 get_proc_addr (hm_advapi32, "SetNamedSecurityInfoW");
894 "SetNamedSecurityInfoW");
895 } 887 }
896 if (s_pfn_Set_Named_Security_InfoW == NULL) 888 if (s_pfn_Set_Named_Security_InfoW == NULL)
897 { 889 {
@@ -911,9 +903,8 @@ set_named_security_info (LPCTSTR lpObjectName,
911 { 903 {
912 g_b_init_set_named_security_info_a = 1; 904 g_b_init_set_named_security_info_a = 1;
913 hm_advapi32 = LoadLibrary ("Advapi32.dll"); 905 hm_advapi32 = LoadLibrary ("Advapi32.dll");
914 s_pfn_Set_Named_Security_InfoA = 906 s_pfn_Set_Named_Security_InfoA = (SetNamedSecurityInfoA_Proc)
915 (SetNamedSecurityInfoA_Proc) GetProcAddress (hm_advapi32, 907 get_proc_addr (hm_advapi32, "SetNamedSecurityInfoA");
916 "SetNamedSecurityInfoA");
917 } 908 }
918 if (s_pfn_Set_Named_Security_InfoA == NULL) 909 if (s_pfn_Set_Named_Security_InfoA == NULL)
919 { 910 {
@@ -943,9 +934,8 @@ get_security_descriptor_owner (PSECURITY_DESCRIPTOR pSecurityDescriptor,
943 { 934 {
944 g_b_init_get_security_descriptor_owner = 1; 935 g_b_init_get_security_descriptor_owner = 1;
945 hm_advapi32 = LoadLibrary ("Advapi32.dll"); 936 hm_advapi32 = LoadLibrary ("Advapi32.dll");
946 s_pfn_Get_Security_Descriptor_Owner = 937 s_pfn_Get_Security_Descriptor_Owner = (GetSecurityDescriptorOwner_Proc)
947 (GetSecurityDescriptorOwner_Proc) GetProcAddress ( 938 get_proc_addr (hm_advapi32, "GetSecurityDescriptorOwner");
948 hm_advapi32, "GetSecurityDescriptorOwner");
949 } 939 }
950 if (s_pfn_Get_Security_Descriptor_Owner == NULL) 940 if (s_pfn_Get_Security_Descriptor_Owner == NULL)
951 { 941 {
@@ -972,9 +962,8 @@ get_security_descriptor_group (PSECURITY_DESCRIPTOR pSecurityDescriptor,
972 { 962 {
973 g_b_init_get_security_descriptor_group = 1; 963 g_b_init_get_security_descriptor_group = 1;
974 hm_advapi32 = LoadLibrary ("Advapi32.dll"); 964 hm_advapi32 = LoadLibrary ("Advapi32.dll");
975 s_pfn_Get_Security_Descriptor_Group = 965 s_pfn_Get_Security_Descriptor_Group = (GetSecurityDescriptorGroup_Proc)
976 (GetSecurityDescriptorGroup_Proc) GetProcAddress ( 966 get_proc_addr (hm_advapi32, "GetSecurityDescriptorGroup");
977 hm_advapi32, "GetSecurityDescriptorGroup");
978 } 967 }
979 if (s_pfn_Get_Security_Descriptor_Group == NULL) 968 if (s_pfn_Get_Security_Descriptor_Group == NULL)
980 { 969 {
@@ -1002,9 +991,8 @@ get_security_descriptor_dacl (PSECURITY_DESCRIPTOR pSecurityDescriptor,
1002 { 991 {
1003 g_b_init_get_security_descriptor_dacl = 1; 992 g_b_init_get_security_descriptor_dacl = 1;
1004 hm_advapi32 = LoadLibrary ("Advapi32.dll"); 993 hm_advapi32 = LoadLibrary ("Advapi32.dll");
1005 s_pfn_Get_Security_Descriptor_Dacl = 994 s_pfn_Get_Security_Descriptor_Dacl = (GetSecurityDescriptorDacl_Proc)
1006 (GetSecurityDescriptorDacl_Proc) GetProcAddress ( 995 get_proc_addr (hm_advapi32, "GetSecurityDescriptorDacl");
1007 hm_advapi32, "GetSecurityDescriptorDacl");
1008 } 996 }
1009 if (s_pfn_Get_Security_Descriptor_Dacl == NULL) 997 if (s_pfn_Get_Security_Descriptor_Dacl == NULL)
1010 { 998 {
@@ -1029,9 +1017,8 @@ is_valid_sid (PSID sid)
1029 { 1017 {
1030 g_b_init_is_valid_sid = 1; 1018 g_b_init_is_valid_sid = 1;
1031 hm_advapi32 = LoadLibrary ("Advapi32.dll"); 1019 hm_advapi32 = LoadLibrary ("Advapi32.dll");
1032 s_pfn_Is_Valid_Sid = 1020 s_pfn_Is_Valid_Sid = (IsValidSid_Proc)
1033 (IsValidSid_Proc) GetProcAddress ( 1021 get_proc_addr (hm_advapi32, "IsValidSid");
1034 hm_advapi32, "IsValidSid");
1035 } 1022 }
1036 if (s_pfn_Is_Valid_Sid == NULL) 1023 if (s_pfn_Is_Valid_Sid == NULL)
1037 { 1024 {
@@ -1053,9 +1040,8 @@ equal_sid (PSID sid1, PSID sid2)
1053 { 1040 {
1054 g_b_init_equal_sid = 1; 1041 g_b_init_equal_sid = 1;
1055 hm_advapi32 = LoadLibrary ("Advapi32.dll"); 1042 hm_advapi32 = LoadLibrary ("Advapi32.dll");
1056 s_pfn_Equal_Sid = 1043 s_pfn_Equal_Sid = (EqualSid_Proc)
1057 (EqualSid_Proc) GetProcAddress ( 1044 get_proc_addr (hm_advapi32, "EqualSid");
1058 hm_advapi32, "EqualSid");
1059 } 1045 }
1060 if (s_pfn_Equal_Sid == NULL) 1046 if (s_pfn_Equal_Sid == NULL)
1061 { 1047 {
@@ -1077,9 +1063,8 @@ get_length_sid (PSID sid)
1077 { 1063 {
1078 g_b_init_get_length_sid = 1; 1064 g_b_init_get_length_sid = 1;
1079 hm_advapi32 = LoadLibrary ("Advapi32.dll"); 1065 hm_advapi32 = LoadLibrary ("Advapi32.dll");
1080 s_pfn_Get_Length_Sid = 1066 s_pfn_Get_Length_Sid = (GetLengthSid_Proc)
1081 (GetLengthSid_Proc) GetProcAddress ( 1067 get_proc_addr (hm_advapi32, "GetLengthSid");
1082 hm_advapi32, "GetLengthSid");
1083 } 1068 }
1084 if (s_pfn_Get_Length_Sid == NULL) 1069 if (s_pfn_Get_Length_Sid == NULL)
1085 { 1070 {
@@ -1101,9 +1086,8 @@ copy_sid (DWORD destlen, PSID dest, PSID src)
1101 { 1086 {
1102 g_b_init_copy_sid = 1; 1087 g_b_init_copy_sid = 1;
1103 hm_advapi32 = LoadLibrary ("Advapi32.dll"); 1088 hm_advapi32 = LoadLibrary ("Advapi32.dll");
1104 s_pfn_Copy_Sid = 1089 s_pfn_Copy_Sid = (CopySid_Proc)
1105 (CopySid_Proc) GetProcAddress ( 1090 get_proc_addr (hm_advapi32, "CopySid");
1106 hm_advapi32, "CopySid");
1107 } 1091 }
1108 if (s_pfn_Copy_Sid == NULL) 1092 if (s_pfn_Copy_Sid == NULL)
1109 { 1093 {
@@ -1127,9 +1111,9 @@ get_native_system_info (LPSYSTEM_INFO lpSystemInfo)
1127 if (g_b_init_get_native_system_info == 0) 1111 if (g_b_init_get_native_system_info == 0)
1128 { 1112 {
1129 g_b_init_get_native_system_info = 1; 1113 g_b_init_get_native_system_info = 1;
1130 s_pfn_Get_Native_System_Info = 1114 s_pfn_Get_Native_System_Info = (GetNativeSystemInfo_Proc)
1131 (GetNativeSystemInfo_Proc)GetProcAddress (GetModuleHandle ("kernel32.dll"), 1115 get_proc_addr (GetModuleHandle ("kernel32.dll"),
1132 "GetNativeSystemInfo"); 1116 "GetNativeSystemInfo");
1133 } 1117 }
1134 if (s_pfn_Get_Native_System_Info != NULL) 1118 if (s_pfn_Get_Native_System_Info != NULL)
1135 s_pfn_Get_Native_System_Info (lpSystemInfo); 1119 s_pfn_Get_Native_System_Info (lpSystemInfo);
@@ -1151,9 +1135,9 @@ get_system_times (LPFILETIME lpIdleTime,
1151 if (g_b_init_get_system_times == 0) 1135 if (g_b_init_get_system_times == 0)
1152 { 1136 {
1153 g_b_init_get_system_times = 1; 1137 g_b_init_get_system_times = 1;
1154 s_pfn_Get_System_times = 1138 s_pfn_Get_System_times = (GetSystemTimes_Proc)
1155 (GetSystemTimes_Proc)GetProcAddress (GetModuleHandle ("kernel32.dll"), 1139 get_proc_addr (GetModuleHandle ("kernel32.dll"),
1156 "GetSystemTimes"); 1140 "GetSystemTimes");
1157 } 1141 }
1158 if (s_pfn_Get_System_times == NULL) 1142 if (s_pfn_Get_System_times == NULL)
1159 return FALSE; 1143 return FALSE;
@@ -1181,9 +1165,9 @@ create_symbolic_link (LPCSTR lpSymlinkFilename,
1181 if (g_b_init_create_symbolic_link_w == 0) 1165 if (g_b_init_create_symbolic_link_w == 0)
1182 { 1166 {
1183 g_b_init_create_symbolic_link_w = 1; 1167 g_b_init_create_symbolic_link_w = 1;
1184 s_pfn_Create_Symbolic_LinkW = 1168 s_pfn_Create_Symbolic_LinkW = (CreateSymbolicLinkW_Proc)
1185 (CreateSymbolicLinkW_Proc)GetProcAddress (GetModuleHandle ("kernel32.dll"), 1169 get_proc_addr (GetModuleHandle ("kernel32.dll"),
1186 "CreateSymbolicLinkW"); 1170 "CreateSymbolicLinkW");
1187 } 1171 }
1188 if (s_pfn_Create_Symbolic_LinkW == NULL) 1172 if (s_pfn_Create_Symbolic_LinkW == NULL)
1189 { 1173 {
@@ -1216,9 +1200,9 @@ create_symbolic_link (LPCSTR lpSymlinkFilename,
1216 if (g_b_init_create_symbolic_link_a == 0) 1200 if (g_b_init_create_symbolic_link_a == 0)
1217 { 1201 {
1218 g_b_init_create_symbolic_link_a = 1; 1202 g_b_init_create_symbolic_link_a = 1;
1219 s_pfn_Create_Symbolic_LinkA = 1203 s_pfn_Create_Symbolic_LinkA = (CreateSymbolicLinkA_Proc)
1220 (CreateSymbolicLinkA_Proc)GetProcAddress (GetModuleHandle ("kernel32.dll"), 1204 get_proc_addr (GetModuleHandle ("kernel32.dll"),
1221 "CreateSymbolicLinkA"); 1205 "CreateSymbolicLinkA");
1222 } 1206 }
1223 if (s_pfn_Create_Symbolic_LinkA == NULL) 1207 if (s_pfn_Create_Symbolic_LinkA == NULL)
1224 { 1208 {
@@ -1261,9 +1245,9 @@ is_valid_security_descriptor (PSECURITY_DESCRIPTOR pSecurityDescriptor)
1261 if (g_b_init_is_valid_security_descriptor == 0) 1245 if (g_b_init_is_valid_security_descriptor == 0)
1262 { 1246 {
1263 g_b_init_is_valid_security_descriptor = 1; 1247 g_b_init_is_valid_security_descriptor = 1;
1264 s_pfn_Is_Valid_Security_Descriptor_Proc = 1248 s_pfn_Is_Valid_Security_Descriptor_Proc = (IsValidSecurityDescriptor_Proc)
1265 (IsValidSecurityDescriptor_Proc)GetProcAddress (GetModuleHandle ("Advapi32.dll"), 1249 get_proc_addr (GetModuleHandle ("Advapi32.dll"),
1266 "IsValidSecurityDescriptor"); 1250 "IsValidSecurityDescriptor");
1267 } 1251 }
1268 if (s_pfn_Is_Valid_Security_Descriptor_Proc == NULL) 1252 if (s_pfn_Is_Valid_Security_Descriptor_Proc == NULL)
1269 { 1253 {
@@ -1295,12 +1279,14 @@ convert_sd_to_sddl (PSECURITY_DESCRIPTOR SecurityDescriptor,
1295 g_b_init_convert_sd_to_sddl = 1; 1279 g_b_init_convert_sd_to_sddl = 1;
1296#ifdef _UNICODE 1280#ifdef _UNICODE
1297 s_pfn_Convert_SD_To_SDDL = 1281 s_pfn_Convert_SD_To_SDDL =
1298 (ConvertSecurityDescriptorToStringSecurityDescriptor_Proc)GetProcAddress (GetModuleHandle ("Advapi32.dll"), 1282 (ConvertSecurityDescriptorToStringSecurityDescriptor_Proc)
1299 "ConvertSecurityDescriptorToStringSecurityDescriptorW"); 1283 get_proc_addr (GetModuleHandle ("Advapi32.dll"),
1284 "ConvertSecurityDescriptorToStringSecurityDescriptorW");
1300#else 1285#else
1301 s_pfn_Convert_SD_To_SDDL = 1286 s_pfn_Convert_SD_To_SDDL =
1302 (ConvertSecurityDescriptorToStringSecurityDescriptor_Proc)GetProcAddress (GetModuleHandle ("Advapi32.dll"), 1287 (ConvertSecurityDescriptorToStringSecurityDescriptor_Proc)
1303 "ConvertSecurityDescriptorToStringSecurityDescriptorA"); 1288 get_proc_addr (GetModuleHandle ("Advapi32.dll"),
1289 "ConvertSecurityDescriptorToStringSecurityDescriptorA");
1304#endif 1290#endif
1305 } 1291 }
1306 if (s_pfn_Convert_SD_To_SDDL == NULL) 1292 if (s_pfn_Convert_SD_To_SDDL == NULL)
@@ -1338,12 +1324,14 @@ convert_sddl_to_sd (LPCTSTR StringSecurityDescriptor,
1338 g_b_init_convert_sddl_to_sd = 1; 1324 g_b_init_convert_sddl_to_sd = 1;
1339#ifdef _UNICODE 1325#ifdef _UNICODE
1340 s_pfn_Convert_SDDL_To_SD = 1326 s_pfn_Convert_SDDL_To_SD =
1341 (ConvertStringSecurityDescriptorToSecurityDescriptor_Proc)GetProcAddress (GetModuleHandle ("Advapi32.dll"), 1327 (ConvertStringSecurityDescriptorToSecurityDescriptor_Proc)
1342 "ConvertStringSecurityDescriptorToSecurityDescriptorW"); 1328 get_proc_addr (GetModuleHandle ("Advapi32.dll"),
1329 "ConvertStringSecurityDescriptorToSecurityDescriptorW");
1343#else 1330#else
1344 s_pfn_Convert_SDDL_To_SD = 1331 s_pfn_Convert_SDDL_To_SD =
1345 (ConvertStringSecurityDescriptorToSecurityDescriptor_Proc)GetProcAddress (GetModuleHandle ("Advapi32.dll"), 1332 (ConvertStringSecurityDescriptorToSecurityDescriptor_Proc)
1346 "ConvertStringSecurityDescriptorToSecurityDescriptorA"); 1333 get_proc_addr (GetModuleHandle ("Advapi32.dll"),
1334 "ConvertStringSecurityDescriptorToSecurityDescriptorA");
1347#endif 1335#endif
1348 } 1336 }
1349 if (s_pfn_Convert_SDDL_To_SD == NULL) 1337 if (s_pfn_Convert_SDDL_To_SD == NULL)
@@ -1375,7 +1363,7 @@ get_adapters_info (PIP_ADAPTER_INFO pAdapterInfo, PULONG pOutBufLen)
1375 hm_iphlpapi = LoadLibrary ("Iphlpapi.dll"); 1363 hm_iphlpapi = LoadLibrary ("Iphlpapi.dll");
1376 if (hm_iphlpapi) 1364 if (hm_iphlpapi)
1377 s_pfn_Get_Adapters_Info = (GetAdaptersInfo_Proc) 1365 s_pfn_Get_Adapters_Info = (GetAdaptersInfo_Proc)
1378 GetProcAddress (hm_iphlpapi, "GetAdaptersInfo"); 1366 get_proc_addr (hm_iphlpapi, "GetAdaptersInfo");
1379 } 1367 }
1380 if (s_pfn_Get_Adapters_Info == NULL) 1368 if (s_pfn_Get_Adapters_Info == NULL)
1381 return ERROR_NOT_SUPPORTED; 1369 return ERROR_NOT_SUPPORTED;
@@ -1398,7 +1386,7 @@ reg_open_key_ex_w (HKEY hkey, LPCWSTR lpSubKey, DWORD ulOptions,
1398 hm_advapi32 = LoadLibrary ("Advapi32.dll"); 1386 hm_advapi32 = LoadLibrary ("Advapi32.dll");
1399 if (hm_advapi32) 1387 if (hm_advapi32)
1400 s_pfn_Reg_Open_Key_Ex_w = (RegOpenKeyExW_Proc) 1388 s_pfn_Reg_Open_Key_Ex_w = (RegOpenKeyExW_Proc)
1401 GetProcAddress (hm_advapi32, "RegOpenKeyExW"); 1389 get_proc_addr (hm_advapi32, "RegOpenKeyExW");
1402 } 1390 }
1403 if (s_pfn_Reg_Open_Key_Ex_w == NULL) 1391 if (s_pfn_Reg_Open_Key_Ex_w == NULL)
1404 return ERROR_NOT_SUPPORTED; 1392 return ERROR_NOT_SUPPORTED;
@@ -1422,7 +1410,7 @@ reg_query_value_ex_w (HKEY hkey, LPCWSTR lpValueName, LPDWORD lpReserved,
1422 hm_advapi32 = LoadLibrary ("Advapi32.dll"); 1410 hm_advapi32 = LoadLibrary ("Advapi32.dll");
1423 if (hm_advapi32) 1411 if (hm_advapi32)
1424 s_pfn_Reg_Query_Value_Ex_w = (RegQueryValueExW_Proc) 1412 s_pfn_Reg_Query_Value_Ex_w = (RegQueryValueExW_Proc)
1425 GetProcAddress (hm_advapi32, "RegQueryValueExW"); 1413 get_proc_addr (hm_advapi32, "RegQueryValueExW");
1426 } 1414 }
1427 if (s_pfn_Reg_Query_Value_Ex_w == NULL) 1415 if (s_pfn_Reg_Query_Value_Ex_w == NULL)
1428 return ERROR_NOT_SUPPORTED; 1416 return ERROR_NOT_SUPPORTED;
@@ -1445,7 +1433,7 @@ expand_environment_strings_w (LPCWSTR lpSrc, LPWSTR lpDst, DWORD nSize)
1445 hm_kernel32 = LoadLibrary ("Kernel32.dll"); 1433 hm_kernel32 = LoadLibrary ("Kernel32.dll");
1446 if (hm_kernel32) 1434 if (hm_kernel32)
1447 s_pfn_Expand_Environment_Strings_w = (ExpandEnvironmentStringsW_Proc) 1435 s_pfn_Expand_Environment_Strings_w = (ExpandEnvironmentStringsW_Proc)
1448 GetProcAddress (hm_kernel32, "ExpandEnvironmentStringsW"); 1436 get_proc_addr (hm_kernel32, "ExpandEnvironmentStringsW");
1449 } 1437 }
1450 if (s_pfn_Expand_Environment_Strings_w == NULL) 1438 if (s_pfn_Expand_Environment_Strings_w == NULL)
1451 { 1439 {
@@ -2807,7 +2795,8 @@ init_environment (char ** argv)
2807 MSIE 5. */ 2795 MSIE 5. */
2808 ShGetFolderPath_fn get_folder_path; 2796 ShGetFolderPath_fn get_folder_path;
2809 get_folder_path = (ShGetFolderPath_fn) 2797 get_folder_path = (ShGetFolderPath_fn)
2810 GetProcAddress (GetModuleHandle ("shell32.dll"), "SHGetFolderPathA"); 2798 get_proc_addr (GetModuleHandle ("shell32.dll"),
2799 "SHGetFolderPathA");
2811 2800
2812 if (get_folder_path != NULL) 2801 if (get_folder_path != NULL)
2813 { 2802 {
@@ -6639,8 +6628,8 @@ create_toolhelp32_snapshot (DWORD Flags, DWORD Ignored)
6639 { 6628 {
6640 g_b_init_create_toolhelp32_snapshot = 1; 6629 g_b_init_create_toolhelp32_snapshot = 1;
6641 s_pfn_Create_Toolhelp32_Snapshot = (CreateToolhelp32Snapshot_Proc) 6630 s_pfn_Create_Toolhelp32_Snapshot = (CreateToolhelp32Snapshot_Proc)
6642 GetProcAddress (GetModuleHandle ("kernel32.dll"), 6631 get_proc_addr (GetModuleHandle ("kernel32.dll"),
6643 "CreateToolhelp32Snapshot"); 6632 "CreateToolhelp32Snapshot");
6644 } 6633 }
6645 if (s_pfn_Create_Toolhelp32_Snapshot == NULL) 6634 if (s_pfn_Create_Toolhelp32_Snapshot == NULL)
6646 { 6635 {
@@ -6658,8 +6647,8 @@ process32_first (HANDLE hSnapshot, LPPROCESSENTRY32 lppe)
6658 { 6647 {
6659 g_b_init_process32_first = 1; 6648 g_b_init_process32_first = 1;
6660 s_pfn_Process32_First = (Process32First_Proc) 6649 s_pfn_Process32_First = (Process32First_Proc)
6661 GetProcAddress (GetModuleHandle ("kernel32.dll"), 6650 get_proc_addr (GetModuleHandle ("kernel32.dll"),
6662 "Process32First"); 6651 "Process32First");
6663 } 6652 }
6664 if (s_pfn_Process32_First == NULL) 6653 if (s_pfn_Process32_First == NULL)
6665 { 6654 {
@@ -6677,8 +6666,8 @@ process32_next (HANDLE hSnapshot, LPPROCESSENTRY32 lppe)
6677 { 6666 {
6678 g_b_init_process32_next = 1; 6667 g_b_init_process32_next = 1;
6679 s_pfn_Process32_Next = (Process32Next_Proc) 6668 s_pfn_Process32_Next = (Process32Next_Proc)
6680 GetProcAddress (GetModuleHandle ("kernel32.dll"), 6669 get_proc_addr (GetModuleHandle ("kernel32.dll"),
6681 "Process32Next"); 6670 "Process32Next");
6682 } 6671 }
6683 if (s_pfn_Process32_Next == NULL) 6672 if (s_pfn_Process32_Next == NULL)
6684 { 6673 {
@@ -6704,8 +6693,8 @@ open_thread_token (HANDLE ThreadHandle,
6704 { 6693 {
6705 g_b_init_open_thread_token = 1; 6694 g_b_init_open_thread_token = 1;
6706 hm_advapi32 = LoadLibrary ("Advapi32.dll"); 6695 hm_advapi32 = LoadLibrary ("Advapi32.dll");
6707 s_pfn_Open_Thread_Token = 6696 s_pfn_Open_Thread_Token = (OpenThreadToken_Proc)
6708 (OpenThreadToken_Proc) GetProcAddress (hm_advapi32, "OpenThreadToken"); 6697 get_proc_addr (hm_advapi32, "OpenThreadToken");
6709 } 6698 }
6710 if (s_pfn_Open_Thread_Token == NULL) 6699 if (s_pfn_Open_Thread_Token == NULL)
6711 { 6700 {
@@ -6734,8 +6723,8 @@ impersonate_self (SECURITY_IMPERSONATION_LEVEL ImpersonationLevel)
6734 { 6723 {
6735 g_b_init_impersonate_self = 1; 6724 g_b_init_impersonate_self = 1;
6736 hm_advapi32 = LoadLibrary ("Advapi32.dll"); 6725 hm_advapi32 = LoadLibrary ("Advapi32.dll");
6737 s_pfn_Impersonate_Self = 6726 s_pfn_Impersonate_Self = (ImpersonateSelf_Proc)
6738 (ImpersonateSelf_Proc) GetProcAddress (hm_advapi32, "ImpersonateSelf"); 6727 get_proc_addr (hm_advapi32, "ImpersonateSelf");
6739 } 6728 }
6740 if (s_pfn_Impersonate_Self == NULL) 6729 if (s_pfn_Impersonate_Self == NULL)
6741 { 6730 {
@@ -6757,8 +6746,8 @@ revert_to_self (void)
6757 { 6746 {
6758 g_b_init_revert_to_self = 1; 6747 g_b_init_revert_to_self = 1;
6759 hm_advapi32 = LoadLibrary ("Advapi32.dll"); 6748 hm_advapi32 = LoadLibrary ("Advapi32.dll");
6760 s_pfn_Revert_To_Self = 6749 s_pfn_Revert_To_Self = (RevertToSelf_Proc)
6761 (RevertToSelf_Proc) GetProcAddress (hm_advapi32, "RevertToSelf"); 6750 get_proc_addr (hm_advapi32, "RevertToSelf");
6762 } 6751 }
6763 if (s_pfn_Revert_To_Self == NULL) 6752 if (s_pfn_Revert_To_Self == NULL)
6764 { 6753 {
@@ -6784,7 +6773,7 @@ get_process_memory_info (HANDLE h_proc,
6784 hm_psapi = LoadLibrary ("Psapi.dll"); 6773 hm_psapi = LoadLibrary ("Psapi.dll");
6785 if (hm_psapi) 6774 if (hm_psapi)
6786 s_pfn_Get_Process_Memory_Info = (GetProcessMemoryInfo_Proc) 6775 s_pfn_Get_Process_Memory_Info = (GetProcessMemoryInfo_Proc)
6787 GetProcAddress (hm_psapi, "GetProcessMemoryInfo"); 6776 get_proc_addr (hm_psapi, "GetProcessMemoryInfo");
6788 } 6777 }
6789 if (s_pfn_Get_Process_Memory_Info == NULL) 6778 if (s_pfn_Get_Process_Memory_Info == NULL)
6790 { 6779 {
@@ -6809,8 +6798,8 @@ get_process_working_set_size (HANDLE h_proc,
6809 { 6798 {
6810 g_b_init_get_process_working_set_size = 1; 6799 g_b_init_get_process_working_set_size = 1;
6811 s_pfn_Get_Process_Working_Set_Size = (GetProcessWorkingSetSize_Proc) 6800 s_pfn_Get_Process_Working_Set_Size = (GetProcessWorkingSetSize_Proc)
6812 GetProcAddress (GetModuleHandle ("kernel32.dll"), 6801 get_proc_addr (GetModuleHandle ("kernel32.dll"),
6813 "GetProcessWorkingSetSize"); 6802 "GetProcessWorkingSetSize");
6814 } 6803 }
6815 if (s_pfn_Get_Process_Working_Set_Size == NULL) 6804 if (s_pfn_Get_Process_Working_Set_Size == NULL)
6816 { 6805 {
@@ -6832,8 +6821,8 @@ global_memory_status (MEMORYSTATUS *buf)
6832 { 6821 {
6833 g_b_init_global_memory_status = 1; 6822 g_b_init_global_memory_status = 1;
6834 s_pfn_Global_Memory_Status = (GlobalMemoryStatus_Proc) 6823 s_pfn_Global_Memory_Status = (GlobalMemoryStatus_Proc)
6835 GetProcAddress (GetModuleHandle ("kernel32.dll"), 6824 get_proc_addr (GetModuleHandle ("kernel32.dll"),
6836 "GlobalMemoryStatus"); 6825 "GlobalMemoryStatus");
6837 } 6826 }
6838 if (s_pfn_Global_Memory_Status == NULL) 6827 if (s_pfn_Global_Memory_Status == NULL)
6839 { 6828 {
@@ -6855,8 +6844,8 @@ global_memory_status_ex (MEMORY_STATUS_EX *buf)
6855 { 6844 {
6856 g_b_init_global_memory_status_ex = 1; 6845 g_b_init_global_memory_status_ex = 1;
6857 s_pfn_Global_Memory_Status_Ex = (GlobalMemoryStatusEx_Proc) 6846 s_pfn_Global_Memory_Status_Ex = (GlobalMemoryStatusEx_Proc)
6858 GetProcAddress (GetModuleHandle ("kernel32.dll"), 6847 get_proc_addr (GetModuleHandle ("kernel32.dll"),
6859 "GlobalMemoryStatusEx"); 6848 "GlobalMemoryStatusEx");
6860 } 6849 }
6861 if (s_pfn_Global_Memory_Status_Ex == NULL) 6850 if (s_pfn_Global_Memory_Status_Ex == NULL)
6862 { 6851 {
@@ -7428,8 +7417,8 @@ init_winsock (int load_now)
7428 return TRUE; 7417 return TRUE;
7429 7418
7430 pfn_SetHandleInformation 7419 pfn_SetHandleInformation
7431 = (void *) GetProcAddress (GetModuleHandle ("kernel32.dll"), 7420 = (void *) get_proc_addr (GetModuleHandle ("kernel32.dll"),
7432 "SetHandleInformation"); 7421 "SetHandleInformation");
7433 7422
7434 winsock_lib = LoadLibrary ("Ws2_32.dll"); 7423 winsock_lib = LoadLibrary ("Ws2_32.dll");
7435 7424
@@ -7438,7 +7427,7 @@ init_winsock (int load_now)
7438 /* dynamically link to socket functions */ 7427 /* dynamically link to socket functions */
7439 7428
7440#define LOAD_PROC(fn) \ 7429#define LOAD_PROC(fn) \
7441 if ((pfn_##fn = (void *) GetProcAddress (winsock_lib, #fn)) == NULL) \ 7430 if ((pfn_##fn = (void *) get_proc_addr (winsock_lib, #fn)) == NULL) \
7442 goto fail; 7431 goto fail;
7443 7432
7444 LOAD_PROC (WSAStartup); 7433 LOAD_PROC (WSAStartup);
@@ -7473,8 +7462,8 @@ init_winsock (int load_now)
7473#undef LOAD_PROC 7462#undef LOAD_PROC
7474 7463
7475 /* Try loading functions not available before XP. */ 7464 /* Try loading functions not available before XP. */
7476 pfn_getaddrinfo = (void *) GetProcAddress (winsock_lib, "getaddrinfo"); 7465 pfn_getaddrinfo = (void *) get_proc_addr (winsock_lib, "getaddrinfo");
7477 pfn_freeaddrinfo = (void *) GetProcAddress (winsock_lib, "freeaddrinfo"); 7466 pfn_freeaddrinfo = (void *) get_proc_addr (winsock_lib, "freeaddrinfo");
7478 /* Paranoia: these two functions should go together, so if one 7467 /* Paranoia: these two functions should go together, so if one
7479 is absent, we cannot use the other. */ 7468 is absent, we cannot use the other. */
7480 if (pfn_getaddrinfo == NULL) 7469 if (pfn_getaddrinfo == NULL)
@@ -9892,10 +9881,10 @@ maybe_load_unicows_dll (void)
9892 pointers, and assign the correct addresses to these 9881 pointers, and assign the correct addresses to these
9893 pointers at program startup (see emacs.c, which calls 9882 pointers at program startup (see emacs.c, which calls
9894 this function early on). */ 9883 this function early on). */
9895 pMultiByteToWideChar = 9884 pMultiByteToWideChar = (MultiByteToWideChar_Proc)
9896 (MultiByteToWideChar_Proc)GetProcAddress (ret, "MultiByteToWideChar"); 9885 get_proc_addr (ret, "MultiByteToWideChar");
9897 pWideCharToMultiByte = 9886 pWideCharToMultiByte = (WideCharToMultiByte_Proc)
9898 (WideCharToMultiByte_Proc)GetProcAddress (ret, "WideCharToMultiByte"); 9887 get_proc_addr (ret, "WideCharToMultiByte");
9899 multiByteToWideCharFlags = MB_ERR_INVALID_CHARS; 9888 multiByteToWideCharFlags = MB_ERR_INVALID_CHARS;
9900 return ret; 9889 return ret;
9901 } 9890 }
@@ -9946,7 +9935,7 @@ globals_of_w32 (void)
9946 HMODULE kernel32 = GetModuleHandle ("kernel32.dll"); 9935 HMODULE kernel32 = GetModuleHandle ("kernel32.dll");
9947 9936
9948 get_process_times_fn = (GetProcessTimes_Proc) 9937 get_process_times_fn = (GetProcessTimes_Proc)
9949 GetProcAddress (kernel32, "GetProcessTimes"); 9938 get_proc_addr (kernel32, "GetProcessTimes");
9950 9939
9951 DEFSYM (QCloaded_from, ":loaded-from"); 9940 DEFSYM (QCloaded_from, ":loaded-from");
9952 9941
diff --git a/src/w32.h b/src/w32.h
index fe8689a07b4..a053ee0fc4b 100644
--- a/src/w32.h
+++ b/src/w32.h
@@ -164,6 +164,10 @@ extern void reset_standard_handles (int in, int out,
164/* Return the string resource associated with KEY of type TYPE. */ 164/* Return the string resource associated with KEY of type TYPE. */
165extern LPBYTE w32_get_resource (const char * key, LPDWORD type); 165extern LPBYTE w32_get_resource (const char * key, LPDWORD type);
166 166
167/* Load a function from a DLL. Defined in this file. */
168typedef void (* VOIDFNPTR) (void);
169INLINE VOIDFNPTR get_proc_addr (HINSTANCE handle, LPCSTR fname);
170
167extern void release_listen_threads (void); 171extern void release_listen_threads (void);
168extern void init_ntproc (int); 172extern void init_ntproc (int);
169extern void term_ntproc (int); 173extern void term_ntproc (int);
@@ -241,14 +245,30 @@ extern ssize_t emacs_gnutls_push (gnutls_transport_ptr_t p,
241 const void* buf, size_t sz); 245 const void* buf, size_t sz);
242#endif /* HAVE_GNUTLS */ 246#endif /* HAVE_GNUTLS */
243 247
244/* Definine a function that will be loaded from a DLL. */ 248
245#define DEF_DLL_FN(type, func, args) static type (FAR CDECL *fn_##func) args 249
250/* Load a function address from a DLL. Cast the result via "VOIDFNPTR"
251 to pacify -Wcast-function-type in GCC 8.1. */
252INLINE VOIDFNPTR
253get_proc_addr (HINSTANCE handle, LPCSTR fname)
254{
255 return (VOIDFNPTR) GetProcAddress (handle, fname);
256}
257
258/* Define a function that will be loaded from a DLL. The variable
259 arguments should contain the argument list for the function, and
260 optionally be followed by function attributes. For example:
261 DEF_DLL_FN (void, png_longjmp, (png_structp, int) PNG_NORETURN);
262 */
263#define DEF_DLL_FN(type, func, ...) \
264 typedef type (CDECL *W32_PFN_##func) __VA_ARGS__; \
265 static W32_PFN_##func fn_##func
246 266
247/* Load a function from the DLL. */ 267/* Load a function from the DLL. */
248#define LOAD_DLL_FN(lib, func) \ 268#define LOAD_DLL_FN(lib, func) \
249 do \ 269 do \
250 { \ 270 { \
251 fn_##func = (void *) GetProcAddress (lib, #func); \ 271 fn_##func = (W32_PFN_##func) get_proc_addr (lib, #func); \
252 if (!fn_##func) \ 272 if (!fn_##func) \
253 return false; \ 273 return false; \
254 } \ 274 } \
diff --git a/src/w32fns.c b/src/w32fns.c
index 8d5293c1af0..c32868fa695 100644
--- a/src/w32fns.c
+++ b/src/w32fns.c
@@ -2640,7 +2640,7 @@ setup_w32_kbdhook (void)
2640 if (w32_kbdhook_active) 2640 if (w32_kbdhook_active)
2641 { 2641 {
2642 IsDebuggerPresent_Proc is_debugger_present = (IsDebuggerPresent_Proc) 2642 IsDebuggerPresent_Proc is_debugger_present = (IsDebuggerPresent_Proc)
2643 GetProcAddress (GetModuleHandle ("kernel32.dll"), "IsDebuggerPresent"); 2643 get_proc_addr (GetModuleHandle ("kernel32.dll"), "IsDebuggerPresent");
2644 if (is_debugger_present && is_debugger_present ()) 2644 if (is_debugger_present && is_debugger_present ())
2645 return; 2645 return;
2646 } 2646 }
@@ -2655,7 +2655,7 @@ setup_w32_kbdhook (void)
2655 (https://support.microsoft.com/en-us/kb/124103) is used for 2655 (https://support.microsoft.com/en-us/kb/124103) is used for
2656 NT 4 systems. */ 2656 NT 4 systems. */
2657 GetConsoleWindow_Proc get_console = (GetConsoleWindow_Proc) 2657 GetConsoleWindow_Proc get_console = (GetConsoleWindow_Proc)
2658 GetProcAddress (GetModuleHandle ("kernel32.dll"), "GetConsoleWindow"); 2658 get_proc_addr (GetModuleHandle ("kernel32.dll"), "GetConsoleWindow");
2659 2659
2660 if (get_console != NULL) 2660 if (get_console != NULL)
2661 kbdhook.console = get_console (); 2661 kbdhook.console = get_console ();
@@ -9117,9 +9117,9 @@ DEFUN ("file-system-info", Ffile_system_info, Sfile_system_info, 1, 1, 0,
9117 { 9117 {
9118 HMODULE hKernel = GetModuleHandle ("kernel32"); 9118 HMODULE hKernel = GetModuleHandle ("kernel32");
9119 GetDiskFreeSpaceExW_Proc pfn_GetDiskFreeSpaceExW = 9119 GetDiskFreeSpaceExW_Proc pfn_GetDiskFreeSpaceExW =
9120 (GetDiskFreeSpaceExW_Proc) GetProcAddress (hKernel, "GetDiskFreeSpaceExW"); 9120 (GetDiskFreeSpaceExW_Proc) get_proc_addr (hKernel, "GetDiskFreeSpaceExW");
9121 GetDiskFreeSpaceExA_Proc pfn_GetDiskFreeSpaceExA = 9121 GetDiskFreeSpaceExA_Proc pfn_GetDiskFreeSpaceExA =
9122 (GetDiskFreeSpaceExA_Proc) GetProcAddress (hKernel, "GetDiskFreeSpaceExA"); 9122 (GetDiskFreeSpaceExA_Proc) get_proc_addr (hKernel, "GetDiskFreeSpaceExA");
9123 bool have_pfn_GetDiskFreeSpaceEx = 9123 bool have_pfn_GetDiskFreeSpaceEx =
9124 ((w32_unicode_filenames && pfn_GetDiskFreeSpaceExW) 9124 ((w32_unicode_filenames && pfn_GetDiskFreeSpaceExW)
9125 || (!w32_unicode_filenames && pfn_GetDiskFreeSpaceExA)); 9125 || (!w32_unicode_filenames && pfn_GetDiskFreeSpaceExA));
@@ -9694,8 +9694,8 @@ get_dll_version (const char *dll_name)
9694 9694
9695 if (hdll) 9695 if (hdll)
9696 { 9696 {
9697 DLLGETVERSIONPROC pDllGetVersion 9697 DLLGETVERSIONPROC pDllGetVersion = (DLLGETVERSIONPROC)
9698 = (DLLGETVERSIONPROC) GetProcAddress (hdll, "DllGetVersion"); 9698 get_proc_addr (hdll, "DllGetVersion");
9699 9699
9700 if (pDllGetVersion) 9700 if (pDllGetVersion)
9701 { 9701 {
@@ -10662,9 +10662,8 @@ void
10662w32_reset_stack_overflow_guard (void) 10662w32_reset_stack_overflow_guard (void)
10663{ 10663{
10664 if (resetstkoflw == NULL) 10664 if (resetstkoflw == NULL)
10665 resetstkoflw = 10665 resetstkoflw = (_resetstkoflw_proc)
10666 (_resetstkoflw_proc)GetProcAddress (GetModuleHandle ("msvcrt.dll"), 10666 get_proc_addr (GetModuleHandle ("msvcrt.dll"), "_resetstkoflw");
10667 "_resetstkoflw");
10668 /* We ignore the return value. If _resetstkoflw fails, the next 10667 /* We ignore the return value. If _resetstkoflw fails, the next
10669 stack overflow will crash the program. */ 10668 stack overflow will crash the program. */
10670 if (resetstkoflw != NULL) 10669 if (resetstkoflw != NULL)
@@ -10738,9 +10737,8 @@ w32_backtrace (void **buffer, int limit)
10738 if (!s_pfn_CaptureStackBackTrace) 10737 if (!s_pfn_CaptureStackBackTrace)
10739 { 10738 {
10740 hm_kernel32 = LoadLibrary ("Kernel32.dll"); 10739 hm_kernel32 = LoadLibrary ("Kernel32.dll");
10741 s_pfn_CaptureStackBackTrace = 10740 s_pfn_CaptureStackBackTrace = (CaptureStackBackTrace_proc)
10742 (CaptureStackBackTrace_proc) GetProcAddress (hm_kernel32, 10741 get_proc_addr (hm_kernel32, "RtlCaptureStackBackTrace");
10743 "RtlCaptureStackBackTrace");
10744 } 10742 }
10745 if (s_pfn_CaptureStackBackTrace) 10743 if (s_pfn_CaptureStackBackTrace)
10746 return s_pfn_CaptureStackBackTrace (0, min (BACKTRACE_LIMIT_MAX, limit), 10744 return s_pfn_CaptureStackBackTrace (0, min (BACKTRACE_LIMIT_MAX, limit),
@@ -10873,29 +10871,29 @@ globals_of_w32fns (void)
10873 it dynamically. Do it once, here, instead of every time it is used. 10871 it dynamically. Do it once, here, instead of every time it is used.
10874 */ 10872 */
10875 track_mouse_event_fn = (TrackMouseEvent_Proc) 10873 track_mouse_event_fn = (TrackMouseEvent_Proc)
10876 GetProcAddress (user32_lib, "TrackMouseEvent"); 10874 get_proc_addr (user32_lib, "TrackMouseEvent");
10877 10875
10878 monitor_from_point_fn = (MonitorFromPoint_Proc) 10876 monitor_from_point_fn = (MonitorFromPoint_Proc)
10879 GetProcAddress (user32_lib, "MonitorFromPoint"); 10877 get_proc_addr (user32_lib, "MonitorFromPoint");
10880 get_monitor_info_fn = (GetMonitorInfo_Proc) 10878 get_monitor_info_fn = (GetMonitorInfo_Proc)
10881 GetProcAddress (user32_lib, "GetMonitorInfoA"); 10879 get_proc_addr (user32_lib, "GetMonitorInfoA");
10882 monitor_from_window_fn = (MonitorFromWindow_Proc) 10880 monitor_from_window_fn = (MonitorFromWindow_Proc)
10883 GetProcAddress (user32_lib, "MonitorFromWindow"); 10881 get_proc_addr (user32_lib, "MonitorFromWindow");
10884 enum_display_monitors_fn = (EnumDisplayMonitors_Proc) 10882 enum_display_monitors_fn = (EnumDisplayMonitors_Proc)
10885 GetProcAddress (user32_lib, "EnumDisplayMonitors"); 10883 get_proc_addr (user32_lib, "EnumDisplayMonitors");
10886 get_title_bar_info_fn = (GetTitleBarInfo_Proc) 10884 get_title_bar_info_fn = (GetTitleBarInfo_Proc)
10887 GetProcAddress (user32_lib, "GetTitleBarInfo"); 10885 get_proc_addr (user32_lib, "GetTitleBarInfo");
10888 10886
10889 { 10887 {
10890 HMODULE imm32_lib = GetModuleHandle ("imm32.dll"); 10888 HMODULE imm32_lib = GetModuleHandle ("imm32.dll");
10891 get_composition_string_fn = (ImmGetCompositionString_Proc) 10889 get_composition_string_fn = (ImmGetCompositionString_Proc)
10892 GetProcAddress (imm32_lib, "ImmGetCompositionStringW"); 10890 get_proc_addr (imm32_lib, "ImmGetCompositionStringW");
10893 get_ime_context_fn = (ImmGetContext_Proc) 10891 get_ime_context_fn = (ImmGetContext_Proc)
10894 GetProcAddress (imm32_lib, "ImmGetContext"); 10892 get_proc_addr (imm32_lib, "ImmGetContext");
10895 release_ime_context_fn = (ImmReleaseContext_Proc) 10893 release_ime_context_fn = (ImmReleaseContext_Proc)
10896 GetProcAddress (imm32_lib, "ImmReleaseContext"); 10894 get_proc_addr (imm32_lib, "ImmReleaseContext");
10897 set_ime_composition_window_fn = (ImmSetCompositionWindow_Proc) 10895 set_ime_composition_window_fn = (ImmSetCompositionWindow_Proc)
10898 GetProcAddress (imm32_lib, "ImmSetCompositionWindow"); 10896 get_proc_addr (imm32_lib, "ImmSetCompositionWindow");
10899 } 10897 }
10900 10898
10901 except_code = 0; 10899 except_code = 0;
diff --git a/src/w32font.c b/src/w32font.c
index c2f5dc3746d..f6130618323 100644
--- a/src/w32font.c
+++ b/src/w32font.c
@@ -153,7 +153,7 @@ get_outline_metrics_w(HDC hdc, UINT cbData, LPOUTLINETEXTMETRICW lpotmw)
153 hm_unicows = w32_load_unicows_or_gdi32 (); 153 hm_unicows = w32_load_unicows_or_gdi32 ();
154 if (hm_unicows) 154 if (hm_unicows)
155 s_pfn_Get_Outline_Text_MetricsW = (GetOutlineTextMetricsW_Proc) 155 s_pfn_Get_Outline_Text_MetricsW = (GetOutlineTextMetricsW_Proc)
156 GetProcAddress (hm_unicows, "GetOutlineTextMetricsW"); 156 get_proc_addr (hm_unicows, "GetOutlineTextMetricsW");
157 } 157 }
158 eassert (s_pfn_Get_Outline_Text_MetricsW != NULL); 158 eassert (s_pfn_Get_Outline_Text_MetricsW != NULL);
159 return s_pfn_Get_Outline_Text_MetricsW (hdc, cbData, lpotmw); 159 return s_pfn_Get_Outline_Text_MetricsW (hdc, cbData, lpotmw);
@@ -170,7 +170,7 @@ get_text_metrics_w(HDC hdc, LPTEXTMETRICW lptmw)
170 hm_unicows = w32_load_unicows_or_gdi32 (); 170 hm_unicows = w32_load_unicows_or_gdi32 ();
171 if (hm_unicows) 171 if (hm_unicows)
172 s_pfn_Get_Text_MetricsW = (GetTextMetricsW_Proc) 172 s_pfn_Get_Text_MetricsW = (GetTextMetricsW_Proc)
173 GetProcAddress (hm_unicows, "GetTextMetricsW"); 173 get_proc_addr (hm_unicows, "GetTextMetricsW");
174 } 174 }
175 eassert (s_pfn_Get_Text_MetricsW != NULL); 175 eassert (s_pfn_Get_Text_MetricsW != NULL);
176 return s_pfn_Get_Text_MetricsW (hdc, lptmw); 176 return s_pfn_Get_Text_MetricsW (hdc, lptmw);
@@ -188,7 +188,7 @@ get_glyph_outline_w (HDC hdc, UINT uChar, UINT uFormat, LPGLYPHMETRICS lpgm,
188 hm_unicows = w32_load_unicows_or_gdi32 (); 188 hm_unicows = w32_load_unicows_or_gdi32 ();
189 if (hm_unicows) 189 if (hm_unicows)
190 s_pfn_Get_Glyph_OutlineW = (GetGlyphOutlineW_Proc) 190 s_pfn_Get_Glyph_OutlineW = (GetGlyphOutlineW_Proc)
191 GetProcAddress (hm_unicows, "GetGlyphOutlineW"); 191 get_proc_addr (hm_unicows, "GetGlyphOutlineW");
192 } 192 }
193 eassert (s_pfn_Get_Glyph_OutlineW != NULL); 193 eassert (s_pfn_Get_Glyph_OutlineW != NULL);
194 return s_pfn_Get_Glyph_OutlineW (hdc, uChar, uFormat, lpgm, cbBuffer, 194 return s_pfn_Get_Glyph_OutlineW (hdc, uChar, uFormat, lpgm, cbBuffer,
@@ -206,7 +206,7 @@ get_char_width_32_w (HDC hdc, UINT uFirstChar, UINT uLastChar, LPINT lpBuffer)
206 hm_unicows = w32_load_unicows_or_gdi32 (); 206 hm_unicows = w32_load_unicows_or_gdi32 ();
207 if (hm_unicows) 207 if (hm_unicows)
208 s_pfn_Get_Char_Width_32W = (GetCharWidth32W_Proc) 208 s_pfn_Get_Char_Width_32W = (GetCharWidth32W_Proc)
209 GetProcAddress (hm_unicows, "GetCharWidth32W"); 209 get_proc_addr (hm_unicows, "GetCharWidth32W");
210 } 210 }
211 eassert (s_pfn_Get_Char_Width_32W != NULL); 211 eassert (s_pfn_Get_Char_Width_32W != NULL);
212 return s_pfn_Get_Char_Width_32W (hdc, uFirstChar, uLastChar, lpBuffer); 212 return s_pfn_Get_Char_Width_32W (hdc, uFirstChar, uLastChar, lpBuffer);
diff --git a/src/w32heap.c b/src/w32heap.c
index df79f8c2cef..8c946825067 100644
--- a/src/w32heap.c
+++ b/src/w32heap.c
@@ -250,7 +250,9 @@ init_heap (void)
250#ifndef MINGW_W64 250#ifndef MINGW_W64
251 /* Set the low-fragmentation heap for OS before Vista. */ 251 /* Set the low-fragmentation heap for OS before Vista. */
252 HMODULE hm_kernel32dll = LoadLibrary ("kernel32.dll"); 252 HMODULE hm_kernel32dll = LoadLibrary ("kernel32.dll");
253 HeapSetInformation_Proc s_pfn_Heap_Set_Information = (HeapSetInformation_Proc) GetProcAddress (hm_kernel32dll, "HeapSetInformation"); 253 HeapSetInformation_Proc s_pfn_Heap_Set_Information =
254 (HeapSetInformation_Proc) get_proc_addr (hm_kernel32dll,
255 "HeapSetInformation");
254 if (s_pfn_Heap_Set_Information != NULL) 256 if (s_pfn_Heap_Set_Information != NULL)
255 { 257 {
256 if (s_pfn_Heap_Set_Information ((PVOID) heap, 258 if (s_pfn_Heap_Set_Information ((PVOID) heap,
@@ -281,7 +283,7 @@ init_heap (void)
281 in ntdll.dll since XP. */ 283 in ntdll.dll since XP. */
282 HMODULE hm_ntdll = LoadLibrary ("ntdll.dll"); 284 HMODULE hm_ntdll = LoadLibrary ("ntdll.dll");
283 RtlCreateHeap_Proc s_pfn_Rtl_Create_Heap 285 RtlCreateHeap_Proc s_pfn_Rtl_Create_Heap
284 = (RtlCreateHeap_Proc) GetProcAddress (hm_ntdll, "RtlCreateHeap"); 286 = (RtlCreateHeap_Proc) get_proc_addr (hm_ntdll, "RtlCreateHeap");
285 /* Specific parameters for the private heap. */ 287 /* Specific parameters for the private heap. */
286 RTL_HEAP_PARAMETERS params; 288 RTL_HEAP_PARAMETERS params;
287 ZeroMemory (&params, sizeof(params)); 289 ZeroMemory (&params, sizeof(params));
diff --git a/src/w32menu.c b/src/w32menu.c
index ece5836498f..a2d39c5edfe 100644
--- a/src/w32menu.c
+++ b/src/w32menu.c
@@ -1607,9 +1607,13 @@ globals_of_w32menu (void)
1607#ifndef NTGUI_UNICODE 1607#ifndef NTGUI_UNICODE
1608 /* See if Get/SetMenuItemInfo functions are available. */ 1608 /* See if Get/SetMenuItemInfo functions are available. */
1609 HMODULE user32 = GetModuleHandle ("user32.dll"); 1609 HMODULE user32 = GetModuleHandle ("user32.dll");
1610 get_menu_item_info = (GetMenuItemInfoA_Proc) GetProcAddress (user32, "GetMenuItemInfoA"); 1610 get_menu_item_info = (GetMenuItemInfoA_Proc)
1611 set_menu_item_info = (SetMenuItemInfoA_Proc) GetProcAddress (user32, "SetMenuItemInfoA"); 1611 get_proc_addr (user32, "GetMenuItemInfoA");
1612 unicode_append_menu = (AppendMenuW_Proc) GetProcAddress (user32, "AppendMenuW"); 1612 set_menu_item_info = (SetMenuItemInfoA_Proc)
1613 unicode_message_box = (MessageBoxW_Proc) GetProcAddress (user32, "MessageBoxW"); 1613 get_proc_addr (user32, "SetMenuItemInfoA");
1614 unicode_append_menu = (AppendMenuW_Proc)
1615 get_proc_addr (user32, "AppendMenuW");
1616 unicode_message_box = (MessageBoxW_Proc)
1617 get_proc_addr (user32, "MessageBoxW");
1614#endif /* !NTGUI_UNICODE */ 1618#endif /* !NTGUI_UNICODE */
1615} 1619}
diff --git a/src/w32proc.c b/src/w32proc.c
index 61ce157b558..5c2cb327495 100644
--- a/src/w32proc.c
+++ b/src/w32proc.c
@@ -548,9 +548,8 @@ init_timers (void)
548 through a pointer. */ 548 through a pointer. */
549 s_pfn_Get_Thread_Times = NULL; /* in case dumped Emacs comes with a value */ 549 s_pfn_Get_Thread_Times = NULL; /* in case dumped Emacs comes with a value */
550 if (os_subtype != OS_9X) 550 if (os_subtype != OS_9X)
551 s_pfn_Get_Thread_Times = 551 s_pfn_Get_Thread_Times = (GetThreadTimes_Proc)
552 (GetThreadTimes_Proc)GetProcAddress (GetModuleHandle ("kernel32.dll"), 552 get_proc_addr (GetModuleHandle ("kernel32.dll"), "GetThreadTimes");
553 "GetThreadTimes");
554 553
555 /* Make sure we start with zeroed out itimer structures, since 554 /* Make sure we start with zeroed out itimer structures, since
556 dumping may have left there traces of threads long dead. */ 555 dumping may have left there traces of threads long dead. */
@@ -2691,8 +2690,8 @@ sys_kill (pid_t pid, int sig)
2691 { 2690 {
2692 g_b_init_debug_break_process = 1; 2691 g_b_init_debug_break_process = 1;
2693 s_pfn_Debug_Break_Process = (DebugBreakProcess_Proc) 2692 s_pfn_Debug_Break_Process = (DebugBreakProcess_Proc)
2694 GetProcAddress (GetModuleHandle ("kernel32.dll"), 2693 get_proc_addr (GetModuleHandle ("kernel32.dll"),
2695 "DebugBreakProcess"); 2694 "DebugBreakProcess");
2696 } 2695 }
2697 2696
2698 if (s_pfn_Debug_Break_Process == NULL) 2697 if (s_pfn_Debug_Break_Process == NULL)
@@ -3608,9 +3607,9 @@ w32_compare_strings (const char *s1, const char *s2, char *locname,
3608 { 3607 {
3609 if (os_subtype == OS_9X) 3608 if (os_subtype == OS_9X)
3610 { 3609 {
3611 pCompareStringW = 3610 pCompareStringW = (CompareStringW_Proc)
3612 (CompareStringW_Proc) GetProcAddress (LoadLibrary ("Unicows.dll"), 3611 get_proc_addr (LoadLibrary ("Unicows.dll"),
3613 "CompareStringW"); 3612 "CompareStringW");
3614 if (!pCompareStringW) 3613 if (!pCompareStringW)
3615 { 3614 {
3616 errno = EINVAL; 3615 errno = EINVAL;
diff --git a/src/w32uniscribe.c b/src/w32uniscribe.c
index 11bfa5490b8..54f161690b7 100644
--- a/src/w32uniscribe.c
+++ b/src/w32uniscribe.c
@@ -1194,11 +1194,11 @@ syms_of_w32uniscribe (void)
1194 register_font_driver (&uniscribe_font_driver, NULL); 1194 register_font_driver (&uniscribe_font_driver, NULL);
1195 1195
1196 script_get_font_scripts_fn = (ScriptGetFontScriptTags_Proc) 1196 script_get_font_scripts_fn = (ScriptGetFontScriptTags_Proc)
1197 GetProcAddress (uniscribe, "ScriptGetFontScriptTags"); 1197 get_proc_addr (uniscribe, "ScriptGetFontScriptTags");
1198 script_get_font_languages_fn = (ScriptGetFontLanguageTags_Proc) 1198 script_get_font_languages_fn = (ScriptGetFontLanguageTags_Proc)
1199 GetProcAddress (uniscribe, "ScriptGetFontLanguageTags"); 1199 get_proc_addr (uniscribe, "ScriptGetFontLanguageTags");
1200 script_get_font_features_fn = (ScriptGetFontFeatureTags_Proc) 1200 script_get_font_features_fn = (ScriptGetFontFeatureTags_Proc)
1201 GetProcAddress (uniscribe, "ScriptGetFontFeatureTags"); 1201 get_proc_addr (uniscribe, "ScriptGetFontFeatureTags");
1202 if (script_get_font_scripts_fn 1202 if (script_get_font_scripts_fn
1203 && script_get_font_languages_fn 1203 && script_get_font_languages_fn
1204 && script_get_font_features_fn) 1204 && script_get_font_features_fn)