diff --git a/src/dags/custom_node_library_manager.cpp b/src/dags/custom_node_library_manager.cpp index b9cc365995..d9302b9252 100644 --- a/src/dags/custom_node_library_manager.cpp +++ b/src/dags/custom_node_library_manager.cpp @@ -114,11 +114,73 @@ Status CustomNodeLibraryManager::loadLibrary(const std::string& name, const std: SPDLOG_LOGGER_INFO(modelmanager_logger, "Successfully loaded custom node library name: {}; base_path: {}", name, basePath); #elif _WIN32 // TODO: implement LoadLibrary for windows with GetProcAddress - void* handle = NULL; - if (handle == NULL) { + HMODULE handle = LoadLibraryA(basePath.c_str()); + DWORD error = GetLastError(); + // void* handle = NULL; + if (!handle) { SPDLOG_LOGGER_ERROR(modelmanager_logger, "Library name: {} failed to open base_path: {} with error: {}", name, basePath, "e"); return StatusCode::NODE_LIBRARY_LOAD_FAILED_OPEN; } + + initialize_fn initialize = reinterpret_cast(GetProcAddress(handle, "initialize")); + if (!initialize) { + error = GetLastError(); + SPDLOG_LOGGER_ERROR(modelmanager_logger, "Failed to load library name: {} with error: {}", name, error); + FreeLibrary(handle); + return StatusCode::NODE_LIBRARY_LOAD_FAILED_SYM; + } + + deinitialize_fn deinitialize = reinterpret_cast(GetProcAddress(handle, "deinitialize")); + if (!deinitialize) { + error = GetLastError(); + SPDLOG_LOGGER_ERROR(modelmanager_logger, "Failed to load library name: {} with error: {}", name, error); + FreeLibrary(handle); + return StatusCode::NODE_LIBRARY_LOAD_FAILED_SYM; + } + + execute_fn execute = reinterpret_cast(GetProcAddress(handle, "execute")); + if (!execute) { + error = GetLastError(); + SPDLOG_LOGGER_ERROR(modelmanager_logger, "Failed to load library name: {} with error: {}", name, error); + FreeLibrary(handle); + return StatusCode::NODE_LIBRARY_LOAD_FAILED_SYM; + } + + metadata_fn getInputsInfo = reinterpret_cast(GetProcAddress(handle, "getInputsInfo")); + if (!getInputsInfo) { + error = GetLastError(); + SPDLOG_LOGGER_ERROR(modelmanager_logger, "Failed to load library name: {} with error: {}", name, error); + FreeLibrary(handle); + return StatusCode::NODE_LIBRARY_LOAD_FAILED_SYM; + } + + metadata_fn getOutputsInfo = reinterpret_cast(GetProcAddress(handle, "getOutputsInfo")); + if (!getOutputsInfo) { + error = GetLastError(); + SPDLOG_LOGGER_ERROR(modelmanager_logger, "Failed to load library name: {} with error: {}", name, error); + FreeLibrary(handle); + return StatusCode::NODE_LIBRARY_LOAD_FAILED_SYM; + } + + release_fn release = reinterpret_cast(GetProcAddress(handle, "release")); + if (!release) { + error = GetLastError(); + SPDLOG_LOGGER_ERROR(modelmanager_logger, "Failed to load library name: {} with error: {}", name, error); + FreeLibrary(handle); + return StatusCode::NODE_LIBRARY_LOAD_FAILED_SYM; + } + + libraries[name] = NodeLibrary{ + initialize, + deinitialize, + execute, + getInputsInfo, + getOutputsInfo, + release, + basePath}; + + SPDLOG_LOGGER_INFO(modelmanager_logger, "Successfully loaded custom node library name: {}; base_path: {}", name, basePath); + #endif return StatusCode::OK;