1 // Copyright (C) 2018-2019 Intel Corporation
2 // SPDX-License-Identifier: Apache-2.0
6 * @brief WINAPI compatible loader for a shared object
7 * @file win_shared_object_loader.h
11 #include "../../ie_api.h"
12 #include "../ie_exception.hpp"
14 // Avoidance of Windows.h to include winsock library.
16 // Avoidance of Windows.h to define min/max.
23 namespace InferenceEngine {
27 * @brief This class provides an OS shared module abstraction
29 class SharedObjectLoader {
31 HMODULE shared_object;
35 * @brief Loads a library with the name specified. The library is loaded according to the
36 * WinAPI LoadLibrary rules
37 * @param pluginName Full or relative path to the plugin library
39 explicit SharedObjectLoader(LPCTSTR pluginName) {
41 shared_object = LoadLibrary(pluginName);
43 THROW_IE_EXCEPTION << "Cannot load library '"
44 << pluginName << "': "
46 << " from cwd: " << _getcwd(cwd, 1024);
49 ~SharedObjectLoader() {
50 FreeLibrary(shared_object);
54 * @brief Searches for a function symbol in the loaded module
55 * @param symbolName Name of function to find
56 * @return A pointer to the function if found
57 * @throws InferenceEngineException if the function is not found
59 void *get_symbol(const char* symbolName) const {
61 THROW_IE_EXCEPTION << "Cannot get '" << symbolName << "' content from unknown library!";
63 auto procAddr = reinterpret_cast<void*>(GetProcAddress(shared_object, symbolName));
64 if (procAddr == nullptr)
65 THROW_IE_EXCEPTION << "GetProcAddress cannot locate method '" << symbolName << "': " << GetLastError();
71 } // namespace details
72 } // namespace InferenceEngine