C++ 动态调用dll库

案例:

使用上一篇文章中封装的dll,即dll中有函数:int ADD(int x, int y);


#include "stdafx.h"
#include <Windows.h>
#include <iostream>
#include <string>

using namespace std;
typedef int(*hADD)(int x, int y); // 宏定义函数指针类型
HINSTANCE hDLL;//DLL句柄
hADD pFun;//函数指针
int main()
{
	hDLL = LoadLibrary(TEXT("E:\\Project\\LibandDll\\MyConsol\\Debug\\MyDLL.dll")); 
        pFun = (hADD)GetProcAddress(hDLL, TEXT("ADD"));/*用pFun取代dll库中的add函数*/
	cout << pFun(1,2) << endl;
	FreeLibrary(hDLL);
    return 0;
}

猜你喜欢

转载自blog.csdn.net/ezreal_pan/article/details/86594697
今日推荐