use LOAD_WITH_ALTERED_SEARCH_PATH for LoadLibraryExA (#3908)

This commit is contained in:
George Wu 2020-05-12 02:53:34 +00:00 committed by GitHub
parent 70abb120b3
commit 6f729b100f
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
2 changed files with 3 additions and 7 deletions

View file

@ -447,7 +447,7 @@ class WindowsEnv : public Env {
}
virtual Status LoadDynamicLibrary(const std::string& library_filename, void** handle) const override {
*handle = ::LoadLibraryExA(library_filename.c_str(), nullptr, LOAD_LIBRARY_SEARCH_DEFAULT_DIRS | LOAD_LIBRARY_SEARCH_DLL_LOAD_DIR);
*handle = ::LoadLibraryExA(library_filename.c_str(), nullptr, LOAD_WITH_ALTERED_SEARCH_PATH);
if (!*handle)
return common::Status(common::ONNXRUNTIME, common::FAIL, "Failed to load library");
return common::Status::OK();

View file

@ -346,15 +346,11 @@ TEST(CApiTest, DISABLED_test_custom_op_library) {
std::string lib_name;
#if defined(_WIN32)
char current_directory[/*MAX_PATH*/ 260];
if (_getcwd(current_directory, _countof(current_directory)))
lib_name = current_directory;
lib_name += "\\custom_op_library.dll";
lib_name = "custom_op_library.dll";
#elif defined(__APPLE__)
lib_name = "libcustom_op_library.dylib";
#else
lib_name = "./libcustom_op_library.so";
lib_name = "./libcustom_op_library.so";
#endif
TestInference<PATH_TYPE, int32_t>(*ort_env, CUSTOM_OP_LIBRARY_TEST_MODEL_URI, inputs, "output", expected_dims_y, expected_values_y, 0, nullptr, lib_name.c_str());