Link to home
Start Free TrialLog in
Avatar of c095276
c095276

asked on

Importing MSXML3 type library

I have created a new ATL COM project with the AppWizard.  The first thing a do is compile and everything compiles fine as expected.  Then if I try to import the msxml3.dll from the classwizrd, I receive several 'struct' type redefinition errors.  Why is this happening?  I noticed that when I did the original compile the line Processing ?C:\Program Files\Microsoft Visual Studio\VC98\INCLUDE\msxml.idl? appears in the build window.  I assume this is cause of the conflict.  Why is the msxml.idl being processed, and how do I work around this conflict?
Avatar of tdubroff
tdubroff

Hmm...when you are importing msxml3 are you using Class Wizard->Add Class->From a Type Library?
What types you have problems with? (some I know of are BLOBS and the like...)

youcan import the TLB using an #import statement like this:

#import "foo.dll" no_namespace exclude("BSTRBLOB", ...)

which uses no namespace for the declarations, and you can specify which symbols to exclude

Another option would be using a dedicated namespace of your choice like

#import "foo.dll" rename_namespace("nsXML")

Peter

Avatar of c095276

ASKER

tdubroff, Yes that is how I import the dll

peterchen, I am usng the classwizrd and not the #import.  Is there not a way to specify a namespace with the classwizard?
Do you have the Platform SDK installed?
Avatar of c095276

ASKER

I do not know.  What is it, and how does it benifit me?
The Platform SDK is what everyone using Visual Studio 6.0 should have installed on their development machine.  It updates a ton of header files, replaces a lot of dlls with more recent ones, adds loads of help files, etc.  Goto http://msdn.microsoft.com/platformsdk to download it.  I'm not sure it will solve your problem, but after installing it myself, a lot of wierd problems I had went away.
Avatar of c095276

ASKER

I installed the platform SDK and now programs that once worked and compiled fine will not do so.  I receive 159 error(s), 989 warning(s) that I did not receive before.  Here are just a few.

d:\myprojects\ncslib\msxml.h(5) : error C2011: 'IXMLDOMNode' : 'struct' type redefinition
d:\myprojects\ncslib\msxml.h(57) : error C2011: 'IXMLDOMNodeList' : 'struct' type redefinition
d:\myprojects\ncslib\msxml.h(77) : error C2011: 'IXMLDOMDocument' : 'struct' type redefinition
d:\myprojects\ncslib\msxml.h(162) : error C2011: 'IXMLDOMElement' : 'struct' type redefinition
d:\myprojects\ncslib\msxml.h(223) : error C2011: 'IXMLDOMAttribute' : 'struct' type redefinition
d:\myprojects\ncslib\msxml.h(278) : error C2011: 'IXMLDOMNamedNodeMap' : 'struct' type redefinition
D:\MyProjects\NCSLib\msxml.cpp(20) : error C2039: 'GetNodeName' : is not a member of 'IXMLDOMNode'
        d:\program files\microsoft platform sdk\include\msxml.h(533) : see declaration of 'IXMLDOMNode'
D:\MyProjects\NCSLib\msxml.cpp(23) : error C2065: 'InvokeHelper' : undeclared identifier
D:\MyProjects\NCSLib\msxml.cpp(27) : error C2039: 'GetNodeValue' : is not a member of 'IXMLDOMNode'
        d:\program files\microsoft platform sdk\include\msxml.h(533) : see declaration of 'IXMLDOMNode'
D:\MyProjects\NCSLib\msxml.cpp(34) : error C2039: 'SetNodeValue' : is not a member of 'IXMLDOMNode'


I uninstalled the platform SDK and everything works fine again.
When you install the Platform SDK, you have to edit the directory list and move all the platform sdk directories before the old directories.
Avatar of c095276

ASKER

I'm a little green.  How do you do this?
Tools/Options/Directories, choose "include directories" on right drop down, then use the arrow buttons to rearrange items in the list
Avatar of c095276

ASKER

I finally had time to get back to this problem.  I have installed the platform SDK and the path to the Platform SDK is listed first for the include and the lib lists.  I am still getting the same problem.  Another bit of confusion is that I used the classwizard to import the msxml.dll into my project, but I am receiving warnings such as this.

