26 #include "../tapctl/error.h"
33 #pragma comment(lib, "msi.lib")
39 _In_ MSIHANDLE hInstall,
41 _Out_ LPTSTR *pszValue)
45 return ERROR_BAD_ARGUMENTS;
49 TCHAR szBufStack[128];
50 DWORD dwLength = _countof(szBufStack);
51 UINT uiResult = MsiGetProperty(hInstall, szName, szBufStack, &dwLength);
52 if (uiResult == ERROR_SUCCESS)
55 *pszValue = (LPTSTR)malloc(++dwLength *
sizeof(TCHAR));
56 if (*pszValue == NULL)
58 msg(
M_FATAL,
"%s: malloc(%u) failed", dwLength *
sizeof(TCHAR));
59 return ERROR_OUTOFMEMORY;
62 memcpy(*pszValue, szBufStack, dwLength *
sizeof(TCHAR));
65 else if (uiResult == ERROR_MORE_DATA)
68 LPTSTR szBufHeap = (LPTSTR)malloc(++dwLength *
sizeof(TCHAR));
69 if (szBufHeap == NULL)
71 msg(
M_FATAL,
"%s: malloc(%u) failed", __FUNCTION__, dwLength *
sizeof(TCHAR));
72 return ERROR_OUTOFMEMORY;
75 uiResult = MsiGetProperty(hInstall, szName, szBufHeap, &dwLength);
76 if (uiResult == ERROR_SUCCESS)
78 *pszValue = szBufHeap;
88 SetLastError(uiResult);
97 _In_ MSIHANDLE hRecord,
98 _In_ unsigned int iField,
99 _Out_ LPTSTR *pszValue)
101 if (pszValue == NULL)
103 return ERROR_BAD_ARGUMENTS;
107 TCHAR szBufStack[128];
108 DWORD dwLength = _countof(szBufStack);
109 UINT uiResult = MsiRecordGetString(hRecord, iField, szBufStack, &dwLength);
110 if (uiResult == ERROR_SUCCESS)
113 *pszValue = (LPTSTR)malloc(++dwLength *
sizeof(TCHAR));
114 if (*pszValue == NULL)
116 msg(
M_FATAL,
"%s: malloc(%u) failed", __FUNCTION__, dwLength *
sizeof(TCHAR));
117 return ERROR_OUTOFMEMORY;
120 memcpy(*pszValue, szBufStack, dwLength *
sizeof(TCHAR));
121 return ERROR_SUCCESS;
123 else if (uiResult == ERROR_MORE_DATA)
126 LPTSTR szBufHeap = (LPTSTR)malloc(++dwLength *
sizeof(TCHAR));
127 if (szBufHeap == NULL)
129 msg(
M_FATAL,
"%s: malloc(%u) failed", __FUNCTION__, dwLength *
sizeof(TCHAR));
130 return ERROR_OUTOFMEMORY;
133 uiResult = MsiRecordGetString(hRecord, iField, szBufHeap, &dwLength);
134 if (uiResult == ERROR_SUCCESS)
136 *pszValue = szBufHeap;
146 SetLastError(uiResult);
155 _In_ MSIHANDLE hInstall,
156 _In_ MSIHANDLE hRecord,
157 _Out_ LPTSTR *pszValue)
159 if (pszValue == NULL)
161 return ERROR_BAD_ARGUMENTS;
165 TCHAR szBufStack[128];
166 DWORD dwLength = _countof(szBufStack);
167 UINT uiResult = MsiFormatRecord(hInstall, hRecord, szBufStack, &dwLength);
168 if (uiResult == ERROR_SUCCESS)
171 *pszValue = (LPTSTR)malloc(++dwLength *
sizeof(TCHAR));
172 if (*pszValue == NULL)
174 msg(
M_FATAL,
"%s: malloc(%u) failed", __FUNCTION__, dwLength *
sizeof(TCHAR));
175 return ERROR_OUTOFMEMORY;
178 memcpy(*pszValue, szBufStack, dwLength *
sizeof(TCHAR));
179 return ERROR_SUCCESS;
181 else if (uiResult == ERROR_MORE_DATA)
184 LPTSTR szBufHeap = (LPTSTR)malloc(++dwLength *
sizeof(TCHAR));
185 if (szBufHeap == NULL)
187 msg(
M_FATAL,
"%s: malloc(%u) failed", __FUNCTION__, dwLength *
sizeof(TCHAR));
188 return ERROR_OUTOFMEMORY;
191 uiResult = MsiFormatRecord(hInstall, hRecord, szBufHeap, &dwLength);
192 if (uiResult == ERROR_SUCCESS)
194 *pszValue = szBufHeap;
204 SetLastError(uiResult);
213 _In_ MSIHANDLE hInstall,
214 _In_ MSIHANDLE hRecord,
215 _In_ unsigned int iField,
216 _Out_ LPTSTR *pszValue)
218 if (pszValue == NULL)
220 return ERROR_BAD_ARGUMENTS;
224 LPTSTR szValue = NULL;
226 if (uiResult != ERROR_SUCCESS)
234 return ERROR_SUCCESS;
238 MSIHANDLE hRecordEx = MsiCreateRecord(1);
241 uiResult = ERROR_INVALID_HANDLE;
243 goto cleanup_szValue;
247 uiResult = MsiRecordSetString(hRecordEx, 0, szValue);
248 if (uiResult != ERROR_SUCCESS)
250 SetLastError(uiResult);
252 goto cleanup_hRecordEx;
259 MsiCloseHandle(hRecordEx);