41 return ERROR_BAD_ARGUMENTS;
45 WCHAR szBufStack[128];
46 DWORD dwLength = _countof(szBufStack);
47 UINT uiResult = MsiGetProperty(hInstall, szName, szBufStack, &dwLength);
48 if (uiResult == ERROR_SUCCESS)
51 *pszValue = (LPWSTR)malloc(++dwLength *
sizeof(WCHAR));
52 if (*pszValue == NULL)
54 msg(
M_FATAL,
"%s: malloc(%u) failed", dwLength *
sizeof(WCHAR));
55 return ERROR_OUTOFMEMORY;
58 memcpy(*pszValue, szBufStack, dwLength *
sizeof(WCHAR));
61 else if (uiResult == ERROR_MORE_DATA)
64 LPWSTR szBufHeap = (LPWSTR)malloc(++dwLength *
sizeof(WCHAR));
65 if (szBufHeap == NULL)
67 msg(
M_FATAL,
"%s: malloc(%u) failed", __FUNCTION__, dwLength *
sizeof(WCHAR));
68 return ERROR_OUTOFMEMORY;
71 uiResult = MsiGetProperty(hInstall, szName, szBufHeap, &dwLength);
72 if (uiResult == ERROR_SUCCESS)
74 *pszValue = szBufHeap;
84 SetLastError(uiResult);
97 return ERROR_BAD_ARGUMENTS;
101 WCHAR szBufStack[128];
102 DWORD dwLength = _countof(szBufStack);
103 UINT uiResult = MsiRecordGetString(hRecord, iField, szBufStack, &dwLength);
104 if (uiResult == ERROR_SUCCESS)
107 *pszValue = (LPWSTR)malloc(++dwLength *
sizeof(WCHAR));
108 if (*pszValue == NULL)
110 msg(
M_FATAL,
"%s: malloc(%u) failed", __FUNCTION__, dwLength *
sizeof(WCHAR));
111 return ERROR_OUTOFMEMORY;
114 memcpy(*pszValue, szBufStack, dwLength *
sizeof(WCHAR));
115 return ERROR_SUCCESS;
117 else if (uiResult == ERROR_MORE_DATA)
120 LPWSTR szBufHeap = (LPWSTR)malloc(++dwLength *
sizeof(WCHAR));
121 if (szBufHeap == NULL)
123 msg(
M_FATAL,
"%s: malloc(%u) failed", __FUNCTION__, dwLength *
sizeof(WCHAR));
124 return ERROR_OUTOFMEMORY;
127 uiResult = MsiRecordGetString(hRecord, iField, szBufHeap, &dwLength);
128 if (uiResult == ERROR_SUCCESS)
130 *pszValue = szBufHeap;
140 SetLastError(uiResult);
151 if (pszValue == NULL)
153 return ERROR_BAD_ARGUMENTS;
157 WCHAR szBufStack[128];
158 DWORD dwLength = _countof(szBufStack);
159 UINT uiResult = MsiFormatRecord(hInstall, hRecord, szBufStack, &dwLength);
160 if (uiResult == ERROR_SUCCESS)
163 *pszValue = (LPWSTR)malloc(++dwLength *
sizeof(WCHAR));
164 if (*pszValue == NULL)
166 msg(
M_FATAL,
"%s: malloc(%u) failed", __FUNCTION__, dwLength *
sizeof(WCHAR));
167 return ERROR_OUTOFMEMORY;
170 memcpy(*pszValue, szBufStack, dwLength *
sizeof(WCHAR));
171 return ERROR_SUCCESS;
173 else if (uiResult == ERROR_MORE_DATA)
176 LPWSTR szBufHeap = (LPWSTR)malloc(++dwLength *
sizeof(WCHAR));
177 if (szBufHeap == NULL)
179 msg(
M_FATAL,
"%s: malloc(%u) failed", __FUNCTION__, dwLength *
sizeof(WCHAR));
180 return ERROR_OUTOFMEMORY;
183 uiResult = MsiFormatRecord(hInstall, hRecord, szBufHeap, &dwLength);
184 if (uiResult == ERROR_SUCCESS)
186 *pszValue = szBufHeap;
196 SetLastError(uiResult);
206 _Out_ LPWSTR *pszValue)
208 if (pszValue == NULL)
210 return ERROR_BAD_ARGUMENTS;
214 LPWSTR szValue = NULL;
216 if (uiResult != ERROR_SUCCESS)
224 return ERROR_SUCCESS;
228 MSIHANDLE hRecordEx = MsiCreateRecord(1);
231 uiResult = ERROR_INVALID_HANDLE;
233 goto cleanup_szValue;
237 uiResult = MsiRecordSetString(hRecordEx, 0, szValue);
238 if (uiResult != ERROR_SUCCESS)
240 SetLastError(uiResult);
243 goto cleanup_hRecordEx;
250 MsiCloseHandle(hRecordEx);
UINT msi_format_field(_In_ MSIHANDLE hInstall, _In_ MSIHANDLE hRecord, _In_ unsigned int iField, _Out_ LPWSTR *pszValue)
Formats MSI record field.
UINT msi_get_record_string(_In_ MSIHANDLE hRecord, _In_ unsigned int iField, _Out_ LPWSTR *pszValue)
Gets MSI record string value.