GetPorcAddress 获取函数地址函数第二个参数 ,函数名称的命名规则
第一种情况
第二种情况
去掉 __stdcall ,C语言 显示链接调用DLL文件
#include <stdio.h>
#include <Windows.h>
//定义函数指针
typedef int(*lpPlus)(int, int);
typedef int(*lpSub)(int, int);
typedef int(*lpMul)(int, int);
typedef int(*lpDiv)(int, int);
int main(int argc,char* argv[])
{
//声明函数指针变量
lpPlus myPlus;
lpSub mySub;
lpMul myMul;
lpDiv myDiv;
//动态加载dll到内存中
HINSTANCE hModule = LoadLibrary(L"TestDll1.dll");
//获取函数 地址
myPlus = (lpPlus)GetProcAddress(hModule, "Plus");
mySub = (lpSub)GetProcAddress(hModule, "Sub");
myMul = (lpMul)GetProcAddress(hModule, "Mul");
myDiv = (lpDiv)GetProcAddress(hModule, "Div");
int x;
x = myPlus(2, 3);
printf("%d \n", x);
return 0;
}
隐藏函数名称导出DLL 的方法
1、DLL 编写方法
2、 def文件说明
注意
1、 DependencyWalker.exe visual6.0 自带的这个软件可以查看到DLL导出的函数(我的TM网盘里面有保存)
隐式调用源代码
//主程序 outoutpeh.cpp
#include <stdio.h>
#include <stdlib.h>
#include "func.h"
#pragma comment(lib, "Dll2.lib")//生产DLL 是会有这个文件,里面保存了函数的位置信息
__declspec(dllimport) int Plus(int x, int y); //导入函数
int main(int argc ,char* argv[])
{
int x = Plus(1, 2); //调用DLL里面的函数
printf("%d\n", x);
// getchar();
return 1;
}