tags:

views:

321

answers:

1

XMLNotepad provides the following text (for example) when a transform fails:

Error Transforming XML
The variable or parameter 'saturated-background-color' was duplicated with the same import precedence.

How would I go about getting this error text programmatically? My code looks like this:

CComPtr<IXSLTemplate> tmpl;
HRESULT hr = CoCreateInstance(CLSID_XSLTemplate, NULL, CLSCTX_INPROC_SERVER, IID_IXSLTemplate, (void**)&tmpl);
if (SUCCEEDED(hr)) {
    hr = tmpl->putref_stylesheet(xslt_doc);
    if (SUCCEEDED(hr)) {
 // Huzzah; do stuff.
    } else {
 // How do I get the error text?  I want to log it!
    }
}
+1  A: 

If IXSLTemplate supports IErrorInfo (AFAIK, it does), then you can query that for additional information.

(jeffamaphone clued me in on the proper way to get this - using the GetErrorInfo() API:)

CComPtr<IErrorInfo> error;
if (SUCCEEDED( GetErrorInfo(0, &error) ) && error)
{
   // call IErrorInfo::GetDescription(), etc.
}
Shog9
Nope, it doesn't seem to support that interface. QueryInterface() returns E_NOINTERFACE.
jeffamaphone
That's a shame. You could try IXMLDOMParseError, but i'm pretty sure that's only used by the DOMDocument classes.
Shog9
Yeah, I had already looked at that. :(
jeffamaphone
I suspect the right way to get the IErrorInfo pointer is not through QueryInterface, but through the GetErrorInfo() COM API itself. I've implemented that, and will see if it works.
jeffamaphone
Interesting... I didn't even know about that. Post an answer if it works!
Shog9
Marking as answer... you were pretty close. Instead the solution is to call the GetErrorInfo() API directly. http://msdn.microsoft.com/en-us/library/ms221032.aspx
jeffamaphone
@jeffamaphone: excellent work, i've updated the example to reflect this.
Shog9