commit f6ad8bd613cb548766d50471d8e31431e28c0384 Author: Simon Rozman Date: Fri Mar 20 13:18:36 2015 +0000 libatl added. The work on al_import.exe continues. Aesthetic modifications diff --git a/atl.vcxproj b/atl.vcxproj new file mode 100644 index 0000000..90dd211 --- /dev/null +++ b/atl.vcxproj @@ -0,0 +1,114 @@ + + + + + Debug + Win32 + + + Debug + x64 + + + Release + Win32 + + + Release + x64 + + + + libatl + {5A4EADF2-3237-457A-9DA8-BB9942A91019} + libatl + Win32Proj + + + + StaticLibrary + Unicode + + + StaticLibrary + Unicode + + + StaticLibrary + Unicode + + + StaticLibrary + Unicode + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + <_ProjectFileVersion>10.0.40219.1 + + + + + + + X64 + + + + + + + + + X64 + + + + + + Create + Create + Create + Create + + + + + + + + + + + + \ No newline at end of file diff --git a/atl.vcxproj.filters b/atl.vcxproj.filters new file mode 100644 index 0000000..83d005e --- /dev/null +++ b/atl.vcxproj.filters @@ -0,0 +1,32 @@ + + + + + {4FC737F1-C7A5-4376-A066-2A32D752A2FF} + cpp;c;cc;cxx;def;odl;idl;hpj;bat;asm;asmx + + + {93995380-89BD-4b04-88EB-625FBE52EBFB} + h;hpp;hxx;hm;inl;inc;xsd + + + + + Source Files + + + + + Header Files + + + Header Files + + + Header Files + + + Header Files + + + \ No newline at end of file diff --git a/atlcrypt.h b/atlcrypt.h new file mode 100644 index 0000000..d6fba7e --- /dev/null +++ b/atlcrypt.h @@ -0,0 +1,51 @@ +/* + Copyright 1991-2015 Amebis + + This file is part of libatl. + + Setup is free software: you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation, either version 3 of the License, or + (at your option) any later version. + + Setup is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License + along with Setup. If not, see . +*/ + +#pragma once + +#include +#include + + +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; +} diff --git a/atlmsi.h b/atlmsi.h new file mode 100644 index 0000000..875d44e --- /dev/null +++ b/atlmsi.h @@ -0,0 +1,241 @@ +/* + Copyright 1991-2015 Amebis + + This file is part of libatl. + + Setup is free software: you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation, either version 3 of the License, or + (at your option) any later version. + + Setup is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License + along with Setup. If not, see . +*/ + +#pragma once + +#include +#include +#include + + +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 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 MsiRecordReadStream(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 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; + } +} diff --git a/atlwin.h b/atlwin.h new file mode 100644 index 0000000..2c6d877 --- /dev/null +++ b/atlwin.h @@ -0,0 +1,65 @@ +/* + Copyright 1991-2015 Amebis + + This file is part of libatl. + + Setup is free software: you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation, either version 3 of the License, or + (at your option) any later version. + + Setup is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License + along with Setup. If not, see . +*/ + +#pragma once + +#include +#include + + +inline int GetWindowTextA(__in HWND hWnd, __out ATL::CAtlStringA &sValue) +{ + int iResult; + + // Query the final string length first. + iResult = ::GetWindowTextLengthA(hWnd); + if (iResult > 0) { + // Prepare the buffer to format the string data into and read it. + LPSTR szBuffer = sValue.GetBuffer(iResult++); + if (!szBuffer) return 0; + iResult = ::GetWindowTextA(hWnd, szBuffer, iResult); + sValue.ReleaseBuffer(iResult); + return iResult; + } else { + // The result is empty. + sValue.Empty(); + return 0; + } +} + + +inline int GetWindowTextW(__in HWND hWnd, __out ATL::CAtlStringW &sValue) +{ + int iResult; + + // Query the final string length first. + iResult = ::GetWindowTextLengthW(hWnd); + if (iResult > 0) { + // Prepare the buffer to format the string data into and read it. + LPWSTR szBuffer = sValue.GetBuffer(iResult++); + if (!szBuffer) return 0; + iResult = ::GetWindowTextW(hWnd, szBuffer, iResult); + sValue.ReleaseBuffer(iResult); + return iResult; + } else { + // The result is empty. + sValue.Empty(); + return 0; + } +} diff --git a/stdafx.cpp b/stdafx.cpp new file mode 100644 index 0000000..81111ac --- /dev/null +++ b/stdafx.cpp @@ -0,0 +1,20 @@ +/* + Copyright 1991-2015 Amebis + + This file is part of libatl. + + Setup is free software: you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation, either version 3 of the License, or + (at your option) any later version. + + Setup is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License + along with Setup. If not, see . +*/ + +#include "stdafx.h" diff --git a/stdafx.h b/stdafx.h new file mode 100644 index 0000000..f2ab7f7 --- /dev/null +++ b/stdafx.h @@ -0,0 +1,25 @@ +/* + Copyright 1991-2015 Amebis + + This file is part of libatl. + + Setup is free software: you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation, either version 3 of the License, or + (at your option) any later version. + + Setup is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License + along with Setup. If not, see . +*/ + +#pragma once + +#include "atlwin.h" + +#include "atlcrypt.h" +#include "atlmsi.h"