可能的标头冲突

时间:2013-11-04 14:28:38

标签: c++ visual-studio-2010 xml-validation msxml6

我想在Visual C ++中针对XSD架构验证XML文件。我浏览了互联网,我发现的MSXML示例似乎是最直接的。

我正在尝试将this集成到我正在处理的项目中。我创建了XMLSchemaValidation类来执行某些XSD架构的验证,并使用相应的XSD文件名初始化对象。我在头文件中有以下指令:

#import "C:\Windows\System32\msxml6.dll"

但我开始得到以下错误:

7>d:\proiecte\wtlcommon\basegui\gdiplushelpers.h(28): error C2872: 'Font' : ambiguous symbol
7>          could be 'c:\program files (x86)\microsoft visual studio 10.0\vc\include\comdef.h(312) : Font'
7>          or       'c:\program files (x86)\microsoft sdks\windows\v7.0a\include\gdiplusheaders.h(244) : Gdiplus::Font'

我也得到了:

7>...\wizarddlgskin.h(96): error C2259: 'Font' : cannot instantiate abstract class
7>          due to following members:
7>          'HRESULT IUnknown::QueryInterface(const IID &,void **)' : is abstract
7>          c:\program files (x86)\microsoft sdks\windows\v7.0a\include\unknwn.h(116) : see declaration of 'IUnknown::QueryInterface'
7>          'ULONG IUnknown::AddRef(void)' : is abstract
7>          c:\program files (x86)\microsoft sdks\windows\v7.0a\include\unknwn.h(120) : see declaration of 'IUnknown::AddRef'
7>          'ULONG IUnknown::Release(void)' : is abstract
7>          c:\program files (x86)\microsoft sdks\windows\v7.0a\include\unknwn.h(122) : see declaration of 'IUnknown::Release'
7>          'HRESULT IDispatch::GetTypeInfoCount(UINT *)' : is abstract
7>          c:\program files (x86)\microsoft sdks\windows\v7.0a\include\oaidl.h(2123) : see declaration of 'IDispatch::GetTypeInfoCount'
7>          'HRESULT IDispatch::GetTypeInfo(UINT,LCID,ITypeInfo **)' : is abstract
7>          c:\program files (x86)\microsoft sdks\windows\v7.0a\include\oaidl.h(2126) : see declaration of 'IDispatch::GetTypeInfo'
7>          'HRESULT IDispatch::GetIDsOfNames(const IID &,LPOLESTR *,UINT,LCID,DISPID *)' : is abstract
7>          c:\program files (x86)\microsoft sdks\windows\v7.0a\include\oaidl.h(2131) : see declaration of 'IDispatch::GetIDsOfNames'
7>          'HRESULT IDispatch::Invoke(DISPID,const IID &,LCID,WORD,DISPPARAMS *,VARIANT *,EXCEPINFO *,UINT *)' : is abstract
7>          c:\program files (x86)\microsoft sdks\windows\v7.0a\include\oaidl.h(2138) : see declaration of 'IDispatch::Invoke'

我最初在示例代码中有#import <msxml.dll>,但是MSXML安装不会将文件放在他们所说的W7上。

我已经在stdafx.h文件(Errors using msxml6.h on visual c++

中删除了#define WIN32_LEAN_AND_MEAN

我做错了什么?

1 个答案:

答案 0 :(得分:1)

这不是真正的标题冲突,而是名称冲突。如果您在同一个翻译单元中包含声明相同名称的不同库的标题,并且这些库中的一个或多个未在适当的命名空间内声明冲突名称,或者您(或上帝禁止,其中一个库),则会出现它们header)使用using指令将名称倒入命名空间范围。

那么你可以做些什么来摆脱错误:

首先,扫描您的代码以使用指令,尤其是using namespace Gdiplus;using Gdiplus::Font;,因为这似乎是冲突的名称。然后通常尽量避免在同一翻译单元中包含GDIPlus和comdef标头。最好通过将两种include限制为.cpp文件来完成。如果您必须在标头中包含其中一个标头,则该标头本身应限制在给定的子模块中,其他标头不应在整个子模块中使用。
您可能希望使用两个库的功能。如果是这种情况,您仍然可以通过提供要使用每个库的功能的接口来分离库本身的使用。这样就可以封装库的使用,并可以控制接口中的名称,以避免在使用这两种功能时出现冲突。

这是一些非常通用的文本 - 如果您向我们展示出现问题的代码,可以给出示例。