生成dll库
#include<Windows.h> //导出函数,可以加载的时候调用 _declspec(dllexport) void msg() { MessageBoxA(0, "1", "2", 0); } //导出函数,可以加载的时候调用 _declspec(dllexport) int add(int a, int b) { return a + b; }
调用dll库
#include<Windows.h> #include<stdlib.h> #include<stdio.h> typedef void(*procA)(); typedef int (*procB)(int a,int b); void main() { HMODULE hdll = LoadLibrary("DLL.dll"); //加载dll if (hdll != NULL) { procB proc1 = (procB*)GetProcAddress(hdll, "add"); if (proc1 != NULL) { printf("%d", proc1(4, 8)); } FARPROC proc = GetProcAddress(hdll, "msg"); if (proc != NULL) { proc(); } } return 0; }