文件名称:加载动态库
文件大小:14KB
文件格式:RAR
更新时间:2020-04-14 06:08:26
加载动态库
没有头文件和静态库加载C++类的输出动态库,一言不合上代码 class CTest { public: CTest(LPCSTR szDll,LPCSTR sText) { m_hdl = LoadLibrary( szDll ); FARPROC proc = GetProcAddress(m_hdl, "??0CSampleDll@@QAE@PBD@Z"); *((FARPROC*)&m_Construct)=proc; (this->*m_Construct)(sText); proc = GetProcAddress(m_hdl, "??1CSampleDll@@UAE@XZ"); *((FARPROC*)&m_DeConstruct)=proc; proc = GetProcAddress(m_hdl, "?GetText@CSampleDll@@QBEPBDXZ"); *((FARPROC*)&m_FunGetText)=proc; } virtual ~CTest() { (this->*m_DeConstruct)(); } LPCSTR GetText() { return (this->*m_FunGetText)(); } private: BYTE m_host[1024]; typedef void(CTest::*Construct)(LPCSTR); typedef void (CTest::*DeConstruct)(); typedef LPCSTR(CTest ::*FunGetText)(); Construct m_Construct; DeConstruct m_DeConstruct; FunGetText m_FunGetText; HMODULE m_hdl; }; int APIENTRY WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance, LPSTR lpCmdLine, int nCmdShow) { CTest test("../SampleDll/debug/SampleDll.dll", "acadasdasdasda"); LPCSTR sVal=test.GetText(); return 0; }
【文件预览】:
LoadDll
----LoadDll.vcproj(6KB)
----LoadDll.suo(8KB)
----LoadDll.dsp(4KB)
----LoadDll.opt(53KB)
----LoadDll.plg(2KB)
----LoadDll.dsw(740B)
----LoadDll.cpp(1KB)
----StdAfx.cpp(294B)
----SampleDll()
--------SampleDll.h(1KB)
--------SampleDll.cpp(845B)
--------SampleDll.plg(2KB)
--------SampleDll.vcproj(6KB)
--------StdAfx.cpp(296B)
--------StdAfx.h(802B)
--------SampleDll.dsp(4KB)
--------ReadMe.txt(1KB)
----StdAfx.h(773B)
----LoadDll.sln(1KB)
----ReadMe.txt(1KB)