#include "iostream" #include "iomanip" #include "fstream" #include "cstdlib" //#include "libxl.h" #include <windows.h> using namespace std; typedef void (*lpconnect)(); //void connect(); //void disconnect(); int main(){ //dll 句柄 HINSTANCE hModule; //函数指针 lpconnect connect; //加载dll hModule = LoadLibrary("..\\lib\\cygmysharelib.dll"); if(hModule!=NULL){ //传入dll句柄 connect = (lpconnect)GetProcAddress(hModule,"connect"); if(connect!=NULL){ connect(); }else{ cout<<"无法调用函数connect"<<endl; } //释放资源 FreeLibrary(hModule); } }
}
1.创建类库
2.动态调用
#include "iostream" #include "iomanip" #include "fstream" #include "cstdlib" //#include "libxl.h" #include <windows.h> using namespace std; typedef void (*lpconnect)(); typedef void (*lpdisconnect)(); //void connect(); //void disconnect(); int main(){ //dll 句柄 HINSTANCE hModule; //函数指针 lpconnect connect; lpdisconnect disconnect; //加载dll hModule = LoadLibrary("..\\lib\\cygmysharelib.dll"); if(hModule!=NULL){ //传入dll句柄 connect = (lpconnect)GetProcAddress(hModule,"connect"); if(connect!=NULL){ connect(); }else{ cout<<"无法调用函数connect"<<endl; } disconnect = (lpdisconnect)GetProcAddress(hModule,"disconnect"); if(disconnect!=NULL){ disconnect(); }else{ cout<<"无法调用函数disconnect"<<endl; } //释放资源 FreeLibrary(hModule); } }