新建一个控制台程序,将动态链接库文件Test63,dll拷贝到源文件统计目录下,在主程序中添加如下代码
// import.cpp : Defines the entry point for the console application.
//
#include "stdafx.h"
#include <windows.h>
#include <stdio.h>
typedef int (*MyMessageBox)(char* lpText,char* lpCaption);
int main(int argc, char* argv[])
{
HMODULE hModule=LoadLibrary("Test63.dll");
MyMessageBox NewMessageBox=(MyMessageBox)GetProcAddress(hModule,"MyMessageBox");
NewMessageBox("by chen","Hello World!");
FreeLibrary(hModule);
return 0;
}
编译执行可以看到如下效果