Here's a MS official example of
But this is supposed to be for C#. How about my C project?
Edit: I find this, https://www.codeproject.com/Articles/43309/How-to-create-a-simple-XML-file-using-MSXML-in-C
The first thing you need to do is add these two lines in the project stdafx.h file:
#import "MSXML4.dll" rename_namespace(_T("MSXML"))
#include <msxml2.h>
I modified this MSXML4.dll
to my newly MSXML6.dll
, but the project can't find it still.
CodePudding user response:
The sample code is using _com_ptr_t
, a COM smart pointer class template provided by Visual Studio. Yet the code provided is incomplete.
To declare a _com_ptr_t
specialization for any given interface you would usually use the _COM_SMARTPTR_TYPEDEF
macro. In this case the following declarations need to be added:
_COM_SMARTPTR_TYPEDEF(IXMLDOMDocument2, __uuidof(IXMLDOMDocument2));
_COM_SMARTPTR_TYPEDEF(IXMLDOMSchemaCollection2, __uuidof(IXMLDOMSchemaCollection2));
This declares the types IXMLDOMDocument2Ptr
and IXMLDOMSchemaCollection2Ptr
as specializations of _com_ptr_t
, ready to be used. You'll need to #include <comip.h>
, too.
An alternative would be to use the compiler specific #import
directive. This generates header files from a type library (TLB), and by default includes the respective _COM_SMARTPTR_TYPEDEF
declarations (see Primary type library header file).
CodePudding user response:
From this demo The first thing you need to do is add these two lines in the project stdafx.h file:
#import "MSXML6.dll" rename_namespace(_T("MSXML"))
#include <msxml2.h>
Then correct all the MSXML2
to MSXML
, as we specified the name rename_namespace(_T("MSXML"))
.
I didn't bother to do this, I at first tried namespace MSXML2=MSXML
didn't work. So I just defined a MACRO #define MSXML2 MSXML
. It compiled!