Microsoft Knowledge Base Email Alertz

KBAlertz.com: (269194) - When you use the #import feature of Visual C++ with the Msxml.dll, Msxml2.dll, or Msxml3.dll file, you may receive the following compiler error messages: error C2872: 'DOMDocument' : ambiguous symbol -or- warning C4099: 'DOMDocument' : type name first...

Receive Microsoft Knowledge Base articles by E-Mail?

Every night we scan the Microsoft Knowledge Base. If technologies you're interested in are updated, we'll send you an e-mail. You only get one e-mail a day, and only when new articles are added.

Click here to create a
FREE account
Already have an account?
[Click here to Login]

Search KbAlertz

Advanced Search

Webmasters
Put kbAlertz on your website.
[ Click Here for more! ]





ASP.NET 3.5 Web Hosting with Windows 2008 and SQL 2008: Click Here!
Discount ASP.NET Hosting
ASP.NET 2.0 and 3.5
Windows2008 and SQL2008
US and UK Hosting
The ad says 3 - but KBAlertz referrals get
** SIX MONTHS FREE **


Bug Tracking Software
For bug tracking software or defect tracking software or issue tracking software, visit Axosoft.


Community Site



We Send hundreds of thousands of emails using ASP.NET Email



Expert Web Design & Graphic Design
Design44.com

ASP.NET 3.5 Web Hosting with Windows 2008 and SQL 2008: Click Here!
Discount ASP.NET Hosting
ASP.NET 2.0 and 3.5
Windows2008 and SQL2008
US and UK Hosting
The ad says 3 - but KBAlertz referrals get
** SIX MONTHS FREE **




Mentioned In








Microsoft Knowledge Base Article

This article contents is Microsoft Copyrighted material.
©2005-©2007 Microsoft Corporation. All rights reserved. Terms of Use | Trademarks




Article ID: 269194 - Last Review: December 5, 2003 - Revision: 3.0

PRB: Compiler Errors When You Use #import with XML

This article was previously published under Q269194

SYMPTOMS

When you use the #import feature of Visual C++ with the Msxml.dll, Msxml2.dll, or Msxml3.dll file, you may receive the following compiler error messages:
error C2872: 'DOMDocument' : ambiguous symbol
-or-
warning C4099: 'DOMDocument' : type name first seen using 'class' now seen using 'struct'
error C2011: 'IXMLDOMImplementation' : 'struct' type redefinition
You may see many other C4099 and C2011 errors in the output as well.

CAUSE

The #import feature includes a file named Comdef.h, which indirectly includes files that include Msxml.h. This is necessary because Comdef.h defines some common GUIDs and contains the following:
_COM_SMARTPTR_TYPEDEF(IXMLDocument, __uuidof(IXMLDocument));
_COM_SMARTPTR_TYPEDEF(IXMLElement, __uuidof(IXMLElement));
_COM_SMARTPTR_TYPEDEF(IXMLElementCollection, __uuidof(IXMLElementCollection));
_COM_SMARTPTR_TYPEDEF(IXMLElementNotificationSink, __uuidof(IXMLElementNotificationSink));
_COM_SMARTPTR_TYPEDEF(IXMLError, __uuidof(IXMLError));
				
Because these types are referenced, it is important for the Msxml.h file to be included. This causes redefinitions when #import'ing on the XML dynamic-link library (DLL). The redefinition errors occur when you use the no_namespace attribute for #import. Here is an example:
#import "c:\winnt\system32\msxml.dll" no_namespace 
int main(int argc, char* argv[])
{
	IXMLDOMDocumentPtr dom(__uuidof(DOMDocument));
				
The "ambiguous symbol" error can occur when you use a namespace with #import, and use the Msxml.h header file from the Platform Software Development Kit (SDK) or a newer preview XML SDK from the Web. Because the newer Msxml.h defines DOMDocument in the global namespace, and the #import defines it in another namespace, the symbol is ambiguous. Here is the code to reproduce the problem:
#import "c:\winnt\system32\msxml.dll"
using namespace MSXML;
int main(int argc, char* argv[])
{
	IXMLDOMDocumentPtr dom(__uuidof(DOMDocument));
				

RESOLUTION

The "no_namespace" attribute cannot be used with #import with the XML DLL.

The "ambiguous symbol" error can be avoided by using the Msxml.h header file from the Visual C++ 6.0 Include folder. This Msxml.h file contains only the old XML definitions that are necessary to satisfy Comdef.h, but doesn't redefine such newer symbols as DOMDocument.

If you use the Platform SDK or XML SDK header files, you can add those Include folders after the Visual C++ Include folder when you use #import. To do this, in Visual C++, on the Tools menu, click Options, and then click the Directories tab.

If a newer version of MSXML has been installed in side-by-side mode, you must explicitly use the Globally Unique Identifiers (GUIDs) or ProgIDs for that version to run the sample code. For example, MSXML version 4.0 can only be installed in side-by-side mode. For additional information about the code changes that are required to run the sample code with the MSXML 4.0 parser, click the following article number to view the article in the Microsoft Knowledge Base:
305019  (http://kbalertz.com/Feedback.aspx?kbNumber=305019/EN-US/ ) INFO: MSXML 4.0 Specific GUIDs and ProgIds
For additional information, click the article number below to view the article in the Microsoft Knowledge Base:
316317  (http://kbalertz.com/Feedback.aspx?kbNumber=316317/EN-US/ ) PRB: Compiler Errors When Using #import with XML in Visual C++ .NET

APPLIES TO
  • Microsoft XML Parser 2.0
  • Microsoft XML Parser 2.5
  • Microsoft XML Parser 2.6
  • Microsoft XML Parser 3.0
  • Microsoft Visual C++ 6.0 Enterprise Edition
  • Microsoft Visual C++ 6.0 Professional Edition
  • Microsoft Visual C++, 32-bit Learning Edition 6.0
Keywords: 
kbdatabase kbprb kbmsxmlnosweep KB269194
       

Community Feedback System

Very often, it takes hours to solve a problem. Very often, you've looked high and low, and have tried a lot of solutions. When you finally found it, chances are, it was because someone else helped you. Here's your chance to give back. Use our community feedback tool to let others know what worked for you and what didn't.

Please also understand that the community feedback system is not warranted to be correct, it's simply a system that we've built to let people try and help each other. If something in a feedback response doesn't make sense to you, or you're not comfortable making changes that the feedback talks about (like registry edits), please consult a professional.

Thank you for using kbAlertz.com Feedback System.

-- Scott Cate

Be the first to leave feedback, to help others about this knowledge base article.

(Optional) Name

(Optional) Public URL Or Email

Comments
No HTML -- Text Only Please