问题
I am changing my C++ project, which was earlier in VC6 and now being migrated to VS 2008, to use MSXML 6 instead of the earlier MSXML 3. When the code was in VC6 we were using MSXML3 by importing it
# import "msxml3.dll"
This was replaced with
# import "msxml6.dll"
After this when I compile the project I get this and several other similar errors Error C2011: 'MSXML2::IXMLDOMImplementation' : 'struct' type redefinition
The above error is in the msxml3.tlh file.
1) Why is msxml3 still being used?
2) I narrowed down the problem to MSXML.h which is somehow automatically being included in my project. Why is this?
3) Which version of MSXML is being referenced in MSXML.h?
4) Why in the world does VC++ automatically include so many header files? What if I dont want some header files to be included?
5) What is the right way of using MSXML6 in a c++ project? #import, header file?????
6) How do I fix this problem?
Give me .net any time. Much cleaner. A VC++ project is a mess.
回答1:
Check the syntax of the #import directive. You can rename imported elements using rename attribute on import directive (or rename_namespace). It will resolve conflicts with duplicated elements.
See here: in MSDN
Sometimes change of the inclusion order (yes - try different order of the include and import statements by commenting them out)
Don't fight with the MS mistakes, just cross them ;)
回答2:
Have a look at the MS docoumentation on MSXML.
They suggest that importing the .dll as you have will create a couple of .thl and .tli files. Make sure you've deleted those.
Make sure any include directories point to the right place.
Make absolutely certain that you're not importing msxml3 somewhere else in your project.
To find the msxml.h do CTRL + SHIFT + F and search you entire solution for 'msxml' <- note the lack of the .h because if you'd been importing it properly, it ought to be done as follows:
#include <msxml6.dll>
Try some of that...
回答3:
I'd try renaming msxml.h and doing a build. That should show you what file is including msxml.h.
来源:https://stackoverflow.com/questions/980082/error-c2011-msxml2ixmldomimplementation-struct-type-redefinition