22template<
class _Traits,
class _Ax>
23static UINT MsiGetPropertyA(_In_ MSIHANDLE hInstall, _In_z_ LPCSTR szName, _Inout_ std::basic_string<char, _Traits, _Ax> &sValue)
28 DWORD dwSize = _countof(szStackBuffer);
32 uiResult = ::MsiGetPropertyA(hInstall, szName, szStackBuffer, &dwSize);
33 if (uiResult == ERROR_SUCCESS) {
35 sValue.assign(szStackBuffer, dwSize);
37 }
else if (uiResult == ERROR_MORE_DATA) {
39 std::unique_ptr<char[]> szBuffer(
new char[++dwSize]);
40 uiResult = ::MsiGetPropertyA(hInstall, szName, szBuffer.get(), &dwSize);
41 sValue.assign(szBuffer.get(), uiResult == ERROR_SUCCESS ? dwSize : 0);
54template<
class _Traits,
class _Ax>
55static UINT MsiGetPropertyW(_In_ MSIHANDLE hInstall, _In_z_ LPCWSTR szName, _Inout_ std::basic_string<wchar_t, _Traits, _Ax> &sValue)
58 DWORD dwSize = _countof(szStackBuffer);
62 uiResult = ::MsiGetPropertyW(hInstall, szName, szStackBuffer, &dwSize);
63 if (uiResult == ERROR_SUCCESS) {
65 sValue.assign(szStackBuffer, dwSize);
67 }
else if (uiResult == ERROR_MORE_DATA) {
69 std::unique_ptr<wchar_t[]> szBuffer(
new wchar_t[++dwSize]);
70 uiResult = ::MsiGetPropertyW(hInstall, szName, szBuffer.get(), &dwSize);
71 sValue.assign(szBuffer.get(), uiResult == ERROR_SUCCESS ? dwSize : 0);
80template<
class _Traits,
class _Ax>
81static UINT MsiRecordGetStringA(_In_ MSIHANDLE hRecord, _In_
unsigned int iField, _Inout_ std::basic_string<char, _Traits, _Ax> &sValue)
86 DWORD dwSize = _countof(szStackBuffer);
90 uiResult = ::MsiRecordGetStringA(hRecord, iField, szStackBuffer, &dwSize);
91 if (uiResult == ERROR_SUCCESS) {
93 sValue.assign(szStackBuffer, dwSize);
95 }
else if (uiResult == ERROR_MORE_DATA) {
97 std::unique_ptr<char[]> szBuffer(
new char[++dwSize]);
98 uiResult = ::MsiRecordGetStringA(hRecord, iField, szBuffer.get(), &dwSize);
99 sValue.assign(szBuffer.get(), uiResult == ERROR_SUCCESS ? dwSize : 0);
112template<
class _Traits,
class _Ax>
113static UINT MsiRecordGetStringW(_In_ MSIHANDLE hRecord, _In_
unsigned int iField, _Inout_ std::basic_string<wchar_t, _Traits, _Ax> &sValue)
116 DWORD dwSize = _countof(szStackBuffer);
120 uiResult = ::MsiRecordGetStringW(hRecord, iField, szStackBuffer, &dwSize);
121 if (uiResult == ERROR_SUCCESS) {
123 sValue.assign(szStackBuffer, dwSize);
124 return ERROR_SUCCESS;
125 }
else if (uiResult == ERROR_MORE_DATA) {
127 std::unique_ptr<wchar_t[]> szBuffer(
new wchar_t[++dwSize]);
128 uiResult = ::MsiRecordGetStringW(hRecord, iField, szBuffer.get(), &dwSize);
129 sValue.assign(szBuffer.get(), uiResult == ERROR_SUCCESS ? dwSize : 0);
138template<
class _Traits,
class _Ax>
139static UINT MsiFormatRecordA(_In_ MSIHANDLE hInstall, _In_ MSIHANDLE hRecord, _Inout_ std::basic_string<char, _Traits, _Ax> &sValue)
144 DWORD dwSize = _countof(szStackBuffer);
148 uiResult = ::MsiFormatRecordA(hInstall, hRecord, szStackBuffer, &dwSize);
149 if (uiResult == ERROR_SUCCESS) {
151 sValue.assign(szStackBuffer, dwSize);
152 return ERROR_SUCCESS;
153 }
else if (uiResult == ERROR_MORE_DATA) {
155 std::unique_ptr<char[]> szBuffer(
new char[++dwSize]);
156 uiResult = ::MsiFormatRecordA(hInstall, hRecord, szBuffer.get(), &dwSize);
157 sValue.assign(szBuffer.get(), uiResult == ERROR_SUCCESS ? dwSize : 0);
170template<
class _Traits,
class _Ax>
171static UINT MsiFormatRecordW(_In_ MSIHANDLE hInstall, _In_ MSIHANDLE hRecord, _Inout_ std::basic_string<wchar_t, _Traits, _Ax> &sValue)
174 DWORD dwSize = _countof(szStackBuffer);
178 uiResult = ::MsiFormatRecordW(hInstall, hRecord, szStackBuffer, &dwSize);
179 if (uiResult == ERROR_SUCCESS) {
181 sValue.assign(szStackBuffer, dwSize);
182 return ERROR_SUCCESS;
183 }
else if (uiResult == ERROR_MORE_DATA) {
185 std::unique_ptr<wchar_t[]> szBuffer(
new wchar_t[++dwSize]);
186 uiResult = ::MsiFormatRecordW(hInstall, hRecord, szBuffer.get(), &dwSize);
187 sValue.assign(szBuffer.get(), uiResult == ERROR_SUCCESS ? dwSize : 0);
200template<
class _Ty,
class _Ax>
201static UINT MsiRecordReadStream(_In_ MSIHANDLE hRecord, _In_
unsigned int iField, _Inout_ std::vector<_Ty, _Ax> &binData)
209 uiResult = ::MsiRecordReadStream(hRecord, iField, NULL, &dwSize);
210 if (uiResult == ERROR_SUCCESS) {
211 binData.resize((dwSize +
sizeof(_Ty) - 1) /
sizeof(_Ty));
212 return ::MsiRecordReadStream(hRecord, iField,
reinterpret_cast<char*
>(binData.data()), &dwSize);
220template<
class _Traits,
class _Ax>
221static UINT MsiGetTargetPathA(_In_ MSIHANDLE hInstall, _In_z_ LPCSTR szFolder, _Out_ std::basic_string<char, _Traits, _Ax> &sValue)
226 DWORD dwSize = _countof(szStackBuffer);
230 uiResult = ::MsiGetTargetPathA(hInstall, szFolder, szStackBuffer, &dwSize);
231 if (uiResult == ERROR_SUCCESS) {
233 sValue.assign(szStackBuffer, dwSize);
234 return ERROR_SUCCESS;
235 }
else if (uiResult == ERROR_MORE_DATA) {
237 std::unique_ptr<char[]> szBuffer(
new char[++dwSize]);
238 uiResult = ::MsiGetTargetPathA(hInstall, szFolder, szBuffer.get(), &dwSize);
239 sValue.assign(szBuffer.get(), uiResult == ERROR_SUCCESS ? dwSize : 0);
252template<
class _Traits,
class _Ax>
253static UINT MsiGetTargetPathW(_In_ MSIHANDLE hInstall, _In_z_ LPCWSTR szFolder, _Inout_ std::basic_string<wchar_t, _Traits, _Ax> &sValue)
256 DWORD dwSize = _countof(szStackBuffer);
260 uiResult = ::MsiGetTargetPathW(hInstall, szFolder, szStackBuffer, &dwSize);
261 if (uiResult == ERROR_SUCCESS) {
263 sValue.assign(szStackBuffer, dwSize);
264 return ERROR_SUCCESS;
265 }
else if (uiResult == ERROR_MORE_DATA) {
267 std::unique_ptr<wchar_t[]> szBuffer(
new wchar_t[++dwSize]);
268 uiResult = ::MsiGetTargetPathW(hInstall, szFolder, szBuffer.get(), &dwSize);
269 sValue.assign(szBuffer.get(), uiResult == ERROR_SUCCESS ? dwSize : 0);
278template<
class _Traits,
class _Ax>
279static INSTALLSTATE MsiGetComponentPathA(_In_z_ LPCSTR szProduct, _In_z_ LPCSTR szComponent, _Inout_ std::basic_string<char, _Traits, _Ax> &sValue)
282 DWORD dwSize = _countof(szStackBuffer);
286 state = ::MsiGetComponentPathA(szProduct, szComponent, szStackBuffer, &dwSize);
287 if (state >= INSTALLSTATE_BROKEN) {
289 sValue.assign(szStackBuffer, dwSize);
291 }
else if (state == INSTALLSTATE_MOREDATA) {
293 std::unique_ptr<char[]> szBuffer(
new char[++dwSize]);
294 state = ::MsiGetComponentPathA(szProduct, szComponent, szBuffer.get(), &dwSize);
295 sValue.assign(szBuffer.get(), state >= INSTALLSTATE_BROKEN ? dwSize : 0);
308template<
class _Traits,
class _Ax>
309static INSTALLSTATE MsiGetComponentPathW(_In_z_ LPCWSTR szProduct, _In_z_ LPCWSTR szComponent, _Inout_ std::basic_string<wchar_t, _Traits, _Ax> &sValue)
312 DWORD dwSize = _countof(szStackBuffer);
316 state = ::MsiGetComponentPathW(szProduct, szComponent, szStackBuffer, &dwSize);
317 if (state >= INSTALLSTATE_BROKEN) {
319 sValue.assign(szStackBuffer, dwSize);
321 }
else if (state == INSTALLSTATE_MOREDATA) {
323 std::unique_ptr<wchar_t[]> szBuffer(
new wchar_t[++dwSize]);
324 state = ::MsiGetComponentPathW(szProduct, szComponent, szBuffer.get(), &dwSize);
325 sValue.assign(szBuffer.get(), state >= INSTALLSTATE_BROKEN ? dwSize : 0);
#define WINSTD_STACK_BUFFER_BYTES
Size of the stack buffer in bytes used for initial system function call.
Definition: Common.h:80