aboutsummaryrefslogtreecommitdiff
path: root/src/dutil/xmlutil.cpp
diff options
context:
space:
mode:
Diffstat (limited to '')
-rw-r--r--src/dutil/xmlutil.cpp193
1 files changed, 104 insertions, 89 deletions
diff --git a/src/dutil/xmlutil.cpp b/src/dutil/xmlutil.cpp
index f97ca962..6ecd2449 100644
--- a/src/dutil/xmlutil.cpp
+++ b/src/dutil/xmlutil.cpp
@@ -2,6 +2,21 @@
2 2
3#include "precomp.h" 3#include "precomp.h"
4 4
5
6// Exit macros
7#define XmlExitOnLastError(x, s, ...) ExitOnLastErrorSource(DUTIL_SOURCE_XMLUTIL, x, s, __VA_ARGS__)
8#define XmlExitOnLastErrorDebugTrace(x, s, ...) ExitOnLastErrorDebugTraceSource(DUTIL_SOURCE_XMLUTIL, x, s, __VA_ARGS__)
9#define XmlExitWithLastError(x, s, ...) ExitWithLastErrorSource(DUTIL_SOURCE_XMLUTIL, x, s, __VA_ARGS__)
10#define XmlExitOnFailure(x, s, ...) ExitOnFailureSource(DUTIL_SOURCE_XMLUTIL, x, s, __VA_ARGS__)
11#define XmlExitOnRootFailure(x, s, ...) ExitOnRootFailureSource(DUTIL_SOURCE_XMLUTIL, x, s, __VA_ARGS__)
12#define XmlExitOnFailureDebugTrace(x, s, ...) ExitOnFailureDebugTraceSource(DUTIL_SOURCE_XMLUTIL, x, s, __VA_ARGS__)
13#define XmlExitOnNull(p, x, e, s, ...) ExitOnNullSource(DUTIL_SOURCE_XMLUTIL, p, x, e, s, __VA_ARGS__)
14#define XmlExitOnNullWithLastError(p, x, s, ...) ExitOnNullWithLastErrorSource(DUTIL_SOURCE_XMLUTIL, p, x, s, __VA_ARGS__)
15#define XmlExitOnNullDebugTrace(p, x, e, s, ...) ExitOnNullDebugTraceSource(DUTIL_SOURCE_XMLUTIL, p, x, e, s, __VA_ARGS__)
16#define XmlExitOnInvalidHandleWithLastError(p, x, s, ...) ExitOnInvalidHandleWithLastErrorSource(DUTIL_SOURCE_XMLUTIL, p, x, s, __VA_ARGS__)
17#define XmlExitOnWin32Error(e, x, s, ...) ExitOnWin32ErrorSource(DUTIL_SOURCE_XMLUTIL, e, x, s, __VA_ARGS__)
18#define XmlExitOnGdipFailure(g, x, s, ...) ExitOnGdipFailureSource(DUTIL_SOURCE_XMLUTIL, g, x, s, __VA_ARGS__)
19
5// intialization globals 20// intialization globals
6CLSID vclsidXMLDOM = { 0, 0, 0, { 0, 0, 0, 0, 0, 0, 0, 0} }; 21CLSID vclsidXMLDOM = { 0, 0, 0, { 0, 0, 0, 0, 0, 0, 0, 0} };
7static volatile LONG vcXmlInitialized = 0; 22static volatile LONG vcXmlInitialized = 0;
@@ -23,7 +38,7 @@ extern "C" HRESULT DAPI XmlInitialize(
23 hr = ::CoInitialize(0); 38 hr = ::CoInitialize(0);
24 if (RPC_E_CHANGED_MODE != hr) 39 if (RPC_E_CHANGED_MODE != hr)
25 { 40 {
26 ExitOnFailure(hr, "failed to initialize COM"); 41 XmlExitOnFailure(hr, "failed to initialize COM");
27 fComInitialized = TRUE; 42 fComInitialized = TRUE;
28 } 43 }
29 } 44 }
@@ -47,7 +62,7 @@ extern "C" HRESULT DAPI XmlInitialize(
47 // try to fall back to old MSXML 62 // try to fall back to old MSXML
48 hr = ::CLSIDFromProgID(L"MSXML.DOMDocument", &vclsidXMLDOM); 63 hr = ::CLSIDFromProgID(L"MSXML.DOMDocument", &vclsidXMLDOM);
49 } 64 }
50 ExitOnFailure(hr, "failed to get CLSID for XML DOM"); 65 XmlExitOnFailure(hr, "failed to get CLSID for XML DOM");
51 66
52 Assert(IsEqualCLSID(vclsidXMLDOM, XmlUtil_CLSID_DOMDocument) || 67 Assert(IsEqualCLSID(vclsidXMLDOM, XmlUtil_CLSID_DOMDocument) ||
53 IsEqualCLSID(vclsidXMLDOM, XmlUtil_CLSID_DOMDocument20) || 68 IsEqualCLSID(vclsidXMLDOM, XmlUtil_CLSID_DOMDocument20) ||
@@ -99,7 +114,7 @@ extern "C" HRESULT DAPI XmlCreateElement(
99 114
100 HRESULT hr = S_OK; 115 HRESULT hr = S_OK;
101 BSTR bstrElementName = ::SysAllocString(wzElementName); 116 BSTR bstrElementName = ::SysAllocString(wzElementName);
102 ExitOnNull(bstrElementName, hr, E_OUTOFMEMORY, "failed SysAllocString"); 117 XmlExitOnNull(bstrElementName, hr, E_OUTOFMEMORY, "failed SysAllocString");
103 hr = pixdDocument->createElement(bstrElementName, ppixnElement); 118 hr = pixdDocument->createElement(bstrElementName, ppixnElement);
104LExit: 119LExit:
105 ReleaseBSTR(bstrElementName); 120 ReleaseBSTR(bstrElementName);
@@ -130,7 +145,7 @@ extern "C" HRESULT DAPI XmlCreateDocument(
130 145
131 // Test if we have access to the Wow64 API, and store the result in fWow64Available 146 // Test if we have access to the Wow64 API, and store the result in fWow64Available
132 HMODULE hKernel32 = ::GetModuleHandleA("kernel32.dll"); 147 HMODULE hKernel32 = ::GetModuleHandleA("kernel32.dll");
133 ExitOnNullWithLastError(hKernel32, hr, "failed to get handle to kernel32.dll"); 148 XmlExitOnNullWithLastError(hKernel32, hr, "failed to get handle to kernel32.dll");
134 149
135 // This will test if we have access to the Wow64 API 150 // This will test if we have access to the Wow64 API
136 if (NULL != GetProcAddress(hKernel32, "IsWow64Process")) 151 if (NULL != GetProcAddress(hKernel32, "IsWow64Process"))
@@ -155,7 +170,7 @@ extern "C" HRESULT DAPI XmlCreateDocument(
155 } 170 }
156 171
157 hr = ::CoCreateInstance(vclsidXMLDOM, NULL, CLSCTX_INPROC_SERVER, XmlUtil_IID_IXMLDOMDocument, (void**)&pixdDocument); 172 hr = ::CoCreateInstance(vclsidXMLDOM, NULL, CLSCTX_INPROC_SERVER, XmlUtil_IID_IXMLDOMDocument, (void**)&pixdDocument);
158 ExitOnFailure(hr, "failed to create XML DOM Document"); 173 XmlExitOnFailure(hr, "failed to create XML DOM Document");
159 Assert(pixdDocument); 174 Assert(pixdDocument);
160 175
161 if (IsEqualCLSID(vclsidXMLDOM, XmlUtil_CLSID_DOMDocument30) || IsEqualCLSID(vclsidXMLDOM, XmlUtil_CLSID_DOMDocument20)) 176 if (IsEqualCLSID(vclsidXMLDOM, XmlUtil_CLSID_DOMDocument30) || IsEqualCLSID(vclsidXMLDOM, XmlUtil_CLSID_DOMDocument20))
@@ -166,9 +181,9 @@ extern "C" HRESULT DAPI XmlCreateDocument(
166 if (pwzElementName) 181 if (pwzElementName)
167 { 182 {
168 hr = XmlCreateElement(pixdDocument, pwzElementName, &pixeRootElement); 183 hr = XmlCreateElement(pixdDocument, pwzElementName, &pixeRootElement);
169 ExitOnFailure(hr, "failed XmlCreateElement"); 184 XmlExitOnFailure(hr, "failed XmlCreateElement");
170 hr = pixdDocument->appendChild(pixeRootElement, NULL); 185 hr = pixdDocument->appendChild(pixeRootElement, NULL);
171 ExitOnFailure(hr, "failed appendChild"); 186 XmlExitOnFailure(hr, "failed appendChild");
172 } 187 }
173 188
174 *ppixdDocument = pixdDocument; 189 *ppixdDocument = pixdDocument;
@@ -222,28 +237,28 @@ static void XmlReportParseError(
222 Trace(REPORT_STANDARD, "Failed to parse XML. IXMLDOMParseError reports:"); 237 Trace(REPORT_STANDARD, "Failed to parse XML. IXMLDOMParseError reports:");
223 238
224 hr = pixpe->get_errorCode(&lNumber); 239 hr = pixpe->get_errorCode(&lNumber);
225 ExitOnFailure(hr, "Failed to query IXMLDOMParseError.errorCode."); 240 XmlExitOnFailure(hr, "Failed to query IXMLDOMParseError.errorCode.");
226 Trace(REPORT_STANDARD, "errorCode = 0x%x", lNumber); 241 Trace(REPORT_STANDARD, "errorCode = 0x%x", lNumber);
227 242
228 hr = pixpe->get_filepos(&lNumber); 243 hr = pixpe->get_filepos(&lNumber);
229 ExitOnFailure(hr, "Failed to query IXMLDOMParseError.filepos."); 244 XmlExitOnFailure(hr, "Failed to query IXMLDOMParseError.filepos.");
230 Trace(REPORT_STANDARD, "filepos = %d", lNumber); 245 Trace(REPORT_STANDARD, "filepos = %d", lNumber);
231 246
232 hr = pixpe->get_line(&lNumber); 247 hr = pixpe->get_line(&lNumber);
233 ExitOnFailure(hr, "Failed to query IXMLDOMParseError.line."); 248 XmlExitOnFailure(hr, "Failed to query IXMLDOMParseError.line.");
234 Trace(REPORT_STANDARD, "line = %d", lNumber); 249 Trace(REPORT_STANDARD, "line = %d", lNumber);
235 250
236 hr = pixpe->get_linepos(&lNumber); 251 hr = pixpe->get_linepos(&lNumber);
237 ExitOnFailure(hr, "Failed to query IXMLDOMParseError.linepos."); 252 XmlExitOnFailure(hr, "Failed to query IXMLDOMParseError.linepos.");
238 Trace(REPORT_STANDARD, "linepos = %d", lNumber); 253 Trace(REPORT_STANDARD, "linepos = %d", lNumber);
239 254
240 hr = pixpe->get_reason(&bstr); 255 hr = pixpe->get_reason(&bstr);
241 ExitOnFailure(hr, "Failed to query IXMLDOMParseError.reason."); 256 XmlExitOnFailure(hr, "Failed to query IXMLDOMParseError.reason.");
242 Trace(REPORT_STANDARD, "reason = %ls", bstr); 257 Trace(REPORT_STANDARD, "reason = %ls", bstr);
243 ReleaseNullBSTR(bstr); 258 ReleaseNullBSTR(bstr);
244 259
245 hr = pixpe->get_srcText (&bstr); 260 hr = pixpe->get_srcText (&bstr);
246 ExitOnFailure(hr, "Failed to query IXMLDOMParseError.srcText ."); 261 XmlExitOnFailure(hr, "Failed to query IXMLDOMParseError.srcText .");
247 Trace(REPORT_STANDARD, "srcText = %ls", bstr); 262 Trace(REPORT_STANDARD, "srcText = %ls", bstr);
248 ReleaseNullBSTR(bstr); 263 ReleaseNullBSTR(bstr);
249 264
@@ -272,7 +287,7 @@ extern "C" HRESULT DAPI XmlLoadDocumentEx(
272 if (!wzDocument || !*wzDocument) 287 if (!wzDocument || !*wzDocument)
273 { 288 {
274 hr = E_UNEXPECTED; 289 hr = E_UNEXPECTED;
275 ExitOnFailure(hr, "string must be non-null"); 290 XmlExitOnFailure(hr, "string must be non-null");
276 } 291 }
277 292
278 hr = XmlCreateDocument(NULL, &pixd); 293 hr = XmlCreateDocument(NULL, &pixd);
@@ -280,22 +295,22 @@ extern "C" HRESULT DAPI XmlLoadDocumentEx(
280 { 295 {
281 hr = E_FAIL; 296 hr = E_FAIL;
282 } 297 }
283 ExitOnFailure(hr, "failed XmlCreateDocument"); 298 XmlExitOnFailure(hr, "failed XmlCreateDocument");
284 299
285 if (dwAttributes & XML_LOAD_PRESERVE_WHITESPACE) 300 if (dwAttributes & XML_LOAD_PRESERVE_WHITESPACE)
286 { 301 {
287 hr = pixd->put_preserveWhiteSpace(VARIANT_TRUE); 302 hr = pixd->put_preserveWhiteSpace(VARIANT_TRUE);
288 ExitOnFailure(hr, "failed put_preserveWhiteSpace"); 303 XmlExitOnFailure(hr, "failed put_preserveWhiteSpace");
289 } 304 }
290 305
291 // Security issue. Avoid triggering anything external. 306 // Security issue. Avoid triggering anything external.
292 hr = pixd->put_validateOnParse(VARIANT_FALSE); 307 hr = pixd->put_validateOnParse(VARIANT_FALSE);
293 ExitOnFailure(hr, "failed put_validateOnParse"); 308 XmlExitOnFailure(hr, "failed put_validateOnParse");
294 hr = pixd->put_resolveExternals(VARIANT_FALSE); 309 hr = pixd->put_resolveExternals(VARIANT_FALSE);
295 ExitOnFailure(hr, "failed put_resolveExternals"); 310 XmlExitOnFailure(hr, "failed put_resolveExternals");
296 311
297 bstrLoad = ::SysAllocString(wzDocument); 312 bstrLoad = ::SysAllocString(wzDocument);
298 ExitOnNull(bstrLoad, hr, E_OUTOFMEMORY, "failed to allocate bstr for Load in XmlLoadDocumentEx"); 313 XmlExitOnNull(bstrLoad, hr, E_OUTOFMEMORY, "failed to allocate bstr for Load in XmlLoadDocumentEx");
299 314
300 hr = pixd->loadXML(bstrLoad, &vbSuccess); 315 hr = pixd->loadXML(bstrLoad, &vbSuccess);
301 if (S_FALSE == hr) 316 if (S_FALSE == hr)
@@ -308,7 +323,7 @@ extern "C" HRESULT DAPI XmlLoadDocumentEx(
308 XmlReportParseError(pixpe); 323 XmlReportParseError(pixpe);
309 } 324 }
310 325
311 ExitOnFailure(hr, "failed loadXML"); 326 XmlExitOnFailure(hr, "failed loadXML");
312 327
313 328
314 hr = S_OK; 329 hr = S_OK;
@@ -359,26 +374,26 @@ extern "C" HRESULT DAPI XmlLoadDocumentFromFileEx(
359 ::VariantInit(&varPath); 374 ::VariantInit(&varPath);
360 varPath.vt = VT_BSTR; 375 varPath.vt = VT_BSTR;
361 varPath.bstrVal = ::SysAllocString(wzPath); 376 varPath.bstrVal = ::SysAllocString(wzPath);
362 ExitOnNull(varPath.bstrVal, hr, E_OUTOFMEMORY, "failed to allocate bstr for Path in XmlLoadDocumentFromFileEx"); 377 XmlExitOnNull(varPath.bstrVal, hr, E_OUTOFMEMORY, "failed to allocate bstr for Path in XmlLoadDocumentFromFileEx");
363 378
364 hr = XmlCreateDocument(NULL, &pixd); 379 hr = XmlCreateDocument(NULL, &pixd);
365 if (hr == S_FALSE) 380 if (hr == S_FALSE)
366 { 381 {
367 hr = E_FAIL; 382 hr = E_FAIL;
368 } 383 }
369 ExitOnFailure(hr, "failed XmlCreateDocument"); 384 XmlExitOnFailure(hr, "failed XmlCreateDocument");
370 385
371 if (dwAttributes & XML_LOAD_PRESERVE_WHITESPACE) 386 if (dwAttributes & XML_LOAD_PRESERVE_WHITESPACE)
372 { 387 {
373 hr = pixd->put_preserveWhiteSpace(VARIANT_TRUE); 388 hr = pixd->put_preserveWhiteSpace(VARIANT_TRUE);
374 ExitOnFailure(hr, "failed put_preserveWhiteSpace"); 389 XmlExitOnFailure(hr, "failed put_preserveWhiteSpace");
375 } 390 }
376 391
377 // Avoid triggering anything external. 392 // Avoid triggering anything external.
378 hr = pixd->put_validateOnParse(VARIANT_FALSE); 393 hr = pixd->put_validateOnParse(VARIANT_FALSE);
379 ExitOnFailure(hr, "failed put_validateOnParse"); 394 XmlExitOnFailure(hr, "failed put_validateOnParse");
380 hr = pixd->put_resolveExternals(VARIANT_FALSE); 395 hr = pixd->put_resolveExternals(VARIANT_FALSE);
381 ExitOnFailure(hr, "failed put_resolveExternals"); 396 XmlExitOnFailure(hr, "failed put_resolveExternals");
382 397
383 pixd->put_async(VARIANT_FALSE); 398 pixd->put_async(VARIANT_FALSE);
384 hr = pixd->load(varPath, &vbSuccess); 399 hr = pixd->load(varPath, &vbSuccess);
@@ -392,7 +407,7 @@ extern "C" HRESULT DAPI XmlLoadDocumentFromFileEx(
392 XmlReportParseError(pixpe); 407 XmlReportParseError(pixpe);
393 } 408 }
394 409
395 ExitOnFailure(hr, "failed to load XML from: %ls", wzPath); 410 XmlExitOnFailure(hr, "failed to load XML from: %ls", wzPath);
396 411
397 if (ppixdDocument) 412 if (ppixdDocument)
398 { 413 {
@@ -434,13 +449,13 @@ extern "C" HRESULT DAPI XmlLoadDocumentFromBuffer(
434 { 449 {
435 hr = E_FAIL; 450 hr = E_FAIL;
436 } 451 }
437 ExitOnFailure(hr, "failed XmlCreateDocument"); 452 XmlExitOnFailure(hr, "failed XmlCreateDocument");
438 453
439 // Security issue. Avoid triggering anything external. 454 // Security issue. Avoid triggering anything external.
440 hr = pixdDocument->put_validateOnParse(VARIANT_FALSE); 455 hr = pixdDocument->put_validateOnParse(VARIANT_FALSE);
441 ExitOnFailure(hr, "failed put_validateOnParse"); 456 XmlExitOnFailure(hr, "failed put_validateOnParse");
442 hr = pixdDocument->put_resolveExternals(VARIANT_FALSE); 457 hr = pixdDocument->put_resolveExternals(VARIANT_FALSE);
443 ExitOnFailure(hr, "failed put_resolveExternals"); 458 XmlExitOnFailure(hr, "failed put_resolveExternals");
444 459
445 // load document 460 // load document
446 sa.cDims = 1; 461 sa.cDims = 1;
@@ -456,7 +471,7 @@ extern "C" HRESULT DAPI XmlLoadDocumentFromBuffer(
456 { 471 {
457 hr = HRESULT_FROM_WIN32(ERROR_OPEN_FAILED); 472 hr = HRESULT_FROM_WIN32(ERROR_OPEN_FAILED);
458 } 473 }
459 ExitOnFailure(hr, "failed loadXML"); 474 XmlExitOnFailure(hr, "failed loadXML");
460 475
461 // return value 476 // return value
462 *ppixdDocument = pixdDocument; 477 *ppixdDocument = pixdDocument;
@@ -488,20 +503,20 @@ extern "C" HRESULT DAPI XmlSetAttribute(
488 IXMLDOMAttribute* pixaAttribute = NULL; 503 IXMLDOMAttribute* pixaAttribute = NULL;
489 IXMLDOMNode* pixaNode = NULL; 504 IXMLDOMNode* pixaNode = NULL;
490 BSTR bstrAttributeName = ::SysAllocString(pwzAttribute); 505 BSTR bstrAttributeName = ::SysAllocString(pwzAttribute);
491 ExitOnNull(bstrAttributeName, hr, E_OUTOFMEMORY, "failed to allocate bstr for AttributeName in XmlSetAttribute"); 506 XmlExitOnNull(bstrAttributeName, hr, E_OUTOFMEMORY, "failed to allocate bstr for AttributeName in XmlSetAttribute");
492 507
493 hr = pixnNode->get_attributes(&pixnnmAttributes); 508 hr = pixnNode->get_attributes(&pixnnmAttributes);
494 ExitOnFailure(hr, "failed get_attributes in XmlSetAttribute(%ls)", pwzAttribute); 509 XmlExitOnFailure(hr, "failed get_attributes in XmlSetAttribute(%ls)", pwzAttribute);
495 510
496 hr = pixnNode->get_ownerDocument(&pixdDocument); 511 hr = pixnNode->get_ownerDocument(&pixdDocument);
497 if (hr == S_FALSE) 512 if (hr == S_FALSE)
498 { 513 {
499 hr = E_FAIL; 514 hr = E_FAIL;
500 } 515 }
501 ExitOnFailure(hr, "failed get_ownerDocument in XmlSetAttribute"); 516 XmlExitOnFailure(hr, "failed get_ownerDocument in XmlSetAttribute");
502 517
503 hr = pixdDocument->createAttribute(bstrAttributeName, &pixaAttribute); 518 hr = pixdDocument->createAttribute(bstrAttributeName, &pixaAttribute);
504 ExitOnFailure(hr, "failed createAttribute in XmlSetAttribute(%ls)", pwzAttribute); 519 XmlExitOnFailure(hr, "failed createAttribute in XmlSetAttribute(%ls)", pwzAttribute);
505 520
506 varAttributeValue.vt = VT_BSTR; 521 varAttributeValue.vt = VT_BSTR;
507 varAttributeValue.bstrVal = ::SysAllocString(pwzAttributeValue); 522 varAttributeValue.bstrVal = ::SysAllocString(pwzAttributeValue);
@@ -509,13 +524,13 @@ extern "C" HRESULT DAPI XmlSetAttribute(
509 { 524 {
510 hr = HRESULT_FROM_WIN32(ERROR_OUTOFMEMORY); 525 hr = HRESULT_FROM_WIN32(ERROR_OUTOFMEMORY);
511 } 526 }
512 ExitOnFailure(hr, "failed SysAllocString in XmlSetAttribute"); 527 XmlExitOnFailure(hr, "failed SysAllocString in XmlSetAttribute");
513 528
514 hr = pixaAttribute->put_nodeValue(varAttributeValue); 529 hr = pixaAttribute->put_nodeValue(varAttributeValue);
515 ExitOnFailure(hr, "failed put_nodeValue in XmlSetAttribute(%ls)", pwzAttribute); 530 XmlExitOnFailure(hr, "failed put_nodeValue in XmlSetAttribute(%ls)", pwzAttribute);
516 531
517 hr = pixnnmAttributes->setNamedItem(pixaAttribute, &pixaNode); 532 hr = pixnnmAttributes->setNamedItem(pixaAttribute, &pixaNode);
518 ExitOnFailure(hr, "failed setNamedItem in XmlSetAttribute(%ls)", pwzAttribute); 533 XmlExitOnFailure(hr, "failed setNamedItem in XmlSetAttribute(%ls)", pwzAttribute);
519 534
520LExit: 535LExit:
521 ReleaseObject(pixdDocument); 536 ReleaseObject(pixdDocument);
@@ -543,11 +558,11 @@ extern "C" HRESULT DAPI XmlSelectSingleNode(
543 558
544 BSTR bstrXPath = NULL; 559 BSTR bstrXPath = NULL;
545 560
546 ExitOnNull(pixnParent, hr, E_UNEXPECTED, "pixnParent parameter was null in XmlSelectSingleNode"); 561 XmlExitOnNull(pixnParent, hr, E_UNEXPECTED, "pixnParent parameter was null in XmlSelectSingleNode");
547 ExitOnNull(ppixnChild, hr, E_UNEXPECTED, "ppixnChild parameter was null in XmlSelectSingleNode"); 562 XmlExitOnNull(ppixnChild, hr, E_UNEXPECTED, "ppixnChild parameter was null in XmlSelectSingleNode");
548 563
549 bstrXPath = ::SysAllocString(wzXPath ? wzXPath : L""); 564 bstrXPath = ::SysAllocString(wzXPath ? wzXPath : L"");
550 ExitOnNull(bstrXPath, hr, E_OUTOFMEMORY, "failed to allocate bstr for XPath expression in XmlSelectSingleNode"); 565 XmlExitOnNull(bstrXPath, hr, E_OUTOFMEMORY, "failed to allocate bstr for XPath expression in XmlSelectSingleNode");
551 566
552 hr = pixnParent->selectSingleNode(bstrXPath, ppixnChild); 567 hr = pixnParent->selectSingleNode(bstrXPath, ppixnChild);
553 568
@@ -575,7 +590,7 @@ extern "C" HRESULT DAPI XmlCreateTextNode(
575 590
576 HRESULT hr = S_OK; 591 HRESULT hr = S_OK;
577 BSTR bstrText = ::SysAllocString(wzText); 592 BSTR bstrText = ::SysAllocString(wzText);
578 ExitOnNull(bstrText, hr, E_OUTOFMEMORY, "failed SysAllocString"); 593 XmlExitOnNull(bstrText, hr, E_OUTOFMEMORY, "failed SysAllocString");
579 hr = pixdDocument->createTextNode(bstrText, ppixnTextNode); 594 hr = pixdDocument->createTextNode(bstrText, ppixnTextNode);
580LExit: 595LExit:
581 ReleaseBSTR(bstrText); 596 ReleaseBSTR(bstrText);
@@ -621,7 +636,7 @@ extern "C" HRESULT DAPI XmlGetAttribute(
621 636
622 // get attribute value from source 637 // get attribute value from source
623 hr = pixnNode->get_attributes(&pixnnmAttributes); 638 hr = pixnNode->get_attributes(&pixnnmAttributes);
624 ExitOnFailure(hr, "failed get_attributes"); 639 XmlExitOnFailure(hr, "failed get_attributes");
625 640
626 hr = XmlGetNamedItem(pixnnmAttributes, bstrAttribute, &pixnAttribute); 641 hr = XmlGetNamedItem(pixnnmAttributes, bstrAttribute, &pixnAttribute);
627 if (S_FALSE == hr) 642 if (S_FALSE == hr)
@@ -629,10 +644,10 @@ extern "C" HRESULT DAPI XmlGetAttribute(
629 // hr = E_FAIL; 644 // hr = E_FAIL;
630 ExitFunction(); 645 ExitFunction();
631 } 646 }
632 ExitOnFailure(hr, "failed getNamedItem in XmlGetAttribute(%ls)", pwzAttribute); 647 XmlExitOnFailure(hr, "failed getNamedItem in XmlGetAttribute(%ls)", pwzAttribute);
633 648
634 hr = pixnAttribute->get_nodeValue(&varAttributeValue); 649 hr = pixnAttribute->get_nodeValue(&varAttributeValue);
635 ExitOnFailure(hr, "failed get_nodeValue in XmlGetAttribute(%ls)", pwzAttribute); 650 XmlExitOnFailure(hr, "failed get_nodeValue in XmlGetAttribute(%ls)", pwzAttribute);
636 651
637 // steal the BSTR from the VARIANT 652 // steal the BSTR from the VARIANT
638 if (S_OK == hr && pbstrAttributeValue) 653 if (S_OK == hr && pbstrAttributeValue)
@@ -672,28 +687,28 @@ HRESULT DAPI XmlGetAttributeEx(
672 687
673 // get attribute value from source 688 // get attribute value from source
674 hr = pixnNode->get_attributes(&pixnnmAttributes); 689 hr = pixnNode->get_attributes(&pixnnmAttributes);
675 ExitOnFailure(hr, "Failed get_attributes."); 690 XmlExitOnFailure(hr, "Failed get_attributes.");
676 691
677 bstrAttribute = ::SysAllocString(wzAttribute); 692 bstrAttribute = ::SysAllocString(wzAttribute);
678 ExitOnNull(bstrAttribute, hr, E_OUTOFMEMORY, "Failed to allocate attribute name BSTR."); 693 XmlExitOnNull(bstrAttribute, hr, E_OUTOFMEMORY, "Failed to allocate attribute name BSTR.");
679 694
680 hr = XmlGetNamedItem(pixnnmAttributes, bstrAttribute, &pixnAttribute); 695 hr = XmlGetNamedItem(pixnnmAttributes, bstrAttribute, &pixnAttribute);
681 if (S_FALSE == hr) 696 if (S_FALSE == hr)
682 { 697 {
683 ExitFunction1(hr = E_NOTFOUND); 698 ExitFunction1(hr = E_NOTFOUND);
684 } 699 }
685 ExitOnFailure(hr, "Failed getNamedItem in XmlGetAttribute(%ls)", wzAttribute); 700 XmlExitOnFailure(hr, "Failed getNamedItem in XmlGetAttribute(%ls)", wzAttribute);
686 701
687 hr = pixnAttribute->get_nodeValue(&varAttributeValue); 702 hr = pixnAttribute->get_nodeValue(&varAttributeValue);
688 if (S_FALSE == hr) 703 if (S_FALSE == hr)
689 { 704 {
690 ExitFunction1(hr = E_NOTFOUND); 705 ExitFunction1(hr = E_NOTFOUND);
691 } 706 }
692 ExitOnFailure(hr, "Failed get_nodeValue in XmlGetAttribute(%ls)", wzAttribute); 707 XmlExitOnFailure(hr, "Failed get_nodeValue in XmlGetAttribute(%ls)", wzAttribute);
693 708
694 // copy value 709 // copy value
695 hr = StrAllocString(psczAttributeValue, varAttributeValue.bstrVal, 0); 710 hr = StrAllocString(psczAttributeValue, varAttributeValue.bstrVal, 0);
696 ExitOnFailure(hr, "Failed to copy attribute value."); 711 XmlExitOnFailure(hr, "Failed to copy attribute value.");
697 712
698LExit: 713LExit:
699 ReleaseObject(pixnnmAttributes); 714 ReleaseObject(pixnnmAttributes);
@@ -721,7 +736,7 @@ HRESULT DAPI XmlGetYesNoAttribute(
721 hr = XmlGetAttributeEx(pixnNode, wzAttribute, &sczValue); 736 hr = XmlGetAttributeEx(pixnNode, wzAttribute, &sczValue);
722 if (E_NOTFOUND != hr) 737 if (E_NOTFOUND != hr)
723 { 738 {
724 ExitOnFailure(hr, "Failed to get attribute."); 739 XmlExitOnFailure(hr, "Failed to get attribute.");
725 740
726 *pfYes = CSTR_EQUAL == ::CompareStringW(LOCALE_INVARIANT, 0, sczValue, -1, L"yes", -1); 741 *pfYes = CSTR_EQUAL == ::CompareStringW(LOCALE_INVARIANT, 0, sczValue, -1, L"yes", -1);
727 } 742 }
@@ -764,7 +779,7 @@ extern "C" HRESULT DAPI XmlGetAttributeNumberBase(
764 BSTR bstrPointer = NULL; 779 BSTR bstrPointer = NULL;
765 780
766 hr = XmlGetAttribute(pixnNode, pwzAttribute, &bstrPointer); 781 hr = XmlGetAttribute(pixnNode, pwzAttribute, &bstrPointer);
767 ExitOnFailure(hr, "Failed to get value from attribute."); 782 XmlExitOnFailure(hr, "Failed to get value from attribute.");
768 783
769 if (S_OK == hr) 784 if (S_OK == hr)
770 { 785 {
@@ -791,13 +806,13 @@ extern "C" HRESULT DAPI XmlGetAttributeLargeNumber(
791 BSTR bstrValue = NULL; 806 BSTR bstrValue = NULL;
792 807
793 hr = XmlGetAttribute(pixnNode, pwzAttribute, &bstrValue); 808 hr = XmlGetAttribute(pixnNode, pwzAttribute, &bstrValue);
794 ExitOnFailure(hr, "failed XmlGetAttribute"); 809 XmlExitOnFailure(hr, "failed XmlGetAttribute");
795 810
796 if (S_OK == hr) 811 if (S_OK == hr)
797 { 812 {
798 LONGLONG ll = 0; 813 LONGLONG ll = 0;
799 hr = StrStringToInt64(bstrValue, 0, &ll); 814 hr = StrStringToInt64(bstrValue, 0, &ll);
800 ExitOnFailure(hr, "Failed to treat attribute value as number."); 815 XmlExitOnFailure(hr, "Failed to treat attribute value as number.");
801 816
802 *pdw64Value = ll; 817 *pdw64Value = ll;
803 } 818 }
@@ -829,7 +844,7 @@ extern "C" HRESULT DAPI XmlGetNamedItem(
829 844
830 HRESULT hr = S_OK; 845 HRESULT hr = S_OK;
831 BSTR bstrName = ::SysAllocString(wzName); 846 BSTR bstrName = ::SysAllocString(wzName);
832 ExitOnNull(bstrName, hr, E_OUTOFMEMORY, "failed SysAllocString"); 847 XmlExitOnNull(bstrName, hr, E_OUTOFMEMORY, "failed SysAllocString");
833 848
834 hr = pixnmAttributes->getNamedItem(bstrName, ppixnNamedItem); 849 hr = pixnmAttributes->getNamedItem(bstrName, ppixnNamedItem);
835 850
@@ -863,12 +878,12 @@ extern "C" HRESULT DAPI XmlSetText(
863 878
864 // find the text node 879 // find the text node
865 hr = pixnNode->get_childNodes(&pixnlNodeList); 880 hr = pixnNode->get_childNodes(&pixnlNodeList);
866 ExitOnFailure(hr, "failed to get child nodes"); 881 XmlExitOnFailure(hr, "failed to get child nodes");
867 882
868 while (S_OK == (hr = pixnlNodeList->nextNode(&pixnChildNode))) 883 while (S_OK == (hr = pixnlNodeList->nextNode(&pixnChildNode)))
869 { 884 {
870 hr = pixnChildNode->get_nodeType(&dnType); 885 hr = pixnChildNode->get_nodeType(&dnType);
871 ExitOnFailure(hr, "failed to get node type"); 886 XmlExitOnFailure(hr, "failed to get node type");
872 887
873 if (NODE_TEXT == dnType) 888 if (NODE_TEXT == dnType)
874 break; 889 break;
@@ -887,10 +902,10 @@ extern "C" HRESULT DAPI XmlSetText(
887 { 902 {
888 hr = HRESULT_FROM_WIN32(ERROR_OUTOFMEMORY); 903 hr = HRESULT_FROM_WIN32(ERROR_OUTOFMEMORY);
889 } 904 }
890 ExitOnFailure(hr, "failed SysAllocString in XmlSetText"); 905 XmlExitOnFailure(hr, "failed SysAllocString in XmlSetText");
891 906
892 hr = pixnChildNode->put_nodeValue(varText); 907 hr = pixnChildNode->put_nodeValue(varText);
893 ExitOnFailure(hr, "failed IXMLDOMNode::put_nodeValue"); 908 XmlExitOnFailure(hr, "failed IXMLDOMNode::put_nodeValue");
894 } 909 }
895 else 910 else
896 { 911 {
@@ -899,13 +914,13 @@ extern "C" HRESULT DAPI XmlSetText(
899 { 914 {
900 hr = E_FAIL; 915 hr = E_FAIL;
901 } 916 }
902 ExitOnFailure(hr, "failed get_ownerDocument in XmlSetAttribute"); 917 XmlExitOnFailure(hr, "failed get_ownerDocument in XmlSetAttribute");
903 918
904 hr = XmlCreateTextNode(pixdDocument, pwzText, &pixtTextNode); 919 hr = XmlCreateTextNode(pixdDocument, pwzText, &pixtTextNode);
905 ExitOnFailure(hr, "failed createTextNode in XmlSetText(%ls)", pwzText); 920 XmlExitOnFailure(hr, "failed createTextNode in XmlSetText(%ls)", pwzText);
906 921
907 hr = pixnNode->appendChild(pixtTextNode, NULL); 922 hr = pixnNode->appendChild(pixtTextNode, NULL);
908 ExitOnFailure(hr, "failed appendChild in XmlSetText(%ls)", pwzText); 923 XmlExitOnFailure(hr, "failed appendChild in XmlSetText(%ls)", pwzText);
909 } 924 }
910 925
911 hr = *pwzText ? S_OK : S_FALSE; 926 hr = *pwzText ? S_OK : S_FALSE;
@@ -933,7 +948,7 @@ extern "C" HRESULT DAPI XmlSetTextNumber(
933 WCHAR wzValue[12]; 948 WCHAR wzValue[12];
934 949
935 hr = ::StringCchPrintfW(wzValue, countof(wzValue), L"%u", dwValue); 950 hr = ::StringCchPrintfW(wzValue, countof(wzValue), L"%u", dwValue);
936 ExitOnFailure(hr, "Failed to format numeric value as string."); 951 XmlExitOnFailure(hr, "Failed to format numeric value as string.");
937 952
938 hr = XmlSetText(pixnNode, wzValue); 953 hr = XmlSetText(pixnNode, wzValue);
939 954
@@ -963,21 +978,21 @@ extern "C" HRESULT DAPI XmlCreateChild(
963 { 978 {
964 hr = E_FAIL; 979 hr = E_FAIL;
965 } 980 }
966 ExitOnFailure(hr, "failed get_ownerDocument"); 981 XmlExitOnFailure(hr, "failed get_ownerDocument");
967 982
968 hr = XmlCreateElement(pixdDocument, pwzElementType, (IXMLDOMElement**) &pixnChild); 983 hr = XmlCreateElement(pixdDocument, pwzElementType, (IXMLDOMElement**) &pixnChild);
969 if (hr == S_FALSE) 984 if (hr == S_FALSE)
970 { 985 {
971 hr = E_FAIL; 986 hr = E_FAIL;
972 } 987 }
973 ExitOnFailure(hr, "failed createElement"); 988 XmlExitOnFailure(hr, "failed createElement");
974 989
975 pixnParent->appendChild(pixnChild,NULL); 990 pixnParent->appendChild(pixnChild,NULL);
976 if (hr == S_FALSE) 991 if (hr == S_FALSE)
977 { 992 {
978 hr = E_FAIL; 993 hr = E_FAIL;
979 } 994 }
980 ExitOnFailure(hr, "failed appendChild"); 995 XmlExitOnFailure(hr, "failed appendChild");
981 996
982 if (ppixnChild) 997 if (ppixnChild)
983 { 998 {
@@ -1005,13 +1020,13 @@ extern "C" HRESULT DAPI XmlRemoveAttribute(
1005 // RELEASEME 1020 // RELEASEME
1006 IXMLDOMNamedNodeMap* pixnnmAttributes = NULL; 1021 IXMLDOMNamedNodeMap* pixnnmAttributes = NULL;
1007 BSTR bstrAttribute = ::SysAllocString(pwzAttribute); 1022 BSTR bstrAttribute = ::SysAllocString(pwzAttribute);
1008 ExitOnNull(bstrAttribute, hr, E_OUTOFMEMORY, "failed to allocate bstr for attribute in XmlRemoveAttribute"); 1023 XmlExitOnNull(bstrAttribute, hr, E_OUTOFMEMORY, "failed to allocate bstr for attribute in XmlRemoveAttribute");
1009 1024
1010 hr = pixnNode->get_attributes(&pixnnmAttributes); 1025 hr = pixnNode->get_attributes(&pixnnmAttributes);
1011 ExitOnFailure(hr, "failed get_attributes in RemoveXmlAttribute(%ls)", pwzAttribute); 1026 XmlExitOnFailure(hr, "failed get_attributes in RemoveXmlAttribute(%ls)", pwzAttribute);
1012 1027
1013 hr = pixnnmAttributes->removeNamedItem(bstrAttribute, NULL); 1028 hr = pixnnmAttributes->removeNamedItem(bstrAttribute, NULL);
1014 ExitOnFailure(hr, "failed removeNamedItem in RemoveXmlAttribute(%ls)", pwzAttribute); 1029 XmlExitOnFailure(hr, "failed removeNamedItem in RemoveXmlAttribute(%ls)", pwzAttribute);
1015 1030
1016LExit: 1031LExit:
1017 ReleaseObject(pixnnmAttributes); 1032 ReleaseObject(pixnnmAttributes);
@@ -1035,11 +1050,11 @@ extern "C" HRESULT DAPI XmlSelectNodes(
1035 1050
1036 BSTR bstrXPath = NULL; 1051 BSTR bstrXPath = NULL;
1037 1052
1038 ExitOnNull(pixnParent, hr, E_UNEXPECTED, "pixnParent parameter was null in XmlSelectNodes"); 1053 XmlExitOnNull(pixnParent, hr, E_UNEXPECTED, "pixnParent parameter was null in XmlSelectNodes");
1039 ExitOnNull(ppixnlChildren, hr, E_UNEXPECTED, "ppixnChild parameter was null in XmlSelectNodes"); 1054 XmlExitOnNull(ppixnlChildren, hr, E_UNEXPECTED, "ppixnChild parameter was null in XmlSelectNodes");
1040 1055
1041 bstrXPath = ::SysAllocString(wzXPath ? wzXPath : L""); 1056 bstrXPath = ::SysAllocString(wzXPath ? wzXPath : L"");
1042 ExitOnNull(bstrXPath, hr, E_OUTOFMEMORY, "failed to allocate bstr for XPath expression in XmlSelectNodes"); 1057 XmlExitOnNull(bstrXPath, hr, E_OUTOFMEMORY, "failed to allocate bstr for XPath expression in XmlSelectNodes");
1043 1058
1044 hr = pixnParent->selectNodes(bstrXPath, ppixnlChildren); 1059 hr = pixnParent->selectNodes(bstrXPath, ppixnlChildren);
1045 1060
@@ -1077,24 +1092,24 @@ extern "C" HRESULT DAPI XmlNextAttribute(
1077 } 1092 }
1078 1093
1079 hr = pixnnm->nextNode(&pixn); 1094 hr = pixnnm->nextNode(&pixn);
1080 ExitOnFailure(hr, "Failed to get next attribute."); 1095 XmlExitOnFailure(hr, "Failed to get next attribute.");
1081 1096
1082 if (S_OK == hr) 1097 if (S_OK == hr)
1083 { 1098 {
1084 hr = pixn->get_nodeType(&nt); 1099 hr = pixn->get_nodeType(&nt);
1085 ExitOnFailure(hr, "failed to get node type"); 1100 XmlExitOnFailure(hr, "failed to get node type");
1086 1101
1087 if (NODE_ATTRIBUTE != nt) 1102 if (NODE_ATTRIBUTE != nt)
1088 { 1103 {
1089 hr = E_UNEXPECTED; 1104 hr = E_UNEXPECTED;
1090 ExitOnFailure(hr, "Failed to get expected node type back: attribute"); 1105 XmlExitOnFailure(hr, "Failed to get expected node type back: attribute");
1091 } 1106 }
1092 1107
1093 // if the caller asked for the attribute name 1108 // if the caller asked for the attribute name
1094 if (pbstrAttribute) 1109 if (pbstrAttribute)
1095 { 1110 {
1096 hr = pixn->get_baseName(pbstrAttribute); 1111 hr = pixn->get_baseName(pbstrAttribute);
1097 ExitOnFailure(hr, "failed to get attribute name"); 1112 XmlExitOnFailure(hr, "failed to get attribute name");
1098 } 1113 }
1099 1114
1100 *pixnAttribute = pixn; 1115 *pixnAttribute = pixn;
@@ -1140,20 +1155,20 @@ extern "C" HRESULT DAPI XmlNextElement(
1140 while (S_OK == (hr = pixnl->nextNode(&pixn))) 1155 while (S_OK == (hr = pixnl->nextNode(&pixn)))
1141 { 1156 {
1142 hr = pixn->get_nodeType(&nt); 1157 hr = pixn->get_nodeType(&nt);
1143 ExitOnFailure(hr, "failed to get node type"); 1158 XmlExitOnFailure(hr, "failed to get node type");
1144 1159
1145 if (NODE_ELEMENT == nt) 1160 if (NODE_ELEMENT == nt)
1146 break; 1161 break;
1147 1162
1148 ReleaseNullObject(pixn); 1163 ReleaseNullObject(pixn);
1149 } 1164 }
1150 ExitOnFailure(hr, "failed to get next element"); 1165 XmlExitOnFailure(hr, "failed to get next element");
1151 1166
1152 // if we have a node and the caller asked for the element name 1167 // if we have a node and the caller asked for the element name
1153 if (pixn && pbstrElement) 1168 if (pixn && pbstrElement)
1154 { 1169 {
1155 hr = pixn->get_baseName(pbstrElement); 1170 hr = pixn->get_baseName(pbstrElement);
1156 ExitOnFailure(hr, "failed to get element name"); 1171 XmlExitOnFailure(hr, "failed to get element name");
1157 } 1172 }
1158 1173
1159 *pixnElement = pixn; 1174 *pixnElement = pixn;
@@ -1185,12 +1200,12 @@ extern "C" HRESULT DAPI XmlRemoveChildren(
1185 if (pwzXPath) 1200 if (pwzXPath)
1186 { 1201 {
1187 hr = XmlSelectNodes(pixnSource, pwzXPath, &pixnlNodeList); 1202 hr = XmlSelectNodes(pixnSource, pwzXPath, &pixnlNodeList);
1188 ExitOnFailure(hr, "failed XmlSelectNodes"); 1203 XmlExitOnFailure(hr, "failed XmlSelectNodes");
1189 } 1204 }
1190 else 1205 else
1191 { 1206 {
1192 hr = pixnSource->get_childNodes(&pixnlNodeList); 1207 hr = pixnSource->get_childNodes(&pixnlNodeList);
1193 ExitOnFailure(hr, "failed childNodes"); 1208 XmlExitOnFailure(hr, "failed childNodes");
1194 } 1209 }
1195 if (S_FALSE == hr) 1210 if (S_FALSE == hr)
1196 { 1211 {
@@ -1200,7 +1215,7 @@ extern "C" HRESULT DAPI XmlRemoveChildren(
1200 while (S_OK == (hr = pixnlNodeList->nextNode(&pixnNode))) 1215 while (S_OK == (hr = pixnlNodeList->nextNode(&pixnNode)))
1201 { 1216 {
1202 hr = pixnSource->removeChild(pixnNode, &pixnRemoveChild); 1217 hr = pixnSource->removeChild(pixnNode, &pixnRemoveChild);
1203 ExitOnFailure(hr, "failed removeChild"); 1218 XmlExitOnFailure(hr, "failed removeChild");
1204 1219
1205 ReleaseNullObject(pixnRemoveChild); 1220 ReleaseNullObject(pixnRemoveChild);
1206 ReleaseNullObject(pixnNode); 1221 ReleaseNullObject(pixnNode);
@@ -1240,14 +1255,14 @@ extern "C" HRESULT DAPI XmlSaveDocument(
1240 { 1255 {
1241 hr = HRESULT_FROM_WIN32(ERROR_OUTOFMEMORY); 1256 hr = HRESULT_FROM_WIN32(ERROR_OUTOFMEMORY);
1242 } 1257 }
1243 ExitOnFailure(hr, "failed to create BSTR"); 1258 XmlExitOnFailure(hr, "failed to create BSTR");
1244 1259
1245 hr = pixdDocument->save(varsDestPath); 1260 hr = pixdDocument->save(varsDestPath);
1246 if (hr == S_FALSE) 1261 if (hr == S_FALSE)
1247 { 1262 {
1248 hr = E_FAIL; 1263 hr = E_FAIL;
1249 } 1264 }
1250 ExitOnFailure(hr, "failed save in WriteDocument"); 1265 XmlExitOnFailure(hr, "failed save in WriteDocument");
1251 1266
1252LExit: 1267LExit:
1253 ReleaseVariant(varsDestPath); 1268 ReleaseVariant(varsDestPath);
@@ -1277,33 +1292,33 @@ extern "C" HRESULT DAPI XmlSaveDocumentToBuffer(
1277 1292
1278 // create stream 1293 // create stream
1279 hr = ::CreateStreamOnHGlobal(NULL, TRUE, &pStream); 1294 hr = ::CreateStreamOnHGlobal(NULL, TRUE, &pStream);
1280 ExitOnFailure(hr, "Failed to create stream."); 1295 XmlExitOnFailure(hr, "Failed to create stream.");
1281 1296
1282 // write document to stream 1297 // write document to stream
1283 vtDestination.vt = VT_UNKNOWN; 1298 vtDestination.vt = VT_UNKNOWN;
1284 vtDestination.punkVal = (IUnknown*)pStream; 1299 vtDestination.punkVal = (IUnknown*)pStream;
1285 hr = pixdDocument->save(vtDestination); 1300 hr = pixdDocument->save(vtDestination);
1286 ExitOnFailure(hr, "Failed to save document."); 1301 XmlExitOnFailure(hr, "Failed to save document.");
1287 1302
1288 // get stream size 1303 // get stream size
1289 hr = pStream->Stat(&statstg, STATFLAG_NONAME); 1304 hr = pStream->Stat(&statstg, STATFLAG_NONAME);
1290 ExitOnFailure(hr, "Failed to get stream size."); 1305 XmlExitOnFailure(hr, "Failed to get stream size.");
1291 1306
1292 // allocate buffer 1307 // allocate buffer
1293 pbDest = static_cast<BYTE*>(MemAlloc((SIZE_T)statstg.cbSize.LowPart, TRUE)); 1308 pbDest = static_cast<BYTE*>(MemAlloc((SIZE_T)statstg.cbSize.LowPart, TRUE));
1294 ExitOnNull(pbDest, hr, E_OUTOFMEMORY, "Failed to allocate destination buffer."); 1309 XmlExitOnNull(pbDest, hr, E_OUTOFMEMORY, "Failed to allocate destination buffer.");
1295 1310
1296 // read data from stream 1311 // read data from stream
1297 li.QuadPart = 0; 1312 li.QuadPart = 0;
1298 hr = pStream->Seek(li, STREAM_SEEK_SET, NULL); 1313 hr = pStream->Seek(li, STREAM_SEEK_SET, NULL);
1299 ExitOnFailure(hr, "Failed to seek stream."); 1314 XmlExitOnFailure(hr, "Failed to seek stream.");
1300 1315
1301 hr = pStream->Read(pbDest, statstg.cbSize.LowPart, &cbRead); 1316 hr = pStream->Read(pbDest, statstg.cbSize.LowPart, &cbRead);
1302 if (cbRead < statstg.cbSize.LowPart) 1317 if (cbRead < statstg.cbSize.LowPart)
1303 { 1318 {
1304 hr = E_FAIL; 1319 hr = E_FAIL;
1305 } 1320 }
1306 ExitOnFailure(hr, "Failed to read stream content to buffer."); 1321 XmlExitOnFailure(hr, "Failed to read stream content to buffer.");
1307 1322
1308 // return value 1323 // return value
1309 *ppbDest = pbDest; 1324 *ppbDest = pbDest;