您的位置:首页 > 其它

全局变量的声明和定义 以及dll中全局变量的导出

2010-03-25 17:01 543 查看
声明全局变量
global_variable.h文件中
#ifndef global_variable_H
#define global_variable_H
extern int selectColumnResult;
extern CString strColumn[100];
#endif //global_variable_H

global_variable.cpp中
int selectColumnResult;
CString strColumn[100];
然后在要用到全局变量 的cpp文件中#include "global_variable.h",可以
将所有的全局变量弄到这个一个文件中。
如果是vc++的话也可以直接都写在stdafx.h和stdafx.pp中。

====================================================

全局变量导出 要封装的dll
global_variable.h文件中
#ifndef global_variable_H
#define global_variable_H
extern "C" _declspec(dllexport) int selectColumnResult;
extern "C" _declspec(dllexport) CString strColumn[100];
#endif //global_variable_H

global_variable.cpp中
int selectColumnResult;
CString strColumn[100];

封装后在proc.cpp中调用

#pragma comment(lib,"global_variable.lib")

extern "C" _declspec(dllimport) int selectColumnResult; //列的数量
extern "C" _declspec(dllimport) CString strColumn[100]; //列名

在dll导出全局变量的方式和导出函数的方式完全一致。
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: 
相关文章推荐