Click here to Skip to main content
15,892,005 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
Hi dear all

I created a application to parse a xml file. The main code shows as follow:
C++
//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:
C++
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
Updated 29-Oct-12 22:19pm
v2

Specify a XML parser version for the namespace and use it also as prefix:
C++
// 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).
 
Share this answer
 
v2
Comments
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.
You have two header files both defining IXMLDOMDocument and the compiler does not know which one to choose.
 
Share this answer
 
Comments
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。

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



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900