-
I want to search for and find a DLL from the system's environment variables path, but it's not working. The exact same code works fine on the MFC side. Why doesn't it work in WinUI3? I'm trying to use LoadLibrary, but it fails with error code 126. size_t sz = 0;
if (_wgetenv_s(&sz, NULL, 0, L"MY_PATH") == 0 && sz > 0)
{
// Allocate buffer to store the value of "MY_PATH"
std::vector<wchar_t> env_mypath(sz);
if (_wgetenv_s(&sz, env_mypath.data(), sz, L"MY_PATH") == 0)
{
if (_wgetenv_s(&sz, NULL, 0, L"PATH") == 0 && sz > 0)
{
std::vector<wchar_t> env_path(sz);
if (_wgetenv_s(&sz, env_path.data(), sz, L"PATH") == 0)
{
std::wstring my_path(env_mypath.data());
my_path.append(L"\\api\\lib\\x86_64");
std::wstring path_var(env_path.data());
path_var.append(L";").append(my_path);
_wputenv_s(L"PATH", path_var.c_str());
}
}
}
}
auto module_ = ::LoadLibraryA( "mySDK.dll" );
DWORD ret = GetLastError(); // 126 ERROR_MOD_NOT_FOUND |
Beta Was this translation helpful? Give feedback.
Answered by
whiskhub
Mar 3, 2025
Replies: 1 comment 1 reply
-
The DLL search order is different for packaged apps: https://learn.microsoft.com/en-us/windows/win32/dlls/dynamic-link-library-search-order#search-order-for-packaged-apps |
Beta Was this translation helpful? Give feedback.
1 reply
Answer selected by
hamu777
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
The DLL search order is different for packaged apps: https://learn.microsoft.com/en-us/windows/win32/dlls/dynamic-link-library-search-order#search-order-for-packaged-apps