Click here to Skip to main content
13,047,596 members (64,521 online)
Rate this:
Please Sign up or sign in to vote.
Hi dear all

I created a application to parse a xml file. The main code shows as follow:
//the .h file 
#import <msxml.dll> named_guids
using namespace MSXML;
//the cpp file
MSXML::IXMLDOMDocumentPtr m_plDomDocument;

when compiling the the code it occurs the error:
d:\program files\microsoft visual studio 8\vc\platformsdk\include\shobjidl.h(9344) : error C2872: "IXMLDOMDocument": ambiguous symbol could be 
d:\program files\microsoft visual studio 8\vc\platformsdk\include\msxml.h(1846) : IXMLDOMDocument" or e:\sorce_code\a0005484_ppu_v6.1\a0005484_ppu_v6.1\src\main\viper32comboutility\debug\msxml.tlh(1378) : MSXML::IXMLDOMDocument"

any solution for it? Thank u.
Posted 29-Oct-12 21:59pm
Updated 29-Oct-12 22:19pm
Rate this: bad
Please Sign up or sign in to vote.

Solution 1

Specify a XML parser version for the namespace and use it also as prefix:
// Version 6 shipped with Vista, XP SP3, VS 2005
#import <msxml6.dll> named_guids
// UPDATE: This must be commented when the msxml.h file is also included
// UPDATE: Changed from MSXML3 to MSXML2 (MSXML2 always present)
//using namespace MSXML2;
// UPDATE: Prefix all XML types with the namespace
MSXML2::IXMLDOMDocumentPtr m_plDomDocument;

The parser version depends on the minmum Windows version that must be supported by your program (UPDATE: and the versions supported by the DLL).
Member 8450542 30-Oct-12 7:29am
I have tried and showed the same mistake.
Jochen Arndt 30-Oct-12 9:11am
According to your comments on Richard's answer you are indirectly including msxml.h by shlobj.h -> shlobjidl.h. You should avoid including shlobj.h and your header file with the MSXML import directive in the same source file.

There may be two solutions:

1. If you only use the SHGetFolderPath function and no other functions from shlobj.h, use the shfolder.h header file (it defines only this function without including other header files).

2. Use the SHGetFolderPath function from within a separate source file that does not need to include the header file with the import statement.
Member 8450542 31-Oct-12 5:44am
Thank u very much,Jochen. I have fixed the problem with your solution.As i discussed with Richard, when delete the "using namespace MSXML;" it can fix the problem too. So the msxml.h indirectly included by shlobj.h has adifferent namespace with the #import msxml.dll that lead to the mistake?
Jochen Arndt 31-Oct-12 6:09am
It's fine that the problem is solved.

The msxml.h file itself uses no namespace. When importing the DLL, a msxml.tlh file is generated and included. Both contain identical definitions that will lead to the error.

There is no need to use the namespace directive when prefixing all XML definitions with the MSXMLn namspace. And omitting the directive avoids the error.

I will update my answer to reflect this.
Member 8450542 31-Oct-12 6:52am
Thank you.
Rate this: bad
Please Sign up or sign in to vote.

Solution 2

You have two header files both defining IXMLDOMDocument and the compiler does not know which one to choose.
Member 8450542 30-Oct-12 7:42am
In my project i used "SHGetFolderPath",so i included the header "shlobj.h". And the error direct to the shlobj.h.

HRESULT STDMETHODCALLTYPE IPublishingWizard_GetTransferManifest_Proxy(
IPublishingWizard * This,
/* [out] */ HRESULT *phrFromTransfer,
/* [out] */ IXMLDOMDocument **pdocManifest);

So the IXMLDOMDocument here have been multiple defined with the msxml.h? And there don't use the same namespace ?
Richard MacCutchan 30-Oct-12 7:58am
The compiler messages are telling you where the ambiguity exists. You need to figure out why the second header file is being included.
Member 8450542 30-Oct-12 8:29am
It is the point that confused me. I dont't explicit invoke the msxml.h。
My friend delete the "using namespace MSXML;" and it works well. Why?Thx
Richard MacCutchan 30-Oct-12 8:39am
I'm not sure as I do not often use the import statement. Why is the compiler looking at the file e:\sorce_code\a0005484_ppu_v6.1\a0005484_ppu_v6.1\src\main\viper32comboutility\debug\msxml.tlh(1378)?
Member 8450542 31-Oct-12 5:52am
It confused me too even i can use Jochen's method to fix the problem. The import statement will build the msxml.tlh. And it conflict with shlobj.h。
Richard MacCutchan 31-Oct-12 6:06am
Look at my comment above: why are you allowing the compiler to search this file on your E: drive?
Jochen Arndt 31-Oct-12 6:57am
It is his project debug output directory. The file is generated by the compiler when processing the import statement. It contains the exported symbols from the DLL.
Richard MacCutchan 31-Oct-12 9:16am
Thanks for the clarification.
Member 8450542 31-Oct-12 6:42am
That is the location of my project.Ths.
Richard MacCutchan 31-Oct-12 6:43am
Well one of those includes needs to be removed, I cannot say more.
Member 8450542 31-Oct-12 7:10am
Thank you very much.

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

  Print Answers RSS
Top Experts
Last 24hrsThis month

Advertise | Privacy | Mobile
Web01 | 2.8.170713.1 | Last Updated 31 Oct 2012
Copyright © CodeProject, 1999-2017
All Rights Reserved. Terms of Service
Layout: fixed | fluid

CodeProject, 503-250 Ferrand Drive Toronto Ontario, M3C 3G8 Canada +1 416-849-8900 x 100