d:\myprojects\upesupdate\ncslib\xmlmanager.h(99) : error C2259: 'IXMLDOMDocument' : cannot instantiate abstract class due to following members:
        d:\microsoft platform sdk\include\msxml.h(1842) : see declaration of 'IXMLDOMDocument'

Looks like the preprocessor is including the platform sdk version and not the version that was imported by the classwizard.
Avatar of c095276

ASKER

I have uninstalled the platform sdk.  The good news is that I am no longer getting the hundreds of errors, and 900 hundred warnings.  The bad news is that I am now getting this error.

d:\myprojects\upesupdate\upesupdate\msxml.h(223) : error C2011: 'IXMLDocument' : 'struct' type redefinition

This is the same error that I was getting when I tryed to import the msxml3.dll, which prompted this discussion.
Avatar of c095276

ASKER

I have uninstalled the platform sdk.  The good news is that I am no longer getting the hundreds of errors, and 900 hundred warnings.  The bad news is that I am now getting this error.

d:\myprojects\upesupdate\upesupdate\msxml.h(223) : error C2011: 'IXMLDocument' : 'struct' type redefinition

This is the same error that I was getting when I tryed to import the msxml3.dll, which prompted this discussion.
ASKER CERTIFIED SOLUTION
Avatar of peterchen092700
peterchen092700

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of c095276

ASKER

I have removed the classwizard generated files from both my project and from its physical location.  Then I inserted the #import staement as follows

#import "C:\\WINNT\\SYSTEM32\\MSXML.DLL" rename_namespace("msXML")

I then changed my declarations as follows

msXML::IXMLDOMDocument _xmlDoc;
msXML::IXMLDOMNode _currentNode;

But I still get over 80 errors and 1000 warnings.


d:\myprojects\upesupdate\ncslib\xmlmanager.h(101) : error C2259: 'IXMLDOMDocument' : cannot instantiate abstract class due to following members:
        d:\myprojects\upesupdate\upesupdate\debug\msxml.tlh(470) : see declaration of 'IXMLDOMDocument'
d:\myprojects\upesupdate\ncslib\xmlmanager.h(101) : warning C4259: 'long __stdcall IUnknown::QueryInterface(const struct _GUID &,void ** )' : pure virtual function was not defined
        c:\program files\microsoft visual studio\vc98\include\unknwn.h(109) : see declaration of 'QueryInterface'
d:\myprojects\upesupdate\ncslib\xmlmanager.h(101) : warning C4259: 'unsigned long __stdcall IUnknown::AddRef(void)' : pure virtual function was not defined
        c:\program files\microsoft visual studio\vc98\include\unknwn.h(113) : see declaration of 'AddRef'
d:\myprojects\upesupdate\ncslib\xmlmanager.h(101) : warning C4259: 'unsigned long __stdcall IUnknown::Release(void)' : pure virtual function was not defined
        c:\program files\microsoft visual studio\vc98\include\unknwn.h(115) : see declaration of 'Release'
You are trying to create an instance of an Interface (which is abstract by nature); this is no problem with #importing the type lib, but with using it.

Giving you a tutorial on COM might be a bit beyond the scope of this question, so only in short:

If you get returned a pointer to the DOM object returned from Somewhere, use

msXML::IXMLDOMDocumentPtr pXmlDoc = ....

Otrherwise, if you want to create your own instance use:

msXML::IXMLDOMDocumentPtr pXmlDoc;
pXmlDoc.CreateInstance( __uuidof( XMLDOMDocument) );

To use the code this way you should be familiar with exceptions and smart pointers. If one of the interface calls fails (an error code is returned), the wrapper classes generated by #import do throw an exception for this.

If you are not comfortable with these things, you should add the raw_interfaces_only specification to the #import statement.
 
MSDN has extensive information on using COM in VC++ in general, _com_ptr_t<> smart pointers, and exception handling.

Good luck
Peter
Avatar of c095276

ASKER

Thanks for the quick tutorial.  I have done as you instructed, and everything seems to work fine.  On error handling.  I have caught the _com_error.  Is there anything else that I should watch out for or any other recommendations that you can give?

Thanks for all your help
catching the COM error is fine. Only thimng to be aware is that #import (without raw_interfaces_only) slightly changes the signature - parameters declared as retval are made actual return value etc.

God luck!
Peter
Avatar of c095276

ASKER

Thanks after changing from the classwizard generated classes to the #import generated classs, I can now use the msxml3.dll withou any erors or warnings.