From 3452ef7cb9113e075e62782780e4399c5ba7f0f2 Mon Sep 17 00:00:00 2001 From: Simon Rozman Date: Fri, 20 Mar 2015 13:19:01 +0000 Subject: [PATCH] libatl added. Aesthetic modifications --- MSICALib.h | 246 +---------------------------------------------------- stdafx.h | 6 +- 2 files changed, 5 insertions(+), 247 deletions(-) diff --git a/MSICALib.h b/MSICALib.h index be04414..0bc1c62 100644 --- a/MSICALib.h +++ b/MSICALib.h @@ -672,6 +672,7 @@ UINT ExecuteSequence(MSIHANDLE hInstall); // Local includes //////////////////////////////////////////////////////////////////// +#include "../../../lib/atl/atlmsi.h" #include #include #include @@ -708,173 +709,6 @@ inline VOID GuidToString(const GUID &guid, ATL::CAtlStringW &str) } // namespace MSICA -inline UINT MsiGetPropertyA(MSIHANDLE hInstall, LPCSTR szName, ATL::CAtlStringA &sValue) -{ - DWORD dwSize = 0; - UINT uiResult; - - // Query the actual string length first. - uiResult = ::MsiGetPropertyA(hInstall, szName, "", &dwSize); - if (uiResult == ERROR_MORE_DATA) { - // Prepare the buffer to read the string data into and read it. - LPSTR szBuffer = sValue.GetBuffer(dwSize++); - if (!szBuffer) return ERROR_OUTOFMEMORY; - uiResult = ::MsiGetPropertyA(hInstall, szName, szBuffer, &dwSize); - sValue.ReleaseBuffer(uiResult == NO_ERROR ? dwSize : 0); - return uiResult; - } else if (uiResult == NO_ERROR) { - // The string in database is empty. - sValue.Empty(); - return NO_ERROR; - } else { - // Return error code. - return uiResult; - } -} - - -inline UINT MsiGetPropertyW(MSIHANDLE hInstall, LPCWSTR szName, ATL::CAtlStringW &sValue) -{ - DWORD dwSize = 0; - UINT uiResult; - - // Query the actual string length first. - uiResult = ::MsiGetPropertyW(hInstall, szName, L"", &dwSize); - if (uiResult == ERROR_MORE_DATA) { - // Prepare the buffer to read the string data into and read it. - LPWSTR szBuffer = sValue.GetBuffer(dwSize++); - if (!szBuffer) return ERROR_OUTOFMEMORY; - uiResult = ::MsiGetPropertyW(hInstall, szName, szBuffer, &dwSize); - sValue.ReleaseBuffer(uiResult == NO_ERROR ? dwSize : 0); - return uiResult; - } else if (uiResult == NO_ERROR) { - // The string in database is empty. - sValue.Empty(); - return NO_ERROR; - } else { - // Return error code. - return uiResult; - } -} - - -inline UINT MsiRecordGetStringA(MSIHANDLE hRecord, unsigned int iField, ATL::CAtlStringA &sValue) -{ - DWORD dwSize = 0; - UINT uiResult; - - // Query the actual string length first. - uiResult = ::MsiRecordGetStringA(hRecord, iField, "", &dwSize); - if (uiResult == ERROR_MORE_DATA) { - // Prepare the buffer to read the string data into and read it. - LPSTR szBuffer = sValue.GetBuffer(dwSize++); - if (!szBuffer) return ERROR_OUTOFMEMORY; - uiResult = ::MsiRecordGetStringA(hRecord, iField, szBuffer, &dwSize); - sValue.ReleaseBuffer(uiResult == NO_ERROR ? dwSize : 0); - return uiResult; - } else if (uiResult == NO_ERROR) { - // The string in database is empty. - sValue.Empty(); - return NO_ERROR; - } else { - // Return error code. - return uiResult; - } -} - - -inline UINT MsiRecordGetStringW(MSIHANDLE hRecord, unsigned int iField, ATL::CAtlStringW &sValue) -{ - DWORD dwSize = 0; - UINT uiResult; - - // Query the actual string length first. - uiResult = ::MsiRecordGetStringW(hRecord, iField, L"", &dwSize); - if (uiResult == ERROR_MORE_DATA) { - // Prepare the buffer to read the string data into and read it. - LPWSTR szBuffer = sValue.GetBuffer(dwSize++); - if (!szBuffer) return ERROR_OUTOFMEMORY; - uiResult = ::MsiRecordGetStringW(hRecord, iField, szBuffer, &dwSize); - sValue.ReleaseBuffer(uiResult == NO_ERROR ? dwSize : 0); - return uiResult; - } else if (uiResult == NO_ERROR) { - // The string in database is empty. - sValue.Empty(); - return NO_ERROR; - } else { - // Return error code. - return uiResult; - } -} - - -inline UINT MsiRecordGetStream(MSIHANDLE hRecord, unsigned int iField, ATL::CAtlArray &binData) -{ - DWORD dwSize = 0; - UINT uiResult; - - // Query the actual data length first. - uiResult = ::MsiRecordReadStream(hRecord, iField, NULL, &dwSize); - if (uiResult == NO_ERROR) { - if (!binData.SetCount(dwSize)) return ERROR_OUTOFMEMORY; - return ::MsiRecordReadStream(hRecord, iField, (char*)binData.GetData(), &dwSize); - } else { - // Return error code. - return uiResult; - } -} - - -inline UINT MsiFormatRecordA(MSIHANDLE hInstall, MSIHANDLE hRecord, ATL::CAtlStringA &sValue) -{ - DWORD dwSize = 0; - UINT uiResult; - - // Query the final string length first. - uiResult = ::MsiFormatRecordA(hInstall, hRecord, "", &dwSize); - if (uiResult == ERROR_MORE_DATA) { - // Prepare the buffer to format the string data into and read it. - LPSTR szBuffer = sValue.GetBuffer(dwSize++); - if (!szBuffer) return ERROR_OUTOFMEMORY; - uiResult = ::MsiFormatRecordA(hInstall, hRecord, szBuffer, &dwSize); - sValue.ReleaseBuffer(uiResult == NO_ERROR ? dwSize : 0); - return uiResult; - } else if (uiResult == NO_ERROR) { - // The result is empty. - sValue.Empty(); - return NO_ERROR; - } else { - // Return error code. - return uiResult; - } -} - - -inline UINT MsiFormatRecordW(MSIHANDLE hInstall, MSIHANDLE hRecord, ATL::CAtlStringW &sValue) -{ - DWORD dwSize = 0; - UINT uiResult; - - // Query the final string length first. - uiResult = ::MsiFormatRecordW(hInstall, hRecord, L"", &dwSize); - if (uiResult == ERROR_MORE_DATA) { - // Prepare the buffer to format the string data into and read it. - LPWSTR szBuffer = sValue.GetBuffer(dwSize++); - if (!szBuffer) return ERROR_OUTOFMEMORY; - uiResult = ::MsiFormatRecordW(hInstall, hRecord, szBuffer, &dwSize); - sValue.ReleaseBuffer(uiResult == NO_ERROR ? dwSize : 0); - return uiResult; - } else if (uiResult == NO_ERROR) { - // The result is empty. - sValue.Empty(); - return NO_ERROR; - } else { - // Return error code. - return uiResult; - } -} - - inline UINT MsiRecordFormatStringA(MSIHANDLE hInstall, MSIHANDLE hRecord, unsigned int iField, ATL::CAtlStringA &sValue) { UINT uiResult; @@ -931,84 +765,6 @@ inline UINT MsiRecordFormatStringW(MSIHANDLE hInstall, MSIHANDLE hRecord, unsign #endif // !UNICODE -inline UINT MsiGetTargetPathA(MSIHANDLE hInstall, LPCSTR szFolder, ATL::CAtlStringA &sValue) -{ - DWORD dwSize = 0; - UINT uiResult; - - // Query the final string length first. - uiResult = ::MsiGetTargetPathA(hInstall, szFolder, "", &dwSize); - if (uiResult == ERROR_MORE_DATA) { - // Prepare the buffer to format the string data into and read it. - LPSTR szBuffer = sValue.GetBuffer(dwSize++); - if (!szBuffer) return ERROR_OUTOFMEMORY; - uiResult = ::MsiGetTargetPathA(hInstall, szFolder, szBuffer, &dwSize); - sValue.ReleaseBuffer(uiResult == NO_ERROR ? dwSize : 0); - return uiResult; - } else if (uiResult == NO_ERROR) { - // The result is empty. - sValue.Empty(); - return NO_ERROR; - } else { - // Return error code. - return uiResult; - } -} - - -inline UINT MsiGetTargetPathW(MSIHANDLE hInstall, LPCWSTR szFolder, ATL::CAtlStringW &sValue) -{ - DWORD dwSize = 0; - UINT uiResult; - - // Query the final string length first. - uiResult = ::MsiGetTargetPathW(hInstall, szFolder, L"", &dwSize); - if (uiResult == ERROR_MORE_DATA) { - // Prepare the buffer to format the string data into and read it. - LPWSTR szBuffer = sValue.GetBuffer(dwSize++); - if (!szBuffer) return ERROR_OUTOFMEMORY; - uiResult = ::MsiGetTargetPathW(hInstall, szFolder, szBuffer, &dwSize); - sValue.ReleaseBuffer(uiResult == NO_ERROR ? dwSize : 0); - return uiResult; - } else if (uiResult == NO_ERROR) { - // The result is empty. - sValue.Empty(); - return NO_ERROR; - } else { - // Return error code. - return uiResult; - } -} - - -inline DWORD CertGetNameStringA(PCCERT_CONTEXT pCertContext, DWORD dwType, DWORD dwFlags, void *pvTypePara, ATL::CAtlStringA &sNameString) -{ - // Query the final string length first. - DWORD dwSize = ::CertGetNameStringA(pCertContext, dwType, dwFlags, pvTypePara, NULL, 0); - - // Prepare the buffer to format the string data into and read it. - LPSTR szBuffer = sNameString.GetBuffer(dwSize); - if (!szBuffer) return ERROR_OUTOFMEMORY; - dwSize = ::CertGetNameStringA(pCertContext, dwType, dwFlags, pvTypePara, szBuffer, dwSize); - sNameString.ReleaseBuffer(dwSize); - return dwSize; -} - - -inline DWORD CertGetNameStringW(PCCERT_CONTEXT pCertContext, DWORD dwType, DWORD dwFlags, void *pvTypePara, ATL::CAtlStringW &sNameString) -{ - // Query the final string length first. - DWORD dwSize = ::CertGetNameStringW(pCertContext, dwType, dwFlags, pvTypePara, NULL, 0); - - // Prepare the buffer to format the string data into and read it. - LPWSTR szBuffer = sNameString.GetBuffer(dwSize); - if (!szBuffer) return ERROR_OUTOFMEMORY; - dwSize = ::CertGetNameStringW(pCertContext, dwType, dwFlags, pvTypePara, szBuffer, dwSize); - sNameString.ReleaseBuffer(dwSize); - return dwSize; -} - - namespace MSICA { //////////////////////////////////////////////////////////////////////////// diff --git a/stdafx.h b/stdafx.h index 8207558..9b99433 100644 --- a/stdafx.h +++ b/stdafx.h @@ -19,6 +19,10 @@ #pragma once +#include "MSICALib.h" + +#include "../../../lib/atl/atlcrypt.h" + #include #include #include @@ -28,5 +32,3 @@ #include #include #include - -#include "MSICALib.h"