typedef ITestApi
*
(__cdecl
*
API_NEW_INTERFACE)();
typedef void(__cdecl
*
API_RELEASE_INTERFACE)(ITestApi
*
pTestApi);
int
main()
{
char
buffer
[MAX_PATH];
GetModuleFileNameA(NULL,
buffer
, MAX_PATH);
/
/
提取目录部分
std::string strCurrentDir
=
buffer
;
size_t pos
=
strCurrentDir.find_last_of(
"\\/"
);
if
(pos !
=
std::string::npos)
{
strCurrentDir
=
strCurrentDir.substr(
0
, pos);
}
API_NEW_INTERFACE pfnNewInterface
=
nullptr;
API_RELEASE_INTERFACE pfnReleaseInterface
=
nullptr;
strCurrentDir
+
=
"\\TestDll.dll"
;
std::cout <<
"filename: "
<< strCurrentDir.c_str() << std::endl;
HMODULE hDll
=
LoadLibraryA(strCurrentDir.c_str());
ITestApi
*
pTestApi
=
nullptr;
if
(hDll)
{
pfnNewInterface
=
(API_NEW_INTERFACE)GetProcAddress(hDll,
"NewInterface"
);
pfnReleaseInterface
=
(API_RELEASE_INTERFACE)GetProcAddress(hDll,
"ReleaseInterface"
);
pTestApi
=
pfnNewInterface();
if
(pTestApi)
{
CTest
*
pTest
=
new CTest();
pTestApi
-
>GetData(&pTest);
if
(pTest
-
>pNext)
{
std::cout <<
"pPrev: "
<<pTest
-
>pPrev << std::endl;
std::cout <<
"pNext: "
<<pTest
-
>pNext << std::endl;
}
}
}
else
{
std::cout <<
"动态库加载失败:Error: "
<< GetLastError()<<std::endl;
}
if
(pfnReleaseInterface && pTestApi)
{
pfnReleaseInterface(pTestApi);
}
system(
"pause"
);
}