C++动态库导出函数及变量,没整理

来源:互联网 发布:php会员信息管理系统 编辑:程序博客网 时间:2024/05/18 12:02
// test.cpp : 定义控制台应用程序的入口点。//#include "stdafx.h"#include "a.h"#include <iostream>#include <windows.h>using namespace std;typedef int (*lpFun)(void);int _tmain(int argc, _TCHAR* argv[]){//load dllHINSTANCE glibsample = NULL;glibsample = LoadLibrary(_T("a.dll"));if (glibsample != NULL){ lpFun myfun = (lpFun)GetProcAddress(glibsample, "getValueFunc");if (myfun != NULL){std::cout<<"x = "<< myfun() <<std::endl;}//Ca myA;//myA.getValue();}FreeLibrary(glibsample);return 0;}



dll

#ifdef A_EXPORTS#define A_API __declspec(dllexport)#else#define A_API __declspec(dllimport)#endif// 此类是从 a.dll 导出的class A_API Ca {public:Ca(void);// TODO: 在此添加您的方法。int getValue();};extern A_API int na;extern "C" A_API int getValueFunc(void);

a.cpp

// a.cpp : 定义 DLL 应用程序的导出函数。//#include "stdafx.h"#include "a.h"// 这是导出变量的一个示例A_API int na=0;// 这是导出函数的一个示例。A_API int getValueFunc(void){return  200;}// 这是已导出类的构造函数。// 有关类定义的信息,请参阅 a.hCa::Ca(){return;}int Ca::getValue(){return 100;}

整理导出类的方法

http://blog.csdn.net/nohackcc/article/details/13613319


原创粉丝点击