Note that there are some explanatory texts on larger screens.

plurals
  1. POFirst chance exception in MSXML6
    text
    copied!<p>I'm validating XML files against XSD schemas as they do in the MSXML documentation <a href="http://msdn.microsoft.com/en-us/library/ms762787%28v=vs.85%29.aspx" rel="nofollow">example</a>. I have the following code:</p> <pre><code>XMLSchemaValidation updateInfoSchema; updateInfoSchema.DoInitialization(L"schema.xsd"); HRESULT hr = CoInitialize(NULL); if(SUCCEEDED(hr)) { try { _bstr_t bstrOutput = updateInfoSchema.validateFile(L"valid.xml"); } catch(_com_error &amp;e) { updateInfoSchema.dump_com_error(e); } CoUninitialize(); } // Macro that calls a COM method returning HRESULT value. #define CHK_HR(stmt) do { hr=(stmt); if (FAILED(hr)) goto CleanUp; } while(0) _bstr_t XMLSchemaValidation::validateFile(_bstr_t bstrFile) { // Declare and initialize variables MSXML2::IXMLDOMSchemaCollectionPtr pXS; MSXML2::IXMLDOMDocument2Ptr pXD; MSXML2::IXMLDOMParseErrorPtr pErr; _bstr_t bstrResult = L""; HRESULT hr = S_OK; // Create a schema cache and add xsd schema to it. CHK_HR(pXS.CreateInstance(__uuidof(MSXML2::XMLSchemaCache60), NULL, CLSCTX_INPROC_SERVER)); CHK_HR(pXS-&gt;add(L"", (LPCSTR)(SchemaFileName.GetString()))); // Create a DOMDocument and set its properties. CHK_HR(pXD.CreateInstance(__uuidof(MSXML2::DOMDocument60), NULL, CLSCTX_INPROC_SERVER)); // Assign the schema cache to the DOMDocument's schemas collection. pXD-&gt;schemas = pXS.GetInterfacePtr(); // Load bstrFile into the DOM document. pXD-&gt;async = VARIANT_FALSE; pXD-&gt;validateOnParse = VARIANT_TRUE; pXD-&gt;resolveExternals = VARIANT_TRUE; if(pXD-&gt;load(bstrFile) != VARIANT_TRUE) { pErr = pXD-&gt;parseError; bstrResult = _bstr_t(L"Validation failed on ") + bstrFile + _bstr_t(L"\n=====================") + _bstr_t(L"\nReason: ") + _bstr_t(pErr-&gt;Getreason()) + _bstr_t(L"\nSource: ") + _bstr_t(pErr-&gt;GetsrcText()) + _bstr_t(L"\nLine: ") + _bstr_t(pErr-&gt;Getline()) + _bstr_t(L"\n"); } else { bstrResult = _bstr_t(L"Validation succeeded for ") + bstrFile + _bstr_t(L"\n======================\n") + _bstr_t(pXD-&gt;xml) + _bstr_t(L"\n"); } CleanUp: return bstrResult; } </code></pre> <p><code>XMLSchemaValidation::DoInitialization(CString XSDFileName)</code> gets the XSD schema file name into the CString <code>XMLSchemaValidation::SchemaFileName</code>.</p> <p>The code then follows the one in the MSXML example, but I get</p> <pre><code>First-chance exception at 0x76f9c41f (KernelBase.dll) in CSW.exe: Microsoft C++ exception: _com_error at memory location 0x04a7f014.. </code></pre> <p>when code reaches <code>CHK_HR(pXS-&gt;add(L"", (LPCSTR)(SchemaFileName.GetString())));</code>. <code>hr</code> has -2146697210.</p> <p>Can anyone tell me why this happens?</p>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload