调用DLL
调用DLL或lib¶
静态库调用
#include<windows.h>
#pragma comment (lib,"User32.lib")
动态库调用
//----------------例1
HMODULE hDLL = LoadLibrary("multiwindow.dll"); //加载dll
typedef int (*func)(void); //int表示要调用的dll里的函数的返回值类型,void那里是参数.
//比如multiwindow.dll里面有个函数int getnum();
//用(*func)替代getnum就行了
typedef int * (*func1)(int id);
func getnum = (func)GetProcAddress(hDLL,"getnum");
int c=getnum();
cout<<c<<endl;
//----------------例2
HMODULE hDLL = LoadLibrary("multiwindow.dll"); //加载dll
typedef int * (*func1)(int id);
func1 getsize =(func1)GetProcAddress(hDLL,"getsize");
int *s=getsize(0);
cout<< s[0]<<endl<<s[1]<<endl;