Microsoft KB Archive/269194

= PRB: Compiler Errors When You Use #import with XML =

Article ID: 269194

Article Last Modified on 12/5/2003

-

APPLIES TO


 * Microsoft XML Parser 2.0
 * Microsoft XML Parser 2.5
 * Microsoft XML Parser 2.6
 * Microsoft XML Core Services 4.0
 * Microsoft Visual C++ 6.0 Enterprise Edition
 * Microsoft Visual C++ 6.0 Professional Edition
 * Microsoft Visual C++ 6.0 Standard Edition

-



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: int main(int argc, char* argv[]) {   IXMLDOMDocumentPtr dom(__uuidof(DOMDocument)); The &quot;ambiguous symbol&quot; 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: using namespace MSXML; int main(int argc, char* argv[]) {   IXMLDOMDocumentPtr dom(__uuidof(DOMDocument));
 * 1) import &quot;c:\winnt\system32\msxml.dll&quot; no_namespace
 * 1) import &quot;c:\winnt\system32\msxml.dll&quot;



RESOLUTION
The &quot;no_namespace&quot; attribute cannot be used with #import with the XML DLL.

The &quot;ambiguous symbol&quot; 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 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 PRB: Compiler Errors When Using #import with XML in Visual C++ .NET

Additional query words: C2872 C4099 C2011

Keywords: kbdatabase kbprb kbmsxmlnosweep KB269194

-

[mailto:TECHNET@MICROSOFT.COM Send feedback to Microsoft]

© Microsoft Corporation. All rights reserved.