I am trying to use the SDK in a WinUI 3 C++ application. When using the SDK, LoadLibrary inside the SDK fails. During debugging, I examined the process and found that calling LoadLibraryExA as a test successfully loaded the DLL. However, I don't understand why LoadLibraryA fails. What could be the possible reasons for this failure? How can I ensure that the SDK can properly load its DLL? It worked well with MFC, but it doesn't seem to work well with WinUI 3.
- LoadLibraryA failed to load DLL. LoadLibraryA fails even with a full path.
- the full path is specified, LoadLibraryExA loads the main DLL successfully.
- Running the application as administrator does not resolve the problem.
I suspect that _wputenv_s may not be setting the environment variable correctly, and the search path is not being added. However, I am unsure how to resolve this issue.
Any help would be appreciated.
IDS_PEAK_GENERIC_SDK_PATH : C:\Program Files\IDS\ids_peak\generic_sdk
.cpp
// LoadLibraryExA succeeds
HMODULE module2 = LoadLibraryExA(
"C:\\Program Files\\IDS\\ids_peak\\generic_sdk\\api\\lib\\x86_64\\ids_peak.dll",
NULL,
LOAD_WITH_ALTERED_SEARCH_PATH
);
size_t sz = 0;
if (_wgetenv_s(&sz, NULL, 0, L"IDS_PEAK_GENERIC_SDK_PATH") == 0 && sz > 0)
{
std::vector<wchar_t> env_ids_peak(sz);
if (_wgetenv_s(&sz, env_ids_peak.data(), sz, L"IDS_PEAK_GENERIC_SDK_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 ids_peak_path(env_ids_peak.data());
ids_peak_path.append(L"\\api\\lib\\x86_64");
std::wstring path_var(env_path.data());
path_var.append(L";").append(ids_peak_path);
_wputenv_s(L"PATH", path_var.c_str());
}
}
}
}
// LoadLibraryA fails
HMODULE module = ::LoadLibraryA("ids_peak.dll");
I am trying to use the SDK in a WinUI 3 C++ application. When using the SDK, LoadLibrary inside the SDK fails. During debugging, I examined the process and found that calling LoadLibraryExA as a test successfully loaded the DLL. However, I don't understand why LoadLibraryA fails. What could be the possible reasons for this failure? How can I ensure that the SDK can properly load its DLL? It worked well with MFC, but it doesn't seem to work well with WinUI 3.
- LoadLibraryA failed to load DLL. LoadLibraryA fails even with a full path.
- the full path is specified, LoadLibraryExA loads the main DLL successfully.
- Running the application as administrator does not resolve the problem.
I suspect that _wputenv_s may not be setting the environment variable correctly, and the search path is not being added. However, I am unsure how to resolve this issue.
Any help would be appreciated.
IDS_PEAK_GENERIC_SDK_PATH : C:\Program Files\IDS\ids_peak\generic_sdk
.cpp
// LoadLibraryExA succeeds
HMODULE module2 = LoadLibraryExA(
"C:\\Program Files\\IDS\\ids_peak\\generic_sdk\\api\\lib\\x86_64\\ids_peak.dll",
NULL,
LOAD_WITH_ALTERED_SEARCH_PATH
);
size_t sz = 0;
if (_wgetenv_s(&sz, NULL, 0, L"IDS_PEAK_GENERIC_SDK_PATH") == 0 && sz > 0)
{
std::vector<wchar_t> env_ids_peak(sz);
if (_wgetenv_s(&sz, env_ids_peak.data(), sz, L"IDS_PEAK_GENERIC_SDK_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 ids_peak_path(env_ids_peak.data());
ids_peak_path.append(L"\\api\\lib\\x86_64");
std::wstring path_var(env_path.data());
path_var.append(L";").append(ids_peak_path);
_wputenv_s(L"PATH", path_var.c_str());
}
}
}
}
// LoadLibraryA fails
HMODULE module = ::LoadLibraryA("ids_peak.dll");
Share
Improve this question
edited Mar 5 at 3:08
kinton
asked Mar 3 at 4:04
kintonkinton
3151 silver badge7 bronze badges
15
|
Show 10 more comments
1 Answer
Reset to default 2I suggest you could refer to the thread: https://github/microsoft/WindowsAppSDK/discussions/5202
The reason is that the DLL search order is different for packaged apps. You could refer to the Doc: Standard search order for packaged apps
In winui3, the App Paths key isn't used when computing the DLL search path.
发布者:admin,转转请注明出处:http://www.yc00.com/questions/1745110241a4611804.html
C:\Program Files\IDS\ids_peak\generic_sdk\api\lib\x86_64
– Simon Mourier Commented Mar 3 at 7:05