ReactOS 0.4.15-dev-7961-gdcf9eb0
xmldomparser.hpp File Reference
#include <initguid.h>
#include <comdef.h>
#include <ole2.h>
#include <msxml2.h>
Include dependency graph for xmldomparser.hpp:
This graph shows which files directly or indirectly include this file:

Go to the source code of this file.

Macros

#define _COM_NO_STANDARD_GUIDS_
 
#define SAFE_RELEASE(p)    do { if ((p)) { (p)->Release(); (p) = NULL; } } while (0)
 
#define IID_PPV_ARG(Itype, ppType)   IID_##Itype, (void**)(ppType)
 
#define IID_NULL_PPV_ARG(Itype, ppType)   IID_##Itype, NULL, (void**)(ppType)
 

Functions

HRESULT InitXMLDOMParser (void)
 
void UninitXMLDOMParser (void)
 
HRESULT CreateAndInitXMLDOMDocument (IXMLDOMDocument **ppDoc)
 
BOOL LoadXMLDocumentFromResource (IXMLDOMDocument *pXMLDom, LPCWSTR lpszXMLResName)
 
BOOL LoadXMLDocumentFromFile (IXMLDOMDocument *pXMLDom, LPCWSTR lpszFilename, BOOL bIgnoreErrorsIfNonExistingFile=FALSE)
 

Macro Definition Documentation

◆ _COM_NO_STANDARD_GUIDS_

#define _COM_NO_STANDARD_GUIDS_

Definition at line 22 of file xmldomparser.hpp.

◆ IID_NULL_PPV_ARG

#define IID_NULL_PPV_ARG (   Itype,
  ppType 
)    IID_##Itype, NULL, (void**)(ppType)

Definition at line 62 of file xmldomparser.hpp.

◆ IID_PPV_ARG

#define IID_PPV_ARG (   Itype,
  ppType 
)    IID_##Itype, (void**)(ppType)

Definition at line 61 of file xmldomparser.hpp.

◆ SAFE_RELEASE

#define SAFE_RELEASE (   p)     do { if ((p)) { (p)->Release(); (p) = NULL; } } while (0)

Definition at line 32 of file xmldomparser.hpp.

Function Documentation

◆ CreateAndInitXMLDOMDocument()

HRESULT CreateAndInitXMLDOMDocument ( IXMLDOMDocument **  ppDoc)

Definition at line 64 of file xmldomparser.cpp.

65{
66 HRESULT hr = CoCreateInstance(CLSID_DOMDocument30, // __uuidof(DOMDocument30), // NOTE: Do not use DOMDocument60 if you want MSConfig working by default on XP.
67 NULL,
68 CLSCTX_INPROC_SERVER,
69 IID_PPV_ARG(IXMLDOMDocument, ppDoc) /* IID_PPV_ARGS(ppDoc) */);
70 if (!SUCCEEDED(hr))
71 return hr;
72
73 /* These methods should not fail so don't inspect result */
74 (*ppDoc)->put_async(VARIANT_FALSE);
75 (*ppDoc)->put_validateOnParse(VARIANT_FALSE);
76 (*ppDoc)->put_resolveExternals(VARIANT_FALSE);
77
78 return hr;
79}
#define NULL
Definition: types.h:112
HRESULT WINAPI DECLSPEC_HOTPATCH CoCreateInstance(REFCLSID rclsid, LPUNKNOWN pUnkOuter, DWORD dwClsContext, REFIID iid, LPVOID *ppv)
Definition: compobj.c:3325
#define SUCCEEDED(hr)
Definition: intsafe.h:50
HRESULT hr
Definition: shlfolder.c:183
#define IID_PPV_ARG(Itype, ppType)

Referenced by FillListView().

◆ InitXMLDOMParser()

HRESULT InitXMLDOMParser ( void  )

Definition at line 51 of file xmldomparser.cpp.

52{
53 return CoInitialize(NULL);
54}
HRESULT WINAPI CoInitialize(LPVOID lpReserved)
Definition: compobj.c:1964

Referenced by FillListView().

◆ LoadXMLDocumentFromFile()

BOOL LoadXMLDocumentFromFile ( IXMLDOMDocument pXMLDom,
LPCWSTR  lpszFilename,
BOOL  bIgnoreErrorsIfNonExistingFile = FALSE 
)

Definition at line 143 of file xmldomparser.cpp.

