We have some legacy code that uses MSXML and the wrapper classes generated using Visual Studio's C++ #import
directive like so:
#import <msxml6.dll> named_guids
We are upgrading the project to use wchar_t
as a built-in type (previously, the /Zc:wchar_t-
flag was set, so wchar_t
was unsigned short
). This seems to cause problems as the type library headers generated using #import
replace const wchar_t*
input parameters with unsigned short*
.
For example the ISAXXMLReader::putProperty
method has the following signature:
HRESULT putProperty(
[in] const wchar_t * pwchName,
[in] VARIANT varValue);
but the generated type library header uses the following signature:
HRESULT ISAXXMLReader::putProperty (
unsigned short * pwchName,
const _variant_t & varValue )
so not only is wchar_t
converted to unsigned short
, but the const is stripped. So the code fails to compile without an unsightly cast:
MSXML2::ISAXXMLReaderPtr saxReader(__uuidof(MSXML2::SAXXMLReader60));
MSXML2::IMXWriterPtr xmlWriter(__uuidof(MSXML2::MXXMLWriter60));
//Set properties on the XML writer.
// Omitted for brevity
saxReader->putProperty(L"http://xml.org/sax/properties/lexical-handler", // Can't convert to unsigned short*
(_variant_t)xmlWriter.GetInterfacePtr());
Is there any way to get the import directive to generate the proper function signatures in the wrapper classes?
Edit To add to the muddle the msxml6.h
header declares a C++ class ISAXXMLReader
with the expected signature:
virtual HRESULT STDMETHODCALLTYPE putProperty(
/* [in] */ const wchar_t *pwchName,
/* [in] */ VARIANT varValue) = 0;
though after reading the answer provided, I guess it's just hiding the gory details. But at least it's consistent with the documentation (which uses this header in its samples.)