C++11 DllParser
#include "pch.h" #include #include #include #include #include using namespace std; class DllParser { public: DllParser():m_hMod(nullptr) { } ~DllParser() { UnLoad(); } bool Load(const std::string & dllPath) { m_hMod = LoadLibraryA(dllPath.data()); if (nullptr == m_hMod) { cout << "LoadLibrary failed" << endl; } return true; } bool UnLoad() { if (nullptr == m_hMod) return true; auto b = FreeLibrary(m_hMod); if (!b) return false; m_hMod = nullptr; return true; } template function { auto it = m_map.find(funcName); if (it == m_map.end()) { auto addr = GetProcAddress(m_hMod,funcName.c_str()); if (!addr) return nullptr; m_map.insert(make_pair(funcName,addr)); it = m_map.find(funcName); } return function } template typename result_of { auto f = GetFunction if (nullptr==f) { string s = "can not find this function "+funcName; throw exception(s.c_str()); } return f(forward(args)...); } private: HMODULE m_hMod; map }; int main() { /* 类似于如下调用 auto max = ExcecuteFunc auto ret = ExecuteFunc */ } (编辑:李大同) 【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容! |