146{
147 VARIANT_BOOL Success = VARIANT_FALSE;
148 _variant_t varFileName(lpszFilename);
149
150 if (!pDoc)
151 return FALSE;
152
153 if (SUCCEEDED(pDoc->load(varFileName, &Success)) && (Success != VARIANT_TRUE))
154 {
155 IXMLDOMParseError* pXMLErr = NULL;
156 LONG lErrorCode = 0L;
157
158 if (SUCCEEDED(pDoc->get_parseError(&pXMLErr)) &&
159 SUCCEEDED(pXMLErr->get_errorCode(&lErrorCode)))
160 {
161 if ( !bIgnoreErrorsIfNonExistingFile ||
162 ((lErrorCode != _HRESULT_TYPEDEF_(0x800C0006) /* INET_E_OBJECT_NOT_FOUND */) &&
163 (lErrorCode != HRESULT_FROM_WIN32(ERROR_FILE_NOT_FOUND))) )
164 {
165 _bstr_t bstrErr;
166
167 if (SUCCEEDED(pXMLErr->get_reason(&bstrErr.GetBSTR())))
168 {
169 LPWSTR lpszStr = FormatString(L"Failed to load DOM from '%wS': %wS", lpszFilename, (wchar_t*)bstrErr);
170 MessageBoxW(NULL, lpszStr, L"Error", MB_ICONERROR | MB_OK);
171 MemFree(lpszStr);
172 }
173 }
174 }
175
176 SAFE_RELEASE(pXMLErr);
177 }
178
179 return (Success == VARIANT_TRUE);
180}
BOOL MemFree(IN PVOID lpMem)
Definition: utils.c:26
#define FALSE
Definition: types.h:117
short VARIANT_BOOL
Definition: compat.h:2290
@ Success
Definition: eventcreate.c:712
DWORD FormatString(DWORD dwFlags, HINSTANCE hInstance, DWORD dwStringId, DWORD dwLanguageId, LPWSTR lpBuffer, DWORD nSize, va_list *Arguments)
Definition: fontview.c:34
#define ERROR_FILE_NOT_FOUND
Definition: disk.h:79
#define L(x)
Definition: ntvdm.h:50
long LONG
Definition: pedump.c:60
#define _HRESULT_TYPEDEF_(x)
Definition: winerror.h:2351
#define HRESULT_FROM_WIN32(x)
Definition: winerror.h:92
int WINAPI MessageBoxW(_In_opt_ HWND hWnd, _In_opt_ LPCWSTR lpText, _In_opt_ LPCWSTR lpCaption, _In_ UINT uType)
#define MB_ICONERROR
Definition: winuser.h:787
#define MB_OK
Definition: winuser.h:790
#define SAFE_RELEASE(p)
WCHAR * LPWSTR
Definition: xmlstorage.h:184

Referenced by FillListView().

◆ LoadXMLDocumentFromResource()

BOOL LoadXMLDocumentFromResource ( IXMLDOMDocument pXMLDom,
LPCWSTR  lpszXMLResName 
)

Definition at line 82 of file xmldomparser.cpp.

84{
85 VARIANT_BOOL Success = VARIANT_FALSE;
86 HRSRC hRes;
88 LPVOID lpXMLRes;
89 _bstr_t bstrXMLRes;
90
91 if (!pDoc)
92 return FALSE;
93
94 // hRes = FindResourceExW(NULL, RT_HTML, lpszXMLResName, MAKELANGID(LANG_NEUTRAL, SUBLANG_NEUTRAL));
95 hRes = FindResourceW(NULL, lpszXMLResName, RT_HTML);
96 if (hRes == NULL)
97 return FALSE;
98
99 handle = LoadResource(NULL, hRes);
100 if (handle == NULL)
101 return FALSE;
102
103 lpXMLRes = LockResource(handle);
104 if (lpXMLRes == NULL)
105 goto Cleanup;
106
107 /* Convert the resource to UNICODE if needed */
108 if (!IsTextUnicode(lpXMLRes, SizeofResource(NULL, hRes), NULL))
109 bstrXMLRes.Attach(ConvertUTF8StringToBSTR((LPCSTR)lpXMLRes));
110 else
111 bstrXMLRes = (LPCWSTR)lpXMLRes;
112
113 if (SUCCEEDED(pDoc->loadXML(bstrXMLRes, &Success)) && (Success != VARIANT_TRUE))
114 {
115 IXMLDOMParseError* pXMLErr = NULL;
116 _bstr_t bstrErr;
117
118 if (SUCCEEDED(pDoc->get_parseError(&pXMLErr)) &&
119 SUCCEEDED(pXMLErr->get_reason(&bstrErr.GetBSTR())))
120 {
121 LPWSTR lpszStr = NULL;
122
123 if (IS_INTRESOURCE((ULONG_PTR)lpszXMLResName))
124 lpszStr = FormatString(L"Failed to load DOM from resource '#%u': %wS", lpszXMLResName, (wchar_t*)bstrErr);
125 else
126 lpszStr = FormatString(L"Failed to load DOM from resource '%wS': %wS", lpszXMLResName, (wchar_t*)bstrErr);
127
128 MessageBoxW(NULL, lpszStr, L"Error", MB_ICONERROR | MB_OK);
129
130 MemFree(lpszStr);
131 }
132
133 SAFE_RELEASE(pXMLErr);
134 }
135
136Cleanup:
138
139 return (Success == VARIANT_TRUE);
140}
BOOL WINAPI IsTextUnicode(IN CONST VOID *lpv, IN INT iSize, IN OUT LPINT lpiResult OPTIONAL)
Definition: unicode.c:27
BOOL WINAPI FreeResource(HGLOBAL handle)
Definition: res.c:559
HRSRC WINAPI FindResourceW(HINSTANCE hModule, LPCWSTR name, LPCWSTR type)
Definition: res.c:176
DWORD WINAPI SizeofResource(HINSTANCE hModule, HRSRC hRsrc)
Definition: res.c:568
LPVOID WINAPI LockResource(HGLOBAL handle)
Definition: res.c:550
HGLOBAL WINAPI LoadResource(HINSTANCE hModule, HRSRC hRsrc)
Definition: res.c:532
static const WCHAR Cleanup[]
Definition: register.c:80
uint32_t ULONG_PTR
Definition: typedefs.h:65
#define RT_HTML
Definition: winuser.h:619
#define IS_INTRESOURCE(i)
Definition: winuser.h:580
static BSTR ConvertUTF8StringToBSTR(const char *pSrc)
const char * LPCSTR
Definition: xmlstorage.h:183
const WCHAR * LPCWSTR
Definition: xmlstorage.h:185

Referenced by FillListView().

◆ UninitXMLDOMParser()

void UninitXMLDOMParser ( void  )

Definition at line 57 of file xmldomparser.cpp.

58{
60 return;
61}
void WINAPI DECLSPEC_HOTPATCH CoUninitialize(void)
Definition: compobj.c:2067

Referenced by FillListView().