diff --git a/client/Windows/wf_client.c b/client/Windows/wf_client.c index b23fa1f05..68080b3d9 100644 --- a/client/Windows/wf_client.c +++ b/client/Windows/wf_client.c @@ -22,6 +22,7 @@ #include #include +#include #include #include @@ -1396,9 +1397,9 @@ static int wfreerdp_client_start(rdpContext* context) if (module) { GetDpiForWindow_t pGetDpiForWindow = - (GetDpiForWindow_t)GetProcAddress(module, "GetDpiForWindow"); + GetProcAddressAs(module, "GetDpiForWindow", GetDpiForWindow_t); SetProcessDPIAware_t pSetProcessDPIAware = - (SetProcessDPIAware_t)GetProcAddress(module, "SetProcessDPIAware"); + GetProcAddressAs(module, "SetProcessDPIAware", SetProcessDPIAware_t); if (pGetDpiForWindow && pSetProcessDPIAware) { const UINT dpiAwareness = pGetDpiForWindow(hWndParent); diff --git a/client/Windows/wf_cliprdr.c b/client/Windows/wf_cliprdr.c index fb2065e82..97218ac1f 100644 --- a/client/Windows/wf_cliprdr.c +++ b/client/Windows/wf_cliprdr.c @@ -31,6 +31,7 @@ #include #include +#include #include #include @@ -2473,12 +2474,12 @@ BOOL wf_cliprdr_init(wfContext* wfc, CliprdrClientContext* cliprdr) if (clipboard->hUser32) { - clipboard->AddClipboardFormatListener = (fnAddClipboardFormatListener)GetProcAddress( - clipboard->hUser32, "AddClipboardFormatListener"); - clipboard->RemoveClipboardFormatListener = (fnRemoveClipboardFormatListener)GetProcAddress( - clipboard->hUser32, "RemoveClipboardFormatListener"); - clipboard->GetUpdatedClipboardFormats = (fnGetUpdatedClipboardFormats)GetProcAddress( - clipboard->hUser32, "GetUpdatedClipboardFormats"); + clipboard->AddClipboardFormatListener = GetProcAddressAs( + clipboard->hUser32, "AddClipboardFormatListener", fnAddClipboardFormatListener); + clipboard->RemoveClipboardFormatListener = GetProcAddressAs( + clipboard->hUser32, "RemoveClipboardFormatListener", fnRemoveClipboardFormatListener); + clipboard->GetUpdatedClipboardFormats = GetProcAddressAs( + clipboard->hUser32, "GetUpdatedClipboardFormats", fnGetUpdatedClipboardFormats); } if (!(clipboard->hUser32 && clipboard->AddClipboardFormatListener && diff --git a/libfreerdp/codec/h264_mf.c b/libfreerdp/codec/h264_mf.c index b5e65f5f1..978d62d2b 100644 --- a/libfreerdp/codec/h264_mf.c +++ b/libfreerdp/codec/h264_mf.c @@ -17,6 +17,7 @@ * limitations under the License. */ +#include #include #include @@ -466,12 +467,13 @@ static BOOL mf_init(H264_CONTEXT* h264) if (!sys->mfplat) goto error; - sys->MFStartup = (pfnMFStartup)GetProcAddress(sys->mfplat, "MFStartup"); - sys->MFShutdown = (pfnMFShutdown)GetProcAddress(sys->mfplat, "MFShutdown"); - sys->MFCreateSample = (pfnMFCreateSample)GetProcAddress(sys->mfplat, "MFCreateSample"); + sys->MFStartup = GetProcAddressAs(sys->mfplat, "MFStartup", pfnMFStartup); + sys->MFShutdown = GetProcAddressAs(sys->mfplat, "MFShutdown", pfnMFShutdown); + sys->MFCreateSample = GetProcAddressAs(sys->mfplat, "MFCreateSample", pfnMFCreateSample); sys->MFCreateMemoryBuffer = - (pfnMFCreateMemoryBuffer)GetProcAddress(sys->mfplat, "MFCreateMemoryBuffer"); - sys->MFCreateMediaType = (pfnMFCreateMediaType)GetProcAddress(sys->mfplat, "MFCreateMediaType"); + GetProcAddressAs(sys->mfplat, "MFCreateMemoryBuffer", pfnMFCreateMemoryBuffer); + sys->MFCreateMediaType = + GetProcAddressAs(sys->mfplat, "MFCreateMediaType", pfnMFCreateMediaType); if (!mf_plat_loaded(sys)) goto error; diff --git a/libfreerdp/codec/h264_openh264.c b/libfreerdp/codec/h264_openh264.c index 2823e55f9..4d1508013 100644 --- a/libfreerdp/codec/h264_openh264.c +++ b/libfreerdp/codec/h264_openh264.c @@ -467,15 +467,15 @@ static BOOL openh264_load_functionpointers(H264_CONTEXT* h264, const char* name) return FALSE; sysContexts->WelsGetCodecVersionEx = - (pWelsGetCodecVersionEx)GetProcAddress(sysContexts->lib, "WelsGetCodecVersionEx"); + GetProcAddressAs(sysContexts->lib, "WelsGetCodecVersionEx", pWelsGetCodecVersionEx); sysContexts->WelsCreateDecoder = - (pWelsCreateDecoder)GetProcAddress(sysContexts->lib, "WelsCreateDecoder"); + GetProcAddressAs(sysContexts->lib, "WelsCreateDecoder", pWelsCreateDecoder); sysContexts->WelsDestroyDecoder = - (pWelsDestroyDecoder)GetProcAddress(sysContexts->lib, "WelsDestroyDecoder"); + GetProcAddressAs(sysContexts->lib, "WelsDestroyDecoder", pWelsDestroyDecoder); sysContexts->WelsCreateSVCEncoder = - (pWelsCreateSVCEncoder)GetProcAddress(sysContexts->lib, "WelsCreateSVCEncoder"); + GetProcAddressAs(sysContexts->lib, "WelsCreateSVCEncoder", pWelsCreateSVCEncoder); sysContexts->WelsDestroySVCEncoder = - (pWelsDestroySVCEncoder)GetProcAddress(sysContexts->lib, "WelsDestroySVCEncoder"); + GetProcAddressAs(sysContexts->lib, "WelsDestroySVCEncoder", pWelsDestroySVCEncoder); if (!sysContexts->WelsCreateDecoder || !sysContexts->WelsDestroyDecoder || !sysContexts->WelsCreateSVCEncoder || !sysContexts->WelsDestroySVCEncoder || diff --git a/libfreerdp/common/addin.c b/libfreerdp/common/addin.c index d07e20880..d15fb1ff4 100644 --- a/libfreerdp/common/addin.c +++ b/libfreerdp/common/addin.c @@ -237,8 +237,7 @@ PVIRTUALCHANNELENTRY freerdp_load_dynamic_addin(LPCSTR pszFileName, LPCSTR pszPa if (!library) goto fail; - FARPROC fp = GetProcAddress(library, pszEntryName); - entry = WINPR_FUNC_PTR_CAST(fp, PVIRTUALCHANNELENTRY); + entry = GetProcAddressAs(library, pszEntryName, PVIRTUALCHANNELENTRY); fail: free(pszRelativeFilePath); free(pszAddinFile); diff --git a/libfreerdp/core/childsession.c b/libfreerdp/core/childsession.c index c03370175..07acca864 100644 --- a/libfreerdp/core/childsession.c +++ b/libfreerdp/core/childsession.c @@ -470,9 +470,8 @@ static BOOL createChildSessionTransport(HANDLE* pFile) WCHAR pipePath[0x80] = { 0 }; char pipePathA[0x80] = { 0 }; - FARPROC fp = GetProcAddress(hModule, "WinStationCreateChildSessionTransport"); - WinStationCreateChildSessionTransportFn createChildSessionFn = - WINPR_FUNC_PTR_CAST(fp, WinStationCreateChildSessionTransportFn); + WinStationCreateChildSessionTransportFn createChildSessionFn = GetProcAddressAs( + hModule, "WinStationCreateChildSessionTransport", WinStationCreateChildSessionTransportFn); if (!createChildSessionFn) { WLog_ERR(TAG, "unable to retrieve WinStationCreateChildSessionTransport function"); diff --git a/libfreerdp/core/credssp_auth.c b/libfreerdp/core/credssp_auth.c index de979fe09..ccbbb36ee 100644 --- a/libfreerdp/core/credssp_auth.c +++ b/libfreerdp/core/credssp_auth.c @@ -814,9 +814,8 @@ static SecurityFunctionTable* auth_resolve_sspi_table(const rdpSettings* setting WLog_INFO(TAG, "Using SSPI Module: %s", module_name); - FARPROC fp = GetProcAddress(hSSPI, proc_name); INIT_SECURITY_INTERFACE InitSecurityInterface_ptr = - WINPR_FUNC_PTR_CAST(fp, INIT_SECURITY_INTERFACE); + GetProcAddressAs(hSSPI, proc_name, INIT_SECURITY_INTERFACE); if (!InitSecurityInterface_ptr) { WLog_ERR(TAG, "Failed to load SSPI module: %s, no function %s", module_name, proc_name); diff --git a/server/proxy/pf_modules.c b/server/proxy/pf_modules.c index 2c5c32bf9..9ae969cbb 100644 --- a/server/proxy/pf_modules.c +++ b/server/proxy/pf_modules.c @@ -491,8 +491,8 @@ static BOOL pf_modules_load_module(const char* module_path, proxyModule* module, return FALSE; } - FARPROC fp = GetProcAddress(handle, MODULE_ENTRY_POINT); - proxyModuleEntryPoint pEntryPoint = WINPR_FUNC_PTR_CAST(fp, proxyModuleEntryPoint); + proxyModuleEntryPoint pEntryPoint = + GetProcAddressAs(handle, MODULE_ENTRY_POINT, proxyModuleEntryPoint); if (!pEntryPoint) { WLog_ERR(TAG, "GetProcAddress failed while loading %s", module_path); diff --git a/server/shadow/Win/win_dxgi.c b/server/shadow/Win/win_dxgi.c index 3c25a007a..9ea8e2bc5 100644 --- a/server/shadow/Win/win_dxgi.c +++ b/server/shadow/Win/win_dxgi.c @@ -20,6 +20,7 @@ #include #include +#include #include #include "win_dxgi.h" @@ -288,7 +289,7 @@ static void win_shadow_d3d11_module_init() if (!d3d11_module) return; - pfnD3D11CreateDevice = (fnD3D11CreateDevice)GetProcAddress(d3d11_module, "D3D11CreateDevice"); + pfnD3D11CreateDevice = GetProcAddressAs(d3d11_module, "D3D11CreateDevice", fnD3D11CreateDevice); } int win_shadow_dxgi_init_duplication(winShadowSubsystem* subsystem) diff --git a/winpr/include/winpr/library.h b/winpr/include/winpr/library.h index 8cdd6db4a..718d97b69 100644 --- a/winpr/include/winpr/library.h +++ b/winpr/include/winpr/library.h @@ -85,6 +85,8 @@ extern "C" } #endif +#define GetProcAddressAs(module, name, type) WINPR_FUNC_PTR_CAST(GetProcAddress(module, name), type) + #if !defined(_WIN32) && !defined(__CYGWIN__) #ifdef __cplusplus diff --git a/winpr/include/winpr/winpr.h b/winpr/include/winpr/winpr.h index fc3da4125..9303c9079 100644 --- a/winpr/include/winpr/winpr.h +++ b/winpr/include/winpr/winpr.h @@ -160,7 +160,7 @@ WINPR_API const char* winpr_get_build_config(void); }) #else #define WINPR_CAST_CONST_PTR_AWAY(ptr, dstType) (dstType) ptr -#define WINPR_CONST_PTR_AWAY_CAST(ptr, dstType) (dstType)(uintptr_t) ptr +#define WINPR_FUNC_PTR_CAST(ptr, dstType) (dstType)(uintptr_t) ptr #endif #endif /* WINPR_H */ diff --git a/winpr/libwinpr/library/test/TestLibraryGetProcAddress.c b/winpr/libwinpr/library/test/TestLibraryGetProcAddress.c index 7bfdfabdb..59085b97e 100644 --- a/winpr/libwinpr/library/test/TestLibraryGetProcAddress.c +++ b/winpr/libwinpr/library/test/TestLibraryGetProcAddress.c @@ -47,13 +47,13 @@ int TestLibraryGetProcAddress(int argc, char* argv[]) return -1; } - if (!(pFunctionA = WINPR_FUNC_PTR_CAST(GetProcAddress(library, "FunctionA"), TEST_AB_FN))) + if (!(pFunctionA = GetProcAddressAs(library, "FunctionA", TEST_AB_FN))) { printf("%s: GetProcAddress failure (FunctionA)\n", __func__); return -1; } - if (!(pFunctionB = WINPR_FUNC_PTR_CAST(GetProcAddress(library, "FunctionB"), TEST_AB_FN))) + if (!(pFunctionB = GetProcAddressAs(library, "FunctionB", TEST_AB_FN))) { printf("%s: GetProcAddress failure (FunctionB)\n", __func__); return -1; diff --git a/winpr/libwinpr/ncrypt/ncrypt.c b/winpr/libwinpr/ncrypt/ncrypt.c index 87d8cb892..c3fb7584e 100644 --- a/winpr/libwinpr/ncrypt/ncrypt.c +++ b/winpr/libwinpr/ncrypt/ncrypt.c @@ -18,6 +18,7 @@ */ #include +#include #include #ifndef _WIN32 @@ -272,10 +273,9 @@ SECURITY_STATUS winpr_NCryptOpenStorageProviderEx(NCRYPT_PROV_HANDLE* phProvider if (!lib) return NTE_PROV_DLL_NOT_FOUND; - FARPROC fp = GetProcAddress(lib, "NCryptOpenStorageProvider"); NCryptOpenStorageProviderFn ncryptOpenStorageProviderFn = - WINPR_FUNC_PTR_CAST(fp, NCryptOpenStorageProviderFn); - (NCryptOpenStorageProviderFn) if (!ncryptOpenStorageProviderFn) + GetProcAddressAs(lib, "NCryptOpenStorageProvider", NCryptOpenStorageProviderFn); + if (!ncryptOpenStorageProviderFn) { ret = NTE_PROV_DLL_NOT_FOUND; goto out_free_lib; diff --git a/winpr/libwinpr/ncrypt/ncrypt_pkcs11.c b/winpr/libwinpr/ncrypt/ncrypt_pkcs11.c index 4a7d48741..c607f62b1 100644 --- a/winpr/libwinpr/ncrypt/ncrypt_pkcs11.c +++ b/winpr/libwinpr/ncrypt/ncrypt_pkcs11.c @@ -1261,8 +1261,8 @@ SECURITY_STATUS NCryptOpenP11StorageProviderEx(NCRYPT_PROV_HANDLE* phProvider, goto out_load_library; } - FARPROC fp = GetProcAddress(library, "C_GetFunctionList"); - c_get_function_list_t c_get_function_list = WINPR_FUNC_PTR_CAST(fp, c_get_function_list_t); + c_get_function_list_t c_get_function_list = + GetProcAddressAs(library, "C_GetFunctionList", c_get_function_list_t); if (!c_get_function_list) { diff --git a/winpr/libwinpr/pool/callback.c b/winpr/libwinpr/pool/callback.c index d4ac8a641..46c160574 100644 --- a/winpr/libwinpr/pool/callback.c +++ b/winpr/libwinpr/pool/callback.c @@ -34,10 +34,8 @@ static BOOL CALLBACK init_module(PINIT_ONCE once, PVOID param, PVOID* context) { HMODULE kernel32 = LoadLibraryA("kernel32.dll"); if (kernel32) - { - FARPROC fp = GetProcAddress(kernel32, "CallbackMayRunLong"); - pCallbackMayRunLong = WINPR_FUNC_PTR_CAST(fp, pCallbackMayRunLong_t); - } + pCallbackMayRunLong = + GetProcAddressAs(kernel32, "CallbackMayRunLong", pCallbackMayRunLong_t); return TRUE; } #endif diff --git a/winpr/libwinpr/pool/callback_cleanup.c b/winpr/libwinpr/pool/callback_cleanup.c index a4a24db1c..068a34612 100644 --- a/winpr/libwinpr/pool/callback_cleanup.c +++ b/winpr/libwinpr/pool/callback_cleanup.c @@ -44,17 +44,17 @@ static BOOL CALLBACK init_module(PINIT_ONCE once, PVOID param, PVOID* context) if (kernel32) { pSetEventWhenCallbackReturns = - (void*)GetProcAddress(kernel32, "SetEventWhenCallbackReturns"); + GetProcAddressAs(kernel32, "SetEventWhenCallbackReturns"), void*); pReleaseSemaphoreWhenCallbackReturns = - (void*)GetProcAddress(kernel32, "ReleaseSemaphoreWhenCallbackReturns"); + GetProcAddressAs(kernel32, "ReleaseSemaphoreWhenCallbackReturns", void*); pReleaseMutexWhenCallbackReturns = - (void*)GetProcAddress(kernel32, "ReleaseMutexWhenCallbackReturns"); + GetProcAddressAs(kernel32, "ReleaseMutexWhenCallbackReturns", void*); pLeaveCriticalSectionWhenCallbackReturns = - (void*)GetProcAddress(kernel32, "LeaveCriticalSectionWhenCallbackReturns"); + GetProcAddressAs(kernel32, "LeaveCriticalSectionWhenCallbackReturns", void*); pFreeLibraryWhenCallbackReturns = - (void*)GetProcAddress(kernel32, "FreeLibraryWhenCallbackReturns"); + GetProcAddressAs(kernel32, "FreeLibraryWhenCallbackReturns", void*); pDisassociateCurrentThreadFromCallback = - (void*)GetProcAddress(kernel32, "DisassociateCurrentThreadFromCallback"); + GetProcAddressAs(kernel32, "DisassociateCurrentThreadFromCallback", void*); } return TRUE; } diff --git a/winpr/libwinpr/pool/cleanup_group.c b/winpr/libwinpr/pool/cleanup_group.c index 9c2569c3d..50b68e20d 100644 --- a/winpr/libwinpr/pool/cleanup_group.c +++ b/winpr/libwinpr/pool/cleanup_group.c @@ -19,6 +19,7 @@ #include +#include #include #include #include @@ -42,11 +43,11 @@ static BOOL CALLBACK init_module(PINIT_ONCE once, PVOID param, PVOID* context) if (kernel32) { pCreateThreadpoolCleanupGroup = - (void*)GetProcAddress(kernel32, "CreateThreadpoolCleanupGroup"); + GetProcAddressAs(kernel32, "CreateThreadpoolCleanupGroup", void*); pCloseThreadpoolCleanupGroupMembers = - (void*)GetProcAddress(kernel32, "CloseThreadpoolCleanupGroupMembers"); + GetProcAddressAs(kernel32, "CloseThreadpoolCleanupGroupMembers", void*); pCloseThreadpoolCleanupGroup = - (void*)GetProcAddress(kernel32, "CloseThreadpoolCleanupGroup"); + GetProcAddressAs(kernel32, "CloseThreadpoolCleanupGroup", void*); } return TRUE; diff --git a/winpr/libwinpr/pool/pool.c b/winpr/libwinpr/pool/pool.c index 80c483347..a4c285dee 100644 --- a/winpr/libwinpr/pool/pool.c +++ b/winpr/libwinpr/pool/pool.c @@ -40,10 +40,12 @@ static BOOL CALLBACK init_module(PINIT_ONCE once, PVOID param, PVOID* context) HMODULE kernel32 = LoadLibraryA("kernel32.dll"); if (kernel32) { - pCreateThreadpool = (void*)GetProcAddress(kernel32, "CreateThreadpool"); - pCloseThreadpool = (void*)GetProcAddress(kernel32, "CloseThreadpool"); - pSetThreadpoolThreadMinimum = (void*)GetProcAddress(kernel32, "SetThreadpoolThreadMinimum"); - pSetThreadpoolThreadMaximum = (void*)GetProcAddress(kernel32, "SetThreadpoolThreadMaximum"); + pCreateThreadpool = GetProcAddressAs(kernel32, "CreateThreadpool", void*); + pCloseThreadpool = GetProcAddressAs(kernel32, "CloseThreadpool", void*); + pSetThreadpoolThreadMinimum = + GetProcAddressAs(kernel32, "SetThreadpoolThreadMinimum", void*); + pSetThreadpoolThreadMaximum = + GetProcAddressAs(kernel32, "SetThreadpoolThreadMaximum", void*); } return TRUE; } diff --git a/winpr/libwinpr/pool/work.c b/winpr/libwinpr/pool/work.c index e83f41736..0fd2e65c4 100644 --- a/winpr/libwinpr/pool/work.c +++ b/winpr/libwinpr/pool/work.c @@ -46,13 +46,13 @@ static BOOL CALLBACK init_module(PINIT_ONCE once, PVOID param, PVOID* context) if (kernel32) { - pCreateThreadpoolWork = (void*)GetProcAddress(kernel32, "CreateThreadpoolWork"); - pCloseThreadpoolWork = (void*)GetProcAddress(kernel32, "CloseThreadpoolWork"); - pSubmitThreadpoolWork = (void*)GetProcAddress(kernel32, "SubmitThreadpoolWork"); + pCreateThreadpoolWork = GetProcAddressAs(kernel32, "CreateThreadpoolWork", void*); + pCloseThreadpoolWork = GetProcAddressAs(kernel32, "CloseThreadpoolWork", void*); + pSubmitThreadpoolWork = GetProcAddressAs(kernel32, "SubmitThreadpoolWork", void*); pTrySubmitThreadpoolCallback = - (void*)GetProcAddress(kernel32, "TrySubmitThreadpoolCallback"); + GetProcAddressAs(kernel32, "TrySubmitThreadpoolCallback", void*); pWaitForThreadpoolWorkCallbacks = - (void*)GetProcAddress(kernel32, "WaitForThreadpoolWorkCallbacks"); + GetProcAddressAs(kernel32, "WaitForThreadpoolWorkCallbacks", void*); } return TRUE; diff --git a/winpr/libwinpr/smartcard/smartcard.c b/winpr/libwinpr/smartcard/smartcard.c index 4979c537b..480572150 100644 --- a/winpr/libwinpr/smartcard/smartcard.c +++ b/winpr/libwinpr/smartcard/smartcard.c @@ -1100,14 +1100,13 @@ WINSCARDAPI char* WINAPI SCardGetReaderStateString(DWORD dwReaderState) return buffer; } -#define WINSCARD_LOAD_PROC(_name, ...) \ - do \ - { \ - WINPR_PRAGMA_DIAG_PUSH \ - WINPR_PRAGMA_DIAG_IGNORED_PEDANTIC \ - FARPROC fp = GetProcAddress(hWinSCardLibrary, #_name); \ - pWinSCardApiTable->pfn##_name = WINPR_FUNC_PTR_CAST(fp, fn##_name); \ - WINPR_PRAGMA_DIAG_POP \ +#define WINSCARD_LOAD_PROC(_name, ...) \ + do \ + { \ + WINPR_PRAGMA_DIAG_PUSH \ + WINPR_PRAGMA_DIAG_IGNORED_PEDANTIC \ + pWinSCardApiTable->pfn##_name = GetProcAddressAs(hWinSCardLibrary, #_name, fn##_name); \ + WINPR_PRAGMA_DIAG_POP \ } while (0) BOOL WinSCard_LoadApiTableFunctions(PSCardApiFunctionTable pWinSCardApiTable, diff --git a/winpr/libwinpr/smartcard/smartcard_pcsc.c b/winpr/libwinpr/smartcard/smartcard_pcsc.c index 297b014c5..239f309d5 100644 --- a/winpr/libwinpr/smartcard/smartcard_pcsc.c +++ b/winpr/libwinpr/smartcard/smartcard_pcsc.c @@ -48,13 +48,13 @@ #include "../log.h" #define TAG WINPR_TAG("smartcard") -#define WINSCARD_LOAD_PROC_EX(module, pcsc, _fname, _name, ...) \ - do \ - { \ - WINPR_PRAGMA_DIAG_PUSH \ - WINPR_PRAGMA_DIAG_IGNORED_PEDANTIC \ - pcsc.pfn##_fname = WINPR_FUNC_PTR_CAST(GetProcAddress(module, #_name), fnPCSC##_fname); \ - WINPR_PRAGMA_DIAG_POP \ +#define WINSCARD_LOAD_PROC_EX(module, pcsc, _fname, _name, ...) \ + do \ + { \ + WINPR_PRAGMA_DIAG_PUSH \ + WINPR_PRAGMA_DIAG_IGNORED_PEDANTIC \ + pcsc.pfn##_fname = GetProcAddressAs(module, #_name, fnPCSC##_fname); \ + WINPR_PRAGMA_DIAG_POP \ } while (0) #define WINSCARD_LOAD_PROC(module, pcsc, _name, ...) \ diff --git a/winpr/libwinpr/sspi/sspi.c b/winpr/libwinpr/sspi/sspi.c index dbfa817e1..b9843d023 100644 --- a/winpr/libwinpr/sspi/sspi.c +++ b/winpr/libwinpr/sspi/sspi.c @@ -107,10 +107,10 @@ BOOL InitializeSspiModule_Native(void) if (!g_SspiModule) return FALSE; - pInitSecurityInterfaceW = WINPR_FUNC_PTR_CAST( - GetProcAddress(g_SspiModule, "InitSecurityInterfaceW"), INIT_SECURITY_INTERFACE_W); - pInitSecurityInterfaceA = WINPR_FUNC_PTR_CAST( - GetProcAddress(g_SspiModule, "InitSecurityInterfaceA"), INIT_SECURITY_INTERFACE_A); + pInitSecurityInterfaceW = + GetProcAddressAs(g_SspiModule, "InitSecurityInterfaceW", INIT_SECURITY_INTERFACE_W); + pInitSecurityInterfaceA = + GetProcAddressAs(g_SspiModule, "InitSecurityInterfaceA", INIT_SECURITY_INTERFACE_A); if (pInitSecurityInterfaceW) { @@ -124,12 +124,11 @@ BOOL InitializeSspiModule_Native(void) g_SspiW->dwVersion = SECURITY_SUPPORT_PROVIDER_INTERFACE_VERSION_3; - g_SspiW->SetContextAttributesW = WINPR_FUNC_PTR_CAST( - GetProcAddress(g_SspiModule, "SetContextAttributesW"), SET_CONTEXT_ATTRIBUTES_FN_W); + g_SspiW->SetContextAttributesW = GetProcAddressAs(g_SspiModule, "SetContextAttributesW", + SET_CONTEXT_ATTRIBUTES_FN_W); - g_SspiW->SetCredentialsAttributesW = - WINPR_FUNC_PTR_CAST(GetProcAddress(g_SspiModule, "SetCredentialsAttributesW"), - SET_CREDENTIALS_ATTRIBUTES_FN_W); + g_SspiW->SetCredentialsAttributesW = GetProcAddressAs( + g_SspiModule, "SetCredentialsAttributesW", SET_CREDENTIALS_ATTRIBUTES_FN_W); } } @@ -145,12 +144,11 @@ BOOL InitializeSspiModule_Native(void) g_SspiA->dwVersion = SECURITY_SUPPORT_PROVIDER_INTERFACE_VERSION_3; - g_SspiA->SetContextAttributesA = WINPR_FUNC_PTR_CAST( - GetProcAddress(g_SspiModule, "SetContextAttributesA"), SET_CONTEXT_ATTRIBUTES_FN_W); + g_SspiA->SetContextAttributesA = GetProcAddressAs(g_SspiModule, "SetContextAttributesA", + SET_CONTEXT_ATTRIBUTES_FN_W); - g_SspiA->SetCredentialsAttributesA = - WINPR_FUNC_PTR_CAST(GetProcAddress(g_SspiModule, "SetCredentialsAttributesA"), - SET_CREDENTIALS_ATTRIBUTES_FN_W); + g_SspiA->SetCredentialsAttributesA = GetProcAddressAs( + g_SspiModule, "SetCredentialsAttributesA", SET_CREDENTIALS_ATTRIBUTES_FN_W); } } diff --git a/winpr/libwinpr/synch/barrier.c b/winpr/libwinpr/synch/barrier.c index ec77be908..2b61a5918 100644 --- a/winpr/libwinpr/synch/barrier.c +++ b/winpr/libwinpr/synch/barrier.c @@ -67,17 +67,14 @@ static BOOL CALLBACK InitOnce_Barrier(PINIT_ONCE once, PVOID param, PVOID* conte if (!g_Kernel32) return TRUE; - pfnInitializeSynchronizationBarrier = (fnInitializeSynchronizationBarrier)GetProcAddress( - g_Kernel32, "InitializeSynchronizationBarrier"); + pfnInitializeSynchronizationBarrier = GetProcAddressAs( + g_Kernel32, "InitializeSynchronizationBarrier", fnInitializeSynchronizationBarrier); + + pfnEnterSynchronizationBarrier = + GetProcAddressAs(g_Kernel32, "EnterSynchronizationBarrier", fnEnterSynchronizationBarrier); + pfnDeleteSynchronizationBarrier = GetProcAddressAs(g_Kernel32, "DeleteSynchronizationBarrier", + fnDeleteSynchronizationBarrier); - { - FARPROC fp = GetProcAddress(g_Kernel32, "EnterSynchronizationBarrier"); - pfnEnterSynchronizationBarrier = WINPR_FUNC_PTR_CAST(fp, fnEnterSynchronizationBarrier); - } - { - FARPROC fp = GetProcAddress(g_Kernel32, "DeleteSynchronizationBarrier"); - pfnDeleteSynchronizationBarrier = WINPR_FUNC_PTR_CAST(fp, fnDeleteSynchronizationBarrier); - } if (pfnInitializeSynchronizationBarrier && pfnEnterSynchronizationBarrier && pfnDeleteSynchronizationBarrier) { diff --git a/winpr/libwinpr/wtsapi/wtsapi.c b/winpr/libwinpr/wtsapi/wtsapi.c index 7b481d718..ccd976a95 100644 --- a/winpr/libwinpr/wtsapi/wtsapi.c +++ b/winpr/libwinpr/wtsapi/wtsapi.c @@ -52,10 +52,10 @@ static WtsApiFunctionTable WtsApi32_WtsApiFunctionTable = { 0 }; #ifdef __MINGW32__ #define WTSAPI32_LOAD_PROC(NAME, TYPE) \ - WtsApi32_WtsApiFunctionTable.p##NAME = (TYPE)GetProcAddress(g_WtsApi32Module, "WTS" #NAME); + WtsApi32_WtsApiFunctionTable.p##NAME = GetProcAddressAs(g_WtsApi32Module, "WTS" #NAME, TYPE); #else #define WTSAPI32_LOAD_PROC(NAME, TYPE) \ - WtsApi32_WtsApiFunctionTable.p##NAME = (##TYPE)GetProcAddress(g_WtsApi32Module, "WTS" #NAME); + WtsApi32_WtsApiFunctionTable.p##NAME = GetProcAddressAs(g_WtsApi32Module, "WTS" #NAME, ##TYPE); #endif static BOOL WtsApi32_InitializeWtsApi(void) @@ -700,8 +700,7 @@ static BOOL LoadAndInitialize(char* library) if (!g_WtsApiModule) return FALSE; - FARPROC fp = GetProcAddress(g_WtsApiModule, "InitWtsApi"); - INIT_WTSAPI_FN pInitWtsApi = WINPR_FUNC_PTR_CAST(fp, INIT_WTSAPI_FN); + INIT_WTSAPI_FN pInitWtsApi = GetProcAddressAs(g_WtsApiModule, "InitWtsApi", INIT_WTSAPI_FN); if (!pInitWtsApi) return FALSE; diff --git a/winpr/libwinpr/wtsapi/wtsapi_win32.c b/winpr/libwinpr/wtsapi/wtsapi_win32.c index cac1624c0..0be7d0bce 100644 --- a/winpr/libwinpr/wtsapi/wtsapi_win32.c +++ b/winpr/libwinpr/wtsapi/wtsapi_win32.c @@ -785,9 +785,9 @@ BOOL Win32_InitializeWinSta(PWtsApiFunctionTable pWtsApi) return FALSE; pfnWinStationVirtualOpen = - (fnWinStationVirtualOpen)GetProcAddress(g_WinStaModule, "WinStationVirtualOpen"); + GetProcAddressAs(g_WinStaModule, "WinStationVirtualOpen", fnWinStationVirtualOpen); pfnWinStationVirtualOpenEx = - (fnWinStationVirtualOpenEx)GetProcAddress(g_WinStaModule, "WinStationVirtualOpenEx"); + GetProcAddressAs(g_WinStaModule, "WinStationVirtualOpenEx", fnWinStationVirtualOpenEx); if (!pfnWinStationVirtualOpen | !pfnWinStationVirtualOpenEx) return FALSE;