Question

I want to validate XML files against XSD schemas in Visual C++. I looked around the internet and the MSXML examples I found seemed to be the most straightforward.

I'm trying to integrate this into the project I'm working on. I created XMLSchemaValidation class to perform validations for certain XSD schemas and I initialize the objects with the corresponding XSD file name. I have the following directives in the header file:

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

but I started getting a looot of the following error:

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'

and I also get:

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'

I initially had #import <msxml.dll> as in the example code, but MSXML installation doesn't put the files where they say it does on W7.

I already removed #define WIN32_LEAN_AND_MEAN in stdafx.h file ( Errors using msxml6.h on visual c++ )

What am I doing wrong?

Was it helpful?

Solution

That is not really a header collision but a name collision. They appear if you include headers of different libraries declaring the same name in the same translation unit and if either one or more of those libraries don't declare the colliding name inside a proper namespace or if you (or god forbid, one of the library headers) pour out the names into namespace scope with a using directive.

So what you can do to get rid of the error:

First, scan your code for using directives, especially for using namespace Gdiplus; and using Gdiplus::Font; since that seems to be the colliding name. Then generally try to avoid including GDIPlus and comdef headers in the same translation unit. That is best done by restricting both kinds of include to .cpp files. If you absolutely have to include one of them in a header, that header itself should be restricted to a given submodule, and the other headers should not be used in the entire submodule.
There may be a point where you want to use functionality of both libraries. If that is the case, you can still separate the use of the libraries themselves by providing an interface to the functionality you want to use of each libray. That way you encapsulate the use of the library and can control the names in the interfaces to avoid collisions in the point where you use both functionalities.

That is some very general text - examples can be given if you show us the code that makes problems.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top