MFC添加全局的.h模块文件

来源:百度知道 编辑:UC知道 时间:2024/05/29 08:51:36
我写了一个Module.h文件,里面定义了一些结构体,例如下面的:
#iclude "stdafx.h"
typedef struct tagURLStatus
{
CString strUrl;
int nCapDepth;
} URLStatus;
我希望只写一次#include,能在当前工程的所有文件都使用这些结构体类型
这些结构体的成员变量,有CString这种非标准C/C++的数据类型,所以我就写了#iclude "stdafx.h"
怎么包含这个文件?我是说只写一次#include
To 何处淬吴钩:
我按照你的方法做了,可以了
出现一个新问题:在这个Module.h里面,我想写一个全局的函数,为什么连接报错?怎么解决?
TestDlg.obj : error LNK2005: _GetUrlFromA already defined in StdAfx.obj
Debug/Test.exe : fatal error LNK1169: one or more multiply defined symbols found
执行 link.exe 时出错.
在Module.h里面,函数的定义如下:
extern "C" bool GetUrlFromA(LPCTSTR strCurUrl, LPCTSTR strData, CString &strUrlRet)
{
......
}

把你的Module.h中的#iclude "stdafx.h"
删除掉,然后在你的stdafx.h末尾添加
#include"Module.h"即可(stdafx.h中已经包含了必要的头文件,所以在它末尾加也就相当于#include "stdafx.h"了)。注意把这个头文件添加到工程。