Added LoadLibraryX and LoadLibraryExX

These functions take a UTF8 string and load a library with
LoadLibraryW under windows.
This commit is contained in:
Armin Novak 2021-08-25 16:34:35 +02:00 committed by akallabeth
parent a485306c9e
commit fbae9ba88c
6 changed files with 46 additions and 4 deletions

View File

@ -215,7 +215,7 @@ PVIRTUALCHANNELENTRY freerdp_load_dynamic_addin(LPCSTR pszFileName, LPCSTR pszPa
else
pszFilePath = _strdup(pszRelativeFilePath);
library = LoadLibraryA(pszFilePath);
library = LoadLibraryX(pszFilePath);
if (!library)
goto fail;

View File

@ -1021,7 +1021,7 @@ static int nla_server_init(rdpNla* nla)
{
HMODULE hSSPI;
INIT_SECURITY_INTERFACE pInitSecurityInterface;
hSSPI = LoadLibrary(nla->SspiModule);
hSSPI = LoadLibraryX(nla->SspiModule);
if (!hSSPI)
{

View File

@ -73,6 +73,18 @@ extern "C"
#endif
#ifdef __cplusplus
extern "C"
{
#endif
WINPR_API HMODULE LoadLibraryX(LPCSTR lpLibFileName);
WINPR_API HMODULE LoadLibraryExX(LPCSTR lpLibFileName, HANDLE hFile, DWORD dwFlags);
#ifdef __cplusplus
}
#endif
#if !defined(_WIN32) && !defined(__CYGWIN__)
#ifdef __cplusplus

View File

@ -343,3 +343,33 @@ DWORD GetModuleFileNameA(HMODULE hModule, LPSTR lpFilename, DWORD nSize)
}
#endif
HMODULE LoadLibraryX(LPCSTR lpLibFileName)
{
#if defined(_WIN32)
HMODULE hm = NULL;
WCHAR* wstr = NULL;
int rc = ConvertToUnicode(CP_UTF8, 0, lpLibFileName, -1, &wstr, 0);
if (rc > 0)
hm = LoadLibraryW(wstr);
free(wstr);
return hm;
#else
return LoadLibraryA(lpLibFileName);
#endif
}
HMODULE LoadLibraryExX(LPCSTR lpLibFileName, HANDLE hFile, DWORD dwFlags)
{
#if defined(_WIN32)
HMODULE hm = NULL;
WCHAR* wstr = NULL;
int rc = ConvertToUnicode(CP_UTF8, 0, lpLibFileName, -1, &wstr, 0);
if (rc > 0)
hm = LoadLibraryExW(wstr, hFile, dwFlags);
free(wstr);
return hm;
#else
return LoadLibraryExA(lpLibFileName, hFile, dwFlags);
#endif
}

View File

@ -3178,7 +3178,7 @@ int PCSC_InitializeSCardApi(void)
/* Disable pcsc-lite's (poor) blocking so we can handle it ourselves */
SetEnvironmentVariableA("PCSCLITE_NO_BLOCKING", "1");
#ifdef __MACOSX__
g_PCSCModule = LoadLibraryA("/System/Library/Frameworks/PCSC.framework/PCSC");
g_PCSCModule = LoadLibraryX("/System/Library/Frameworks/PCSC.framework/PCSC");
OSXVersion = determineMacOSXVersion();
if (OSXVersion == 0)

View File

@ -688,7 +688,7 @@ BOOL WTSRegisterWtsApiFunctionTable(const WtsApiFunctionTable* table)
static BOOL LoadAndInitialize(char* library)
{
INIT_WTSAPI_FN pInitWtsApi;
g_WtsApiModule = LoadLibraryA(library);
g_WtsApiModule = LoadLibraryX(library);
if (!g_WtsApiModule)
return FALSE;