#include <windows.h>
#include <stdio.h>
typedef int (__cdecl *MYPROC)(LPWSTR);
int main( void )
{
HINSTANCE hinstLib;
MYPROC ProcAdd;
BOOL fFreeResult, fRunTimeLinkSuccess = FALSE;
// 获取动态链接库的句柄
hinstLib = LoadLibrary(TEXT("MyPuts.dll"));
// 如果句柄有效,获取函数地址
if (hinstLib != NULL)
{
ProcAdd = (MYPROC) GetProcAddress(hinstLib, "myPuts");
// 如果函数地址有效,调用函数
if (NULL != ProcAdd)
{
fRunTimeLinkSuccess = TRUE;
(ProcAdd) (L"Message sent to the DLL function\n");
}
// 释放动态链接库
fFreeResult = FreeLibrary(hinstLib);
}
// 如果不能调用动态链接库的函数,选择其他方式
if (! fRunTimeLinkSuccess)
printf("Message printed from executable\n");
return 0;
}