Author: ashaposhnikov
Date: Tue Jul 11 22:08:48 2017
New Revision: 75319
URL:
http://svn.reactos.org/svn/reactos?rev=75319&view=rev
Log:
[SDK] Added atlex for future use
- atlex is ATL wrappers for WINAPI functions
- It is header-only library licensed under GPLv3
- For details see
https://github.com/Amebis/atlex
Added:
branches/GSoC_2017/rapps/reactos/sdk/include/reactos/atlex/
branches/GSoC_2017/rapps/reactos/sdk/include/reactos/atlex/atlcrypt.h (with props)
branches/GSoC_2017/rapps/reactos/sdk/include/reactos/atlex/atleap.h (with props)
branches/GSoC_2017/rapps/reactos/sdk/include/reactos/atlex/atlex.h (with props)
branches/GSoC_2017/rapps/reactos/sdk/include/reactos/atlex/atlmsi.h (with props)
branches/GSoC_2017/rapps/reactos/sdk/include/reactos/atlex/atlsec.h (with props)
branches/GSoC_2017/rapps/reactos/sdk/include/reactos/atlex/atlshlwapi.h (with
props)
branches/GSoC_2017/rapps/reactos/sdk/include/reactos/atlex/atlwin.h (with props)
branches/GSoC_2017/rapps/reactos/sdk/include/reactos/atlex/atlwlan.h (with props)
Added: branches/GSoC_2017/rapps/reactos/sdk/include/reactos/atlex/atlcrypt.h
URL:
http://svn.reactos.org/svn/reactos/branches/GSoC_2017/rapps/reactos/sdk/inc…
==============================================================================
--- branches/GSoC_2017/rapps/reactos/sdk/include/reactos/atlex/atlcrypt.h (added)
+++ branches/GSoC_2017/rapps/reactos/sdk/include/reactos/atlex/atlcrypt.h [iso-8859-1] Tue
Jul 11 22:08:48 2017
@@ -0,0 +1,498 @@
+/*
+ Copyright 1991-2017 Amebis
+
+ This file is part of atlex.
+
+ 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 <http://www.gnu.org/licenses/>.
+*/
+
+#pragma once
+
+#include "atlex.h"
+#include <atlcoll.h>
+#include <atlstr.h>
+#include <WinCrypt.h>
+
+///
+/// \defgroup ATLCryptoAPI Cryptography API
+/// Integrates ATL classes with Microsoft Cryptography API
+///
+/// @{
+
+///
+/// Obtains the subject or issuer name from a certificate
[
CERT_CONTEXT](https://msdn.microsoft.com/en-us/library/windows/desktop/aa37…
structure and stores it in a ATL::CAtlStringA string.
+///
+/// \sa [CertGetNameString
function](https://msdn.microsoft.com/en-us/library/windows/desktop/aa376086…
+///
+inline DWORD CertGetNameStringA(_In_ PCCERT_CONTEXT pCertContext, _In_ DWORD dwType, _In_
DWORD dwFlags, _In_ void *pvTypePara, _Out_ ATL::CAtlStringA &sNameString)
+{
+ // Query the final string length first.
+ DWORD dwSize = ::CertGetNameStringA(pCertContext, dwType, dwFlags, pvTypePara, NULL,
0);
+
+ // Allocate buffer on heap 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;
+}
+
+
+///
+/// Obtains the subject or issuer name from a certificate
[
CERT_CONTEXT](https://msdn.microsoft.com/en-us/library/windows/desktop/aa37…
structure and stores it in a ATL::CAtlStringW string.
+///
+/// \sa [CertGetNameString
function](https://msdn.microsoft.com/en-us/library/windows/desktop/aa376086…
+///
+inline DWORD CertGetNameStringW(_In_ PCCERT_CONTEXT pCertContext, _In_ DWORD dwType, _In_
DWORD dwFlags, _In_ void *pvTypePara, _Out_ ATL::CAtlStringW &sNameString)
+{
+ // Query the final string length first.
+ DWORD dwSize = ::CertGetNameStringW(pCertContext, dwType, dwFlags, pvTypePara, NULL,
0);
+
+ // Allocate buffer on heap 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;
+}
+
+
+///
+/// Retrieves data that governs the operations of a hash object. The actual hash value
can be retrieved by using this function.
+///
+/// \sa [CryptGetHashParam
function](https://msdn.microsoft.com/en-us/library/windows/desktop/aa379947…
+///
+inline BOOL CryptGetHashParam(_In_ HCRYPTHASH hHash, _In_ DWORD dwParam, _Out_
ATL::CAtlArray<BYTE> &aData, _In_ DWORD dwFlags)
+{
+ DWORD dwHashSize;
+
+ if (CryptGetHashParam(hHash, dwParam, NULL, &dwHashSize, dwFlags)) {
+ if (aData.SetCount(dwHashSize)) {
+ if (CryptGetHashParam(hHash, dwParam, aData.GetData(), &dwHashSize,
dwFlags)) {
+ return TRUE;
+ } else {
+ aData.SetCount(0);
+ return FALSE;
+ }
+ } else {
+ SetLastError(ERROR_OUTOFMEMORY);
+ return FALSE;
+ }
+ } else
+ return FALSE;
+}
+
+
+///
+/// Exports a cryptographic key or a key pair from a cryptographic service provider (CSP)
in a secure manner.
+///
+/// \sa [CryptExportKey
function](https://msdn.microsoft.com/en-us/library/windows/desktop/aa379931…
+///
+inline BOOL CryptExportKey(_In_ HCRYPTKEY hKey, _In_ HCRYPTKEY hExpKey, _In_ DWORD
dwBlobType, _In_ DWORD dwFlags, _Out_ ATL::CAtlArray<BYTE> &aData)
+{
+ DWORD dwKeyBLOBSize;
+
+ if (CryptExportKey(hKey, hExpKey, dwBlobType, dwFlags, NULL, &dwKeyBLOBSize)) {
+ if (aData.SetCount(dwKeyBLOBSize)) {
+ if (CryptExportKey(hKey, hExpKey, dwBlobType, dwFlags, aData.GetData(),
&dwKeyBLOBSize)) {
+ return TRUE;
+ } else {
+ aData.SetCount(0);
+ return FALSE;
+ }
+ } else {
+ SetLastError(ERROR_OUTOFMEMORY);
+ return FALSE;
+ }
+ } else
+ return FALSE;
+}
+
+/// @}
+
+
+namespace ATL
+{
+ namespace Crypt
+ {
+ /// \addtogroup ATLCryptoAPI
+ /// @{
+
+ ///
+ /// PCCERT_CONTEXT wrapper class
+ ///
+ class CCertContext : public ATL::CObjectWithHandleDuplT<PCCERT_CONTEXT>
+ {
+ public:
+ ///
+ /// Destroys the certificate context.
+ ///
+ /// \sa [CertFreeCertificateContext
function](https://msdn.microsoft.com/en-us/library/windows/desktop/aa376075…
+ ///
+ virtual ~CCertContext()
+ {
+ if (m_h)
+ CertFreeCertificateContext(m_h);
+ }
+
+ ///
+ /// Creates the certificate context.
+ ///
+ /// \return
+ /// - TRUE when creation succeeds;
+ /// - FALSE when creation fails. For extended error information, call
`GetLastError()`.
+ /// \sa [CertCreateCertificateContext
function](https://msdn.microsoft.com/en-us/library/windows/desktop/aa376033…
+ ///
+ inline BOOL Create(_In_ DWORD dwCertEncodingType, _In_ const BYTE
*pbCertEncoded, _In_ DWORD cbCertEncoded)
+ {
+ HANDLE h = CertCreateCertificateContext(dwCertEncodingType,
pbCertEncoded, cbCertEncoded);
+ if (h) {
+ Attach(h);
+ return TRUE;
+ } else
+ return FALSE;
+ }
+
+ protected:
+ ///
+ /// Destroys the certificate context.
+ ///
+ /// \sa [CertFreeCertificateContext
function](https://msdn.microsoft.com/en-us/library/windows/desktop/aa376075…
+ ///
+ virtual void InternalFree()
+ {
+ CertFreeCertificateContext(m_h);
+ }
+
+ ///
+ /// Duplicates the certificate context.
+ ///
+ /// \param[in] h Object handle of existing certificate context
+ /// \return Duplicated certificate context handle
+ /// \sa [CertDuplicateCertificateContext
function](https://msdn.microsoft.com/en-us/library/windows/desktop/aa376045…
+ ///
+ virtual HANDLE InternalDuplicate(_In_ HANDLE h) const
+ {
+ return CertDuplicateCertificateContext(h);
+ }
+ };
+
+
+ ///
+ /// PCCERT_CHAIN_CONTEXT wrapper class
+ ///
+ class CCertChainContext : public
ATL::CObjectWithHandleDuplT<PCCERT_CHAIN_CONTEXT>
+ {
+ public:
+ ///
+ /// Destroys the certificate chain context.
+ ///
+ /// \sa [CertFreeCertificateChain
function](https://msdn.microsoft.com/en-us/library/windows/desktop/aa376073…
+ ///
+ virtual ~CCertChainContext()
+ {
+ if (m_h)
+ CertFreeCertificateChain(m_h);
+ }
+
+ ///
+ /// Creates the certificate chain context.
+ ///
+ /// \return
+ /// - TRUE when creation succeeds;
+ /// - FALSE when creation fails. For extended error information, call
`GetLastError()`.
+ /// \sa [CertGetCertificateChain
function](https://msdn.microsoft.com/en-us/library/windows/desktop/aa376078…
+ ///
+ inline BOOL Create(_In_opt_ HCERTCHAINENGINE hChainEngine, _In_
PCCERT_CONTEXT pCertContext, _In_opt_ LPFILETIME pTime, _In_opt_ HCERTSTORE
hAdditionalStore, _In_ PCERT_CHAIN_PARA pChainPara, _In_ DWORD dwFlags, __reserved LPVOID
pvReserved)
+ {
+ HANDLE h;
+ if (CertGetCertificateChain(hChainEngine, pCertContext, pTime,
hAdditionalStore, pChainPara, dwFlags, pvReserved, &h)) {
+ Attach(h);
+ return TRUE;
+ } else
+ return FALSE;
+ }
+
+ protected:
+ ///
+ /// Destroys the certificate chain context.
+ ///
+ /// \sa [CertFreeCertificateChain
function](https://msdn.microsoft.com/en-us/library/windows/desktop/aa376073…
+ ///
+ virtual void InternalFree()
+ {
+ CertFreeCertificateChain(m_h);
+ }
+
+ ///
+ /// Duplicates the certificate chain context.
+ ///
+ /// \param[in] h Object handle of existing certificate chain context
+ /// \return Duplicated certificate chain context handle
+ /// \sa [CertDuplicateCertificateContext
function](https://msdn.microsoft.com/en-us/library/windows/desktop/aa376045…
+ ///
+ virtual HANDLE InternalDuplicate(_In_ HANDLE h) const
+ {
+ return CertDuplicateCertificateChain(h);
+ }
+ };
+
+
+ ///
+ /// HCERTSTORE wrapper class
+ ///
+ class CCertStore : public ATL::CObjectWithHandleT<HCERTSTORE>
+ {
+ public:
+ ///
+ /// Closes the certificate store.
+ ///
+ /// \sa [CertCloseStore
function](https://msdn.microsoft.com/en-us/library/windows/desktop/aa376026…
+ ///
+ virtual ~CCertStore()
+ {
+ if (m_h)
+ CertCloseStore(m_h, 0);
+ }
+
+ ///
+ /// Opens the certificate store.
+ ///
+ /// \return
+ /// - TRUE when creation succeeds;
+ /// - FALSE when creation fails. For extended error information, call
`GetLastError()`.
+ /// \sa [CertOpenStore
function](https://msdn.microsoft.com/en-us/library/windows/desktop/aa376559…
+ ///
+ inline BOOL Create(_In_ LPCSTR lpszStoreProvider, _In_ DWORD dwEncodingType,
_In_opt_ HCRYPTPROV_LEGACY hCryptProv, _In_ DWORD dwFlags, _In_opt_ const void *pvPara)
+ {
+ HANDLE h = CertOpenStore(lpszStoreProvider, dwEncodingType, hCryptProv,
dwFlags, pvPara);
+ if (h) {
+ Attach(h);
+ return TRUE;
+ } else
+ return FALSE;
+ }
+
+ protected:
+ ///
+ /// Closes the certificate store.
+ ///
+ /// \sa [CertCloseStore
function](https://msdn.microsoft.com/en-us/library/windows/desktop/aa376026…
+ ///
+ virtual void InternalFree()
+ {
+ CertCloseStore(m_h, 0);
+ }
+ };
+
+
+ ///
+ /// HCRYPTPROV wrapper class
+ ///
+ class CContext : public ATL::CObjectWithHandleT<HCRYPTPROV>
+ {
+ public:
+ ///
+ /// Releases the cryptographi context.
+ ///
+ /// \sa [CryptReleaseContext
function](https://msdn.microsoft.com/en-us/library/windows/desktop/aa380268…
+ ///
+ virtual ~CContext()
+ {
+ if (m_h)
+ CryptReleaseContext(m_h, 0);
+ }
+
+ ///
+ /// Acquires the cryptographic context.
+ ///
+ /// \return
+ /// - TRUE when creation succeeds;
+ /// - FALSE when creation fails. For extended error information, call
`GetLastError()`.
+ /// \sa [CryptAcquireContext
function](https://msdn.microsoft.com/en-us/library/windows/desktop/aa379886…
+ ///
+ inline BOOL Create(_In_opt_ LPCTSTR szContainer, _In_opt_ LPCTSTR szProvider,
_In_ DWORD dwProvType, _In_ DWORD dwFlags)
+ {
+ HANDLE h;
+ if (CryptAcquireContext(&h, szContainer, szProvider, dwProvType,
dwFlags)) {
+ Attach(h);
+ return TRUE;
+ } else
+ return FALSE;
+ }
+
+ protected:
+ ///
+ /// Releases the cryptographic context.
+ ///
+ /// \sa [CryptReleaseContext
function](https://msdn.microsoft.com/en-us/library/windows/desktop/aa380268…
+ ///
+ virtual void InternalFree()
+ {
+ CryptReleaseContext(m_h, 0);
+ }
+ };
+
+
+ ///
+ /// HCRYPTHASH wrapper class
+ ///
+ class CHash : public ATL::CObjectWithHandleDuplT<HCRYPTHASH>
+ {
+ public:
+ ///
+ /// Destroys the hash context.
+ ///
+ /// \sa [CryptDestroyHash
function](https://msdn.microsoft.com/en-us/library/windows/desktop/aa379917…
+ ///
+ virtual ~CHash()
+ {
+ if (m_h)
+ CryptDestroyHash(m_h);
+ }
+
+ ///
+ /// Creates the hash context.
+ ///
+ /// \return
+ /// - TRUE when creation succeeds;
+ /// - FALSE when creation fails. For extended error information, call
`GetLastError()`.
+ /// \sa [CryptCreateHash
function](https://msdn.microsoft.com/en-us/library/windows/desktop/aa379908…
+ ///
+ inline BOOL Create(_In_ HCRYPTPROV hProv, _In_ ALG_ID Algid, _In_ HCRYPTKEY
hKey, _In_ DWORD dwFlags)
+ {
+ HANDLE h;
+ if (CryptCreateHash(hProv, Algid, hKey, dwFlags, &h)) {
+ Attach(h);
+ return TRUE;
+ } else
+ return FALSE;
+ }
+
+ protected:
+ ///
+ /// Destroys the hash context.
+ ///
+ /// \sa [CryptDestroyHash
function](https://msdn.microsoft.com/en-us/library/windows/desktop/aa379917…
+ ///
+ virtual void InternalFree()
+ {
+ CryptDestroyHash(m_h);
+ }
+
+ ///
+ /// Duplicates the hash context.
+ ///
+ /// \param[in] h Object handle of existing hash context
+ /// \return Duplicated hash context handle
+ /// \sa [CryptDuplicateHash
function](https://msdn.microsoft.com/en-us/library/windows/desktop/aa379919…
+ ///
+ virtual HANDLE InternalDuplicate(_In_ HANDLE h) const
+ {
+ HANDLE hNew = NULL;
+ return CryptDuplicateHash(h, NULL, 0, &hNew) ? hNew : NULL;
+ }
+ };
+
+
+ ///
+ /// HCRYPTKEY wrapper class
+ ///
+ class CKey : public ATL::CObjectWithHandleDuplT<HCRYPTKEY>
+ {
+ public:
+ ///
+ /// Destroys the key.
+ ///
+ /// \sa [CryptDestroyKey
function](https://msdn.microsoft.com/en-us/library/windows/desktop/aa379918…
+ ///
+ virtual ~CKey()
+ {
+ if (m_h)
+ CryptDestroyKey(m_h);
+ }
+
+ ///
+ /// Generates the key.
+ ///
+ /// \sa [CryptGenKey
function](https://msdn.microsoft.com/en-us/library/windows/desktop/aa379941…
+ ///
+ inline BOOL Generate(_In_ HCRYPTPROV hProv, _In_ ALG_ID Algid, _In_ DWORD
dwFlags)
+ {
+ HANDLE h;
+ if (CryptGenKey(hProv, Algid, dwFlags, &h)) {
+ Attach(h);
+ return TRUE;
+ } else
+ return FALSE;
+ }
+
+ ///
+ /// Imports the key.
+ ///
+ /// \sa [CryptImportKey
function](https://msdn.microsoft.com/en-us/library/windows/desktop/aa380207…
+ ///
+ inline BOOL Import(_In_ HCRYPTPROV hProv, __in_bcount(dwDataLen) CONST BYTE
*pbData, _In_ DWORD dwDataLen, _In_ HCRYPTKEY hPubKey, _In_ DWORD dwFlags)
+ {
+ HANDLE h;
+ if (CryptImportKey(hProv, pbData, dwDataLen, hPubKey, dwFlags, &h))
{
+ Attach(h);
+ return TRUE;
+ } else
+ return FALSE;
+ }
+
+ ///
+ /// Imports the public key.
+ ///
+ /// \sa [CryptImportPublicKeyInfo
function](https://msdn.microsoft.com/en-us/library/windows/desktop/aa380209…
+ ///
+ inline BOOL ImportPublic(_In_ HCRYPTPROV hCryptProv, _In_ DWORD
dwCertEncodingType, _In_ PCERT_PUBLIC_KEY_INFO pInfo)
+ {
+ HANDLE h;
+ if (CryptImportPublicKeyInfo(hCryptProv, dwCertEncodingType, pInfo,
&h)) {
+ Attach(h);
+ return TRUE;
+ } else
+ return FALSE;
+ }
+
+ protected:
+ ///
+ /// Destroys the key.
+ ///
+ /// \sa [CryptDestroyKey
function](https://msdn.microsoft.com/en-us/library/windows/desktop/aa379918…
+ ///
+ virtual void InternalFree()
+ {
+ CryptDestroyKey(m_h);
+ }
+
+ ///
+ /// Duplicates the key.
+ ///
+ /// \param[in] h Object handle of existing key
+ /// \return Duplicated key handle
+ /// \sa [CryptDuplicateKey
function](https://msdn.microsoft.com/en-us/library/windows/desktop/aa379920…
+ ///
+ virtual HANDLE InternalDuplicate(_In_ HANDLE h) const
+ {
+ HANDLE hNew = NULL;
+ return CryptDuplicateKey(h, NULL, 0, &hNew) ? hNew : NULL;
+ }
+ };
+
+ /// @}
+ }
+}
Propchange: branches/GSoC_2017/rapps/reactos/sdk/include/reactos/atlex/atlcrypt.h
------------------------------------------------------------------------------
svn:eol-style = native
Added: branches/GSoC_2017/rapps/reactos/sdk/include/reactos/atlex/atleap.h
URL:
http://svn.reactos.org/svn/reactos/branches/GSoC_2017/rapps/reactos/sdk/inc…
==============================================================================
--- branches/GSoC_2017/rapps/reactos/sdk/include/reactos/atlex/atleap.h (added)
+++ branches/GSoC_2017/rapps/reactos/sdk/include/reactos/atlex/atleap.h [iso-8859-1] Tue
Jul 11 22:08:48 2017
@@ -0,0 +1,63 @@
+/*
+ Copyright 1991-2017 Amebis
+
+ This file is part of atlex.
+
+ 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 <http://www.gnu.org/licenses/>.
+*/
+
+#pragma once
+
+#include <eaptypes.h>
+
+
+namespace ATL
+{
+ namespace EAP
+ {
+ ///
+ /// \defgroup ATLEAPAPI Extensible Authentication Protocol API
+ /// Integrates ATL classes with Microsoft EAP API
+ ///
+ /// @{
+
+ ///
+ /// EAP_ATTRIBUTE wrapper class
+ ///
+ class CEAPAttribute : public EAP_ATTRIBUTE
+ {
+ public:
+ ///
+ /// Initializes a new EAP attribute set to eatReserved.
+ ///
+ CEAPAttribute()
+ {
+ eaType = eatReserved;
+ dwLength = 0;
+ pValue = NULL;
+ }
+
+ ///
+ /// Destroys the EAP attribute.
+ ///
+ ~CEAPAttribute()
+ {
+ if (pValue)
+ delete pValue;
+ }
+ };
+
+ /// @}
+ }
+}
Propchange: branches/GSoC_2017/rapps/reactos/sdk/include/reactos/atlex/atleap.h
------------------------------------------------------------------------------
svn:eol-style = native
Added: branches/GSoC_2017/rapps/reactos/sdk/include/reactos/atlex/atlex.h
URL:
http://svn.reactos.org/svn/reactos/branches/GSoC_2017/rapps/reactos/sdk/inc…
==============================================================================
--- branches/GSoC_2017/rapps/reactos/sdk/include/reactos/atlex/atlex.h (added)
+++ branches/GSoC_2017/rapps/reactos/sdk/include/reactos/atlex/atlex.h [iso-8859-1] Tue
Jul 11 22:08:48 2017
@@ -0,0 +1,654 @@
+/*
+ Copyright 1991-2017 Amebis
+
+ This file is part of atlex.
+
+ 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 <http://www.gnu.org/licenses/>.
+*/
+
+#pragma once
+
+#include <atlconv.h>
+#include <atldef.h>
+#include <atlstr.h>
+
+#ifndef ATL_STACK_BUFFER_BYTES
+///
+/// Size of the stack buffer in bytes used for initial system function call
+///
+/// Some system functions with variable length output data fail for
+/// insufficient buffer sizes, and return an exact buffer length required.
+/// The function helpers use a fixed size stack buffer first. If the stack
+/// buffer really prooved sufficient, the helper allocates the exact length
+/// output on heap and copies the data without calling the system function
+/// again. Otherwise it allocates the exact length output on heap and retries.
+///
+/// \note
+/// Decrease this value in case of stack overflow.
+///
+#define ATL_STACK_BUFFER_BYTES 1024
+#endif
+
+
+namespace ATL
+{
+ ///
+ /// \defgroup ATLSysHandles System Handles
+ /// Simplifies work with object handles of various type
+ ///
+ /// @{
+
+ ///
+ /// Base abstract template class to support generic object handle keeping
+ ///
+ /// It provides basic operators and methods common to all descendands of this class
establishing a base to ease the replacement of native object handle type with classes in
object-oriented approach.
+ ///
+ template <class T> class CObjectWithHandleT
+ {
+ public:
+ ///
+ /// Datatype of the object handle this template class handles
+ ///
+ typedef T HANDLE;
+
+ ///
+ /// Initializes a new class instance with the object handle set to NULL.
+ ///
+ inline CObjectWithHandleT() : m_h(NULL)
+ {
+ }
+
+ ///
+ /// Initializes a new class instance with an available object handle.
+ ///
+ /// \param[in] h Initial object handle value
+ ///
+ inline CObjectWithHandleT(_In_opt_ HANDLE h) : m_h(h)
+ {
+ }
+
+ /// \name Operators for transparent usage of this class
+ /// @{
+
+ ///
+ /// Auto-typecasting operator
+ ///
+ /// \return Object handle
+ ///
+ inline operator HANDLE() const
+ {
+ return m_h;
+ }
+
+ ///
+ /// Returns the object handle value when the object handle is a pointer to a
value (class, struct, etc.).
+ ///
+ /// \return Object handle value
+ ///
+ inline HANDLE*& operator*() const
+ {
+ ATLENSURE(m_h != NULL);
+ return *m_h;
+ }
+
+ ///
+ /// Returns the object handle reference.
+ /// \return Object handle reference
+ ///
+ inline HANDLE* operator&()
+ {
+ ATLASSERT(m_h == NULL);
+ return &m_h;
+ }
+
+ ///
+ /// Provides object handle member access when the object handle is a pointer to a
class or struct.
+ ///
+ /// \return Object handle
+ ///
+ inline HANDLE operator->() const
+ {
+ ATLASSERT(m_h != NULL);
+ return m_h;
+ }
+
+ /// @}
+
+ /// \name Comparison operators
+ /// @{
+
+ ///
+ /// Tests if the object handle is NULL.
+ ///
+ /// \return
+ /// - Non zero when object handle is NULL;
+ /// - Zero otherwise.
+ ///
+ inline bool operator!() const
+ {
+ return m_h == NULL;
+ }
+
+ ///
+ /// Is handle less than?
+ ///
+ /// \param[in] h Object handle to compare against
+ /// \return
+ /// - Non zero when object handle is less than h;
+ /// - Zero otherwise.
+ ///
+ inline bool operator<(_In_opt_ HANDLE h) const
+ {
+ return m_h < h;
+ }
+
+ ///
+ /// Is handle less than or equal to?
+ ///
+ /// \param[in] h Object handle to compare against
+ /// \return
+ /// - Non zero when object handle is less than or equal to h;
+ /// - Zero otherwise.
+ ///
+ inline bool operator<=(_In_opt_ HANDLE h) const
+ {
+ return m_h <= h;
+ }
+
+ ///
+ /// Is handle greater than or equal to?
+ ///
+ /// \param[in] h Object handle to compare against
+ /// \return
+ /// - Non zero when object handle is greater than or equal to h;
+ /// - Zero otherwise.
+ ///
+ inline bool operator>=(_In_opt_ HANDLE h) const
+ {
+ return m_h >= h;
+ }
+
+ ///
+ /// Is handle greater than?
+ ///
+ /// \param[in] h Object handle to compare against
+ /// \return
+ /// - Non zero when object handle is greater than h;
+ /// - Zero otherwise.
+ ///
+ inline bool operator>(_In_opt_ HANDLE h) const
+ {
+ return m_h > h;
+ }
+
+ ///
+ /// Is handle not equal to?
+ ///
+ /// \param[in] h Object handle to compare against
+ /// \return
+ /// - Non zero when object handle is not equal to h;
+ /// - Zero otherwise.
+ ///
+ inline bool operator!=(_In_opt_ HANDLE h) const
+ {
+ return !operator==(h);
+ }
+
+ ///
+ /// Is handle equal to?
+ ///
+ /// \param[in] h Object handle to compare against
+ /// \return
+ /// - Non zero when object handle is equal to h;
+ /// - Zero otherwise.
+ ///
+ inline bool operator==(_In_opt_ HANDLE h) const
+ {
+ return m_h == h;
+ }
+
+ /// @}
+
+ ///
+ /// Sets a new object handle for the class
+ ///
+ /// When the current object handle of the class is non-NULL, the object is
destroyed first.
+ ///
+ /// \param[in] h New object handle
+ ///
+ inline void Attach(_In_opt_ HANDLE h)
+ {
+ if (m_h)
+ InternalFree();
+ m_h = h;
+ }
+
+ ///
+ /// Dismisses the object handle from this class
+ ///
+ /// \return Object handle
+ ///
+ inline HANDLE Detach()
+ {
+ HANDLE h = m_h;
+ m_h = NULL;
+ return h;
+ }
+
+ ///
+ /// Destroys the object
+ ///
+ inline void Free()
+ {
+ if (m_h) {
+ InternalFree();
+ m_h = NULL;
+ }
+ }
+
+ /// @}
+
+ protected:
+ ///
+ /// Abstract member function that must be implemented by child classes to do the
actual object destruction.
+ ///
+ virtual void InternalFree() = 0;
+
+ protected:
+ HANDLE m_h; ///< Object handle
+ };
+
+
+ ///
+ /// Base abstract template class to support object handle keeping for objects that
support handle duplication
+ ///
+ template <class T>
+ class CObjectWithHandleDuplT : public CObjectWithHandleT<T>
+ {
+ public:
+ ///
+ /// Duplicates and returns a new object handle.
+ ///
+ /// \return Duplicated object handle
+ ///
+ inline HANDLE GetDuplicate() const
+ {
+ return m_h ? InternalDuplicate(m_h) : NULL;
+ }
+
+ ///
+ /// Duplicates an object handle and sets a new object handle.
+ ///
+ /// \param[in] h Object handle of existing object
+ /// \return
+ /// - TRUE when duplication succeeds;
+ /// - FALSE when duplication fails. In case of failure obtaining the extended
error information is object type specific (for example: `GetLastError()`).
+ ///
+ inline BOOL DuplicateAndAttach(_In_opt_ HANDLE h)
+ {
+ if (m_h)
+ InternalFree();
+
+ return h ? (m_h = InternalDuplicate(h)) != NULL : (m_h = NULL, TRUE);
+ }
+
+ //
+ // Do not allow = operators. They are semantically ambigious:
+ // Do they attach the class to the existing instance of object, or do they
duplicate it?
+ // To avoid confusion, user should use Attach() and Duplicate() methods
explicitly.
+ //
+ //inline const CObjectWithHandleDuplT<T>& operator=(_In_ const HANDLE
src)
+ //{
+ // Attach(src ? InternalDuplicate(src) : NULL);
+ // return *this;
+ //}
+
+ //inline const CObjectWithHandleDuplT<T>& operator=(_In_ const
CObjectWithHandleDuplT<T> &src)
+ //{
+ // Attach(src.m_h ? InternalDuplicate(src.m_h) : NULL);
+ // return *this;
+ //}
+
+ protected:
+ ///
+ /// Abstract member function that must be implemented by child classes to do the
actual object handle duplication.
+ ///
+ /// \param[in] h Object handle of existing object
+ /// \return Duplicated object handle
+ ///
+ virtual HANDLE InternalDuplicate(_In_ HANDLE h) const = 0;
+ };
+
+ /// @}
+
+ ///
+ /// \defgroup ATLStrFormat String Formatting
+ /// Formatted string generation
+ ///
+ /// \par Example
+ /// \code
+ /// // Please note the PCSTR typecasting invokes an operator to return
+ /// // pointer to formatted buffer rather than class reference itself.
+ /// cout << (PCSTR)(CStrFormatA("%i is less than %i.\n", 1, 5));
+ /// \endcode
+ ///
+ /// @{
+
+ ///
+ /// Base template class to support string formatting using `printf()` style
templates
+ ///
+ template<typename BaseType, class StringTraits>
+ class CStrFormatT : public CStringT<BaseType, StringTraits>
+ {
+ public:
+ /// \name Initializing string using template in memory
+ /// @{
+
+ ///
+ /// Initializes a new string and formats its contents using `printf()` style
template.
+ ///
+ /// \param[in] pszFormat String template using `printf()` style
+ ///
+ CStrFormatT(_In_z_ _Printf_format_string_ PCXSTR pszFormat, ...)
+ {
+ ATLASSERT(AtlIsValidString(pszFormat));
+
+ va_list argList;
+ va_start(argList, pszFormat);
+ FormatV(pszFormat, argList);
+ va_end(argList);
+ }
+
+ /// @}
+
+ /// \name Initializing string using template in resources
+ /// @{
+
+ ///
+ /// Initializes a new string and formats its contents using `printf()` style
template in resources.
+ ///
+ /// \param[in] nFormatID Resource ID of the string template using `printf()`
style
+ ///
+ CStrFormatT(_In_ UINT nFormatID, ...)
+ {
+ CStringT strFormat(GetManager());
+ ATLENSURE(strFormat.LoadString(nFormatID));
+
+ va_list argList;
+ va_start(argList, nFormatID);
+ FormatV(strFormat, argList);
+ va_end(argList);
+ }
+
+ ///
+ /// Initializes a new string and formats its contents using `printf()` style
template in resources.
+ ///
+ /// \param[in] hInstance Resource module handle
+ /// \param[in] nFormatID Resource ID of the string template using `printf()`
style
+ ///
+ CStrFormatT(_In_ HINSTANCE hInstance, _In_ UINT nFormatID, ...)
+ {
+ CStringT strFormat(GetManager());
+ ATLENSURE(strFormat.LoadString(hInstance, nFormatID));
+
+ va_list argList;
+ va_start(argList, nFormatID);
+ FormatV(strFormat, argList);
+ va_end(argList);
+ }
+
+ ///
+ /// Initializes a new string and formats its contents using `printf()` style
template in resources.
+ ///
+ /// \param[in] hInstance Resource module handle
+ /// \param[in] wLanguageID Resource language
+ /// \param[in] nFormatID Resource ID of the string template using `printf()`
style
+ ///
+ CStrFormatT(_In_ HINSTANCE hInstance, _In_ WORD wLanguageID, _In_ UINT nFormatID,
...)
+ {
+ CStringT strFormat(GetManager());
+ ATLENSURE(strFormat.LoadString(hInstance, nFormatID, wLanguageID));
+
+ va_list argList;
+ va_start(argList, nFormatID);
+ FormatV(strFormat, argList);
+ va_end(argList);
+ }
+
+ /// }@
+ };
+
+ ///
+ /// Wide character implementation of a class to support string formatting using
`printf()` style templates
+ ///
+ typedef CStrFormatT< wchar_t, StrTraitATL< wchar_t, ChTraitsCRT< wchar_t
> > > CStrFormatW;
+
+ ///
+ /// Single-byte character implementation of a class to support string formatting
using `printf()` style templates
+ ///
+ typedef CStrFormatT< char, StrTraitATL< char, ChTraitsCRT< char > >
> CStrFormatA;
+
+ ///
+ /// TCHAR implementation of a class to support string formatting using `printf()`
style templates
+ ///
+ typedef CStrFormatT< TCHAR, StrTraitATL< TCHAR, ChTraitsCRT< TCHAR > >
> CStrFormat;
+
+
+ ///
+ /// Base template class to support string formatting using `FormatMessage()` style
templates
+ ///
+ template<typename BaseType, class StringTraits>
+ class CStrFormatMsgT : public CStringT<BaseType, StringTraits>
+ {
+ public:
+ /// \name Initializing string using template in memory
+ /// @{
+
+ ///
+ /// Initializes a new string and formats its contents using `FormatMessage()`
style template.
+ ///
+ /// \param[in] pszFormat String template using `FormatMessage()` style
+ ///
+ CStrFormatMsgT(_In_z_ _FormatMessage_format_string_ PCXSTR pszFormat, ...)
+ {
+ ATLASSERT(AtlIsValidString(pszFormat));
+
+ va_list argList;
+ va_start(argList, pszFormat);
+ FormatMessageV(pszFormat, &argList);
+ va_end(argList);
+ }
+
+ /// @}
+
+ /// \name Initializing string using template in resources
+ /// @{
+
+ ///
+ /// Initializes a new string and formats its contents using `FormatMessage()`
style template in resources.
+ ///
+ /// \param[in] nFormatID Resource ID of the string template using
`FormatMessage()` style
+ ///
+ CStrFormatMsgT(_In_ UINT nFormatID, ...)
+ {
+ CStringT strFormat(GetManager());
+ ATLENSURE(strFormat.LoadString(nFormatID));
+
+ va_list argList;
+ va_start(argList, nFormatID);
+ FormatMessageV(strFormat, &argList);
+ va_end(argList);
+ }
+
+ ///
+ /// Initializes a new string and formats its contents using `FormatMessage()`
style template in resources.
+ ///
+ /// \param[in] hInstance Resource module handle
+ /// \param[in] nFormatID Resource ID of the string template using
`FormatMessage()` style
+ ///
+ CStrFormatMsgT(_In_ HINSTANCE hInstance, _In_ UINT nFormatID, ...)
+ {
+ CStringT strFormat(GetManager());
+ ATLENSURE(strFormat.LoadString(hInstance, nFormatID));
+
+ va_list argList;
+ va_start(argList, nFormatID);
+ FormatMessageV(strFormat, &argList);
+ va_end(argList);
+ }
+
+ ///
+ /// Initializes a new string and formats its contents using `FormatMessage()`
style template in resources.
+ ///
+ /// \param[in] hInstance Resource module handle
+ /// \param[in] wLanguageID Resource language
+ /// \param[in] nFormatID Resource ID of the string template using
`FormatMessage()` style
+ ///
+ CStrFormatMsgT(_In_ HINSTANCE hInstance, _In_ WORD wLanguageID, _In_ UINT
nFormatID, ...)
+ {
+ CStringT strFormat(GetManager());
+ ATLENSURE(strFormat.LoadString(hInstance, nFormatID, wLanguageID));
+
+ va_list argList;
+ va_start(argList, nFormatID);
+ FormatMessageV(strFormat, &argList);
+ va_end(argList);
+ }
+
+ /// @}
+ };
+
+ ///
+ /// Wide character implementation of a class to support string formatting using
`FormatMessage()` style templates
+ ///
+ typedef CStrFormatMsgT< wchar_t, StrTraitATL< wchar_t, ChTraitsCRT< wchar_t
> > > CStrFormatMsgW;
+
+ ///
+ /// Single-byte character implementation of a class to support string formatting
using `FormatMessage()` style templates
+ ///
+ typedef CStrFormatMsgT< char, StrTraitATL< char, ChTraitsCRT< char > >
> CStrFormatMsgA;
+
+ ///
+ /// TCHAR implementation of a class to support string formatting using
`FormatMessage()` style templates
+ ///
+ typedef CStrFormatMsgT< TCHAR, StrTraitATL< TCHAR, ChTraitsCRT< TCHAR >
> > CStrFormatMsg;
+
+ /// @}
+
+ /// \defgroup ATLMemSanitize Auto-sanitize Memory Management
+ /// Sanitizes memory before dismissed
+ ///
+ /// @{
+
+ ///
+ /// A heap template that sanitizes each memory block before it is destroyed or
reallocated
+ ///
+ /// This template is typcally used to extend one of the base ATL heap management
classes.
+ ///
+ /// \par Example
+ /// \code
+ /// CParanoidHeap<CWin32Heap> myHeap;
+ /// \endcode
+ ///
+ /// \note
+ /// CParanoidHeap introduces a performance penalty. However, it provides an
additional level of security.
+ /// Use for security sensitive data memory storage only.
+ ///
+ /// \sa [Memory Management
Classes](https://msdn.microsoft.com/en-us/library/44yh1z4f.aspx)
+ ///
+ template <class BaseHeap>
+ class CParanoidHeap : public BaseHeap {
+ public:
+ ///
+ /// Sanitizes memory before freeing it
+ ///
+ /// \param[in] p Pointer to heap memory block
+ ///
+ virtual void Free(_In_opt_ void* p)
+ {
+ // Sanitize then free.
+ SecureZeroMemory(p, GetSize(p));
+ BaseHeap::Free(p);
+ }
+
+ ///
+ /// Safely reallocates the memory block by sanitizing memory at the previous
location
+ ///
+ /// This member function always performs the following steps (regardless of the
current and new size):
+ /// 1. Allocates a new memory block,
+ /// 2. Copies the data,
+ /// 3. Sanitizes the old memory block,
+ /// 4. Frees the old memory block.
+ ///
+ /// \param[in] p Pointer to heap memory block
+ /// \param[in] nBytes New size in bytes
+ /// \return Pointer to the new heap memory block
+ ///
+ virtual /*_Ret_opt_bytecap_(nBytes)*/ void* Reallocate(_In_opt_ void* p, _In_
size_t nBytes)
+ {
+ // Create a new sized copy.
+ void *pNew = Allocate(nBytes);
+ size_t nSizePrev = GetSize(p);
+ CopyMemory(pNew, p, nSizePrev);
+
+ // Sanitize the old data then free.
+ SecureZeroMemory(p, nSizePrev);
+ Free(p);
+
+ return pNew;
+ }
+ };
+
+
+ ///
+ /// Base template class to support string conversion with memory sanitization after
use
+ ///
+ template<int t_nBufferLength = 128>
+ class CW2AParanoidEX : public CW2AEX<t_nBufferLength> {
+ public:
+ ///
+ /// Initializes a new class instance with the string provided.
+ ///
+ /// \param[in] psz Pointer to wide string
+ ///
+ CW2AParanoidEX(_In_z_ LPCWSTR psz) throw(...) :
CW2AEX<t_nBufferLength>(psz) {}
+
+ ///
+ /// Initializes a new class instance with the string provided.
+ ///
+ /// \param[in] psz Pointer to wide string
+ /// \param[in] nCodePage Code page to use when converting to single-byte string
+ ///
+ CW2AParanoidEX(_In_z_ LPCWSTR psz, _In_ UINT nCodePage) throw(...) :
CW2AEX<t_nBufferLength>(psz, nCodePage) {}
+
+ ///
+ /// Sanitizes string memory, then destroys it
+ ///
+ ~CW2AParanoidEX()
+ {
+ // Sanitize before free.
+ if (m_psz != m_szBuffer)
+ SecureZeroMemory(m_psz, _msize(m_psz));
+ else
+ SecureZeroMemory(m_szBuffer, sizeof(m_szBuffer));
+ }
+ };
+
+ ///
+ /// Support for string conversion with memory sanitization after use
+ ///
+ typedef CW2AParanoidEX<> CW2AParanoid;
+
+ /// @}
+}
Propchange: branches/GSoC_2017/rapps/reactos/sdk/include/reactos/atlex/atlex.h
------------------------------------------------------------------------------
svn:eol-style = native
Added: branches/GSoC_2017/rapps/reactos/sdk/include/reactos/atlex/atlmsi.h
URL:
http://svn.reactos.org/svn/reactos/branches/GSoC_2017/rapps/reactos/sdk/inc…
==============================================================================
--- branches/GSoC_2017/rapps/reactos/sdk/include/reactos/atlex/atlmsi.h (added)
+++ branches/GSoC_2017/rapps/reactos/sdk/include/reactos/atlex/atlmsi.h [iso-8859-1] Tue
Jul 11 22:08:48 2017
@@ -0,0 +1,326 @@
+/*
+ Copyright 1991-2017 Amebis
+
+ This file is part of atlex.
+
+ 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 <http://www.gnu.org/licenses/>.
+*/
+
+#pragma once
+
+#include "atlex.h"
+#include <atlcoll.h>
+#include <atlstr.h>
+#include <MsiQuery.h>
+
+///
+/// \defgroup ATLMSIAPI Microsoft Installer API
+/// Integrates ATL classes with Microsoft Installer API
+///
+/// @{
+
+///
+/// Gets the value for an installer property and stores it in a ATL::CAtlStringA string.
+///
+/// \sa [MsiGetProperty
function](https://msdn.microsoft.com/en-us/library/aa370134.aspx)
+///
+inline UINT MsiGetPropertyA(_In_ MSIHANDLE hInstall, _In_ LPCSTR szName, _Out_
ATL::CAtlStringA &sValue)
+{
+ CHAR szStackBuffer[ATL_STACK_BUFFER_BYTES/sizeof(CHAR)];
+ DWORD dwSize = _countof(szStackBuffer);
+ UINT uiResult;
+
+ // Try with stack buffer first.
+ uiResult = ::MsiGetPropertyA(hInstall, szName, szStackBuffer, &dwSize);
+ if (uiResult == NO_ERROR) {
+ // Allocate buffer on heap, copy from stack buffer, and zero terminate.
+ LPSTR szBuffer = sValue.GetBuffer(dwSize);
+ if (!szBuffer) return ERROR_OUTOFMEMORY;
+ memcpy(szBuffer, szStackBuffer, dwSize);
+ sValue.ReleaseBuffer(dwSize);
+ return NO_ERROR;
+ } else if (uiResult == ERROR_MORE_DATA) {
+ // Allocate buffer on heap 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 {
+ // Return error code.
+ return uiResult;
+ }
+}
+
+
+///
+/// Gets the value for an installer property and stores it in a ATL::CAtlStringW string.
+///
+/// \sa [MsiGetProperty
function](https://msdn.microsoft.com/en-us/library/aa370134.aspx)
+///
+inline UINT MsiGetPropertyW(_In_ MSIHANDLE hInstall, _In_ LPCWSTR szName, _Out_
ATL::CAtlStringW &sValue)
+{
+ WCHAR szStackBuffer[ATL_STACK_BUFFER_BYTES/sizeof(WCHAR)];
+ DWORD dwSize = _countof(szStackBuffer);
+ UINT uiResult;
+
+ // Try with stack buffer first.
+ uiResult = ::MsiGetPropertyW(hInstall, szName, szStackBuffer, &dwSize);
+ if (uiResult == NO_ERROR) {
+ // Allocate buffer on heap, copy from stack buffer, and zero terminate.
+ LPWSTR szBuffer = sValue.GetBuffer(dwSize);
+ if (!szBuffer) return ERROR_OUTOFMEMORY;
+ wmemcpy(szBuffer, szStackBuffer, dwSize);
+ sValue.ReleaseBuffer(dwSize);
+ return NO_ERROR;
+ } else if (uiResult == ERROR_MORE_DATA) {
+ // Allocate buffer on heap 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 {
+ // Return error code.
+ return uiResult;
+ }
+}
+
+
+///
+/// Returns the string value of a record field and stores it in a ATL::CAtlStringA
string.
+///
+/// \sa [MsiRecordGetString
function](https://msdn.microsoft.com/en-us/library/aa370368.aspx)
+///
+inline UINT MsiRecordGetStringA(_In_ MSIHANDLE hRecord, _In_ unsigned int iField, _Out_
ATL::CAtlStringA &sValue)
+{
+ CHAR szStackBuffer[ATL_STACK_BUFFER_BYTES/sizeof(CHAR)];
+ DWORD dwSize = _countof(szStackBuffer);
+ UINT uiResult;
+
+ // Try with stack buffer first.
+ uiResult = ::MsiRecordGetStringA(hRecord, iField, szStackBuffer, &dwSize);
+ if (uiResult == NO_ERROR) {
+ // Allocate buffer on heap, copy from stack buffer, and zero terminate.
+ LPSTR szBuffer = sValue.GetBuffer(dwSize);
+ if (!szBuffer) return ERROR_OUTOFMEMORY;
+ memcpy(szBuffer, szStackBuffer, dwSize);
+ sValue.ReleaseBuffer(dwSize);
+ return NO_ERROR;
+ } else if (uiResult == ERROR_MORE_DATA) {
+ // Allocate buffer on heap 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 {
+ // Return error code.
+ return uiResult;
+ }
+}
+
+
+///
+/// Returns the string value of a record field and stores it in a ATL::CAtlStringW
string.
+///
+/// \sa [MsiRecordGetString
function](https://msdn.microsoft.com/en-us/library/aa370368.aspx)
+///
+inline UINT MsiRecordGetStringW(_In_ MSIHANDLE hRecord, _In_ unsigned int iField, _Out_
ATL::CAtlStringW &sValue)
+{
+ WCHAR szStackBuffer[ATL_STACK_BUFFER_BYTES/sizeof(WCHAR)];
+ DWORD dwSize = _countof(szStackBuffer);
+ UINT uiResult;
+
+ // Try with stack buffer first.
+ uiResult = ::MsiRecordGetStringW(hRecord, iField, szStackBuffer, &dwSize);
+ if (uiResult == NO_ERROR) {
+ // Allocate buffer on heap, copy from stack buffer, and zero terminate.
+ LPWSTR szBuffer = sValue.GetBuffer(dwSize);
+ if (!szBuffer) return ERROR_OUTOFMEMORY;
+ wmemcpy(szBuffer, szStackBuffer, dwSize);
+ sValue.ReleaseBuffer(dwSize);
+ return NO_ERROR;
+ } else if (uiResult == ERROR_MORE_DATA) {
+ // Allocate buffer on heap 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 {
+ // Return error code.
+ return uiResult;
+ }
+}
+
+
+///
+/// Formats record field data and properties using a format string and stores it in a
ATL::CAtlStringA string.
+///
+/// \sa [MsiFormatRecord
function](https://msdn.microsoft.com/en-us/library/aa370109.aspx)
+///
+inline UINT MsiFormatRecordA(MSIHANDLE hInstall, MSIHANDLE hRecord, ATL::CAtlStringA
&sValue)
+{
+ CHAR szStackBuffer[ATL_STACK_BUFFER_BYTES/sizeof(CHAR)];
+ DWORD dwSize = _countof(szStackBuffer);
+ UINT uiResult;
+
+ // Try with stack buffer first.
+ uiResult = ::MsiFormatRecordA(hInstall, hRecord, szStackBuffer, &dwSize);
+ if (uiResult == NO_ERROR) {
+ // Allocate buffer on heap, copy from stack buffer, and zero terminate.
+ LPSTR szBuffer = sValue.GetBuffer(dwSize);
+ if (!szBuffer) return ERROR_OUTOFMEMORY;
+ memcpy(szBuffer, szStackBuffer, dwSize);
+ sValue.ReleaseBuffer(dwSize);
+ return NO_ERROR;
+ } else if (uiResult == ERROR_MORE_DATA) {
+ // Allocate buffer on heap 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 {
+ // Return error code.
+ return uiResult;
+ }
+}
+
+
+///
+/// Formats record field data and properties using a format string and stores it in a
ATL::CAtlStringW string.
+///
+/// \sa [MsiFormatRecord
function](https://msdn.microsoft.com/en-us/library/aa370109.aspx)
+///
+inline UINT MsiFormatRecordW(MSIHANDLE hInstall, MSIHANDLE hRecord, ATL::CAtlStringW
&sValue)
+{
+ WCHAR szStackBuffer[ATL_STACK_BUFFER_BYTES/sizeof(WCHAR)];
+ DWORD dwSize = _countof(szStackBuffer);
+ UINT uiResult;
+
+ // Try with stack buffer first.
+ uiResult = ::MsiFormatRecordW(hInstall, hRecord, szStackBuffer, &dwSize);
+ if (uiResult == NO_ERROR) {
+ // Allocate buffer on heap, copy from stack buffer, and zero terminate.
+ LPWSTR szBuffer = sValue.GetBuffer(dwSize);
+ if (!szBuffer) return ERROR_OUTOFMEMORY;
+ wmemcpy(szBuffer, szStackBuffer, dwSize);
+ sValue.ReleaseBuffer(dwSize);
+ return NO_ERROR;
+ } else if (uiResult == ERROR_MORE_DATA) {
+ // Allocate buffer on heap 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 {
+ // Return error code.
+ return uiResult;
+ }
+}
+
+
+///
+/// Reads bytes from a record stream field into a ATL::CAtlArray<BYTE> buffer.
+///
+/// \sa [MsiRecordReadStream
function](https://msdn.microsoft.com/en-us/library/aa370370.aspx)
+///
+inline UINT MsiRecordReadStream(_In_ MSIHANDLE hRecord, _In_ unsigned int iField, _Out_
ATL::CAtlArray<BYTE> &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;
+ }
+}
+
+
+///
+/// Returns the full target path for a folder in the Directory table and stores it in a
ATL::CAtlStringA string.
+///
+/// \sa [MsiGetTargetPath
function](https://msdn.microsoft.com/en-us/library/aa370303.aspx)
+///
+inline UINT MsiGetTargetPathA(_In_ MSIHANDLE hInstall, _In_ LPCSTR szFolder, _Out_
ATL::CAtlStringA &sValue)
+{
+ CHAR szStackBuffer[ATL_STACK_BUFFER_BYTES/sizeof(CHAR)];
+ DWORD dwSize = _countof(szStackBuffer);
+ UINT uiResult;
+
+ // Try with stack buffer first.
+ uiResult = ::MsiGetTargetPathA(hInstall, szFolder, szStackBuffer, &dwSize);
+ if (uiResult == NO_ERROR) {
+ // Allocate buffer on heap, copy from stack buffer, and zero terminate.
+ LPSTR szBuffer = sValue.GetBuffer(dwSize);
+ if (!szBuffer) return ERROR_OUTOFMEMORY;
+ memcpy(szBuffer, szStackBuffer, dwSize);
+ sValue.ReleaseBuffer(dwSize);
+ return NO_ERROR;
+ } else if (uiResult == ERROR_MORE_DATA) {
+ // Allocate buffer on heap 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 {
+ // Return error code.
+ return uiResult;
+ }
+}
+
+
+///
+/// Returns the full target path for a folder in the Directory table and stores it in a
ATL::CAtlStringW string.
+///
+/// \sa [MsiGetTargetPath
function](https://msdn.microsoft.com/en-us/library/aa370303.aspx)
+///
+inline UINT MsiGetTargetPathW(_In_ MSIHANDLE hInstall, _In_ LPCWSTR szFolder, _Out_
ATL::CAtlStringW &sValue)
+{
+ WCHAR szStackBuffer[ATL_STACK_BUFFER_BYTES/sizeof(WCHAR)];
+ DWORD dwSize = _countof(szStackBuffer);
+ UINT uiResult;
+
+ // Try with stack buffer first.
+ uiResult = ::MsiGetTargetPathW(hInstall, szFolder, szStackBuffer, &dwSize);
+ if (uiResult == NO_ERROR) {
+ // Allocate buffer on heap, copy from stack buffer, and zero terminate.
+ LPWSTR szBuffer = sValue.GetBuffer(dwSize);
+ if (!szBuffer) return ERROR_OUTOFMEMORY;
+ wmemcpy(szBuffer, szStackBuffer, dwSize);
+ sValue.ReleaseBuffer(dwSize);
+ return NO_ERROR;
+ } else if (uiResult == ERROR_MORE_DATA) {
+ // Allocate buffer on heap 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 {
+ // Return error code.
+ return uiResult;
+ }
+}
+
+/// @}
Propchange: branches/GSoC_2017/rapps/reactos/sdk/include/reactos/atlex/atlmsi.h
------------------------------------------------------------------------------
svn:eol-style = native
Added: branches/GSoC_2017/rapps/reactos/sdk/include/reactos/atlex/atlsec.h
URL:
http://svn.reactos.org/svn/reactos/branches/GSoC_2017/rapps/reactos/sdk/inc…
==============================================================================
--- branches/GSoC_2017/rapps/reactos/sdk/include/reactos/atlex/atlsec.h (added)
+++ branches/GSoC_2017/rapps/reactos/sdk/include/reactos/atlex/atlsec.h [iso-8859-1] Tue
Jul 11 22:08:48 2017
@@ -0,0 +1,117 @@
+/*
+ Copyright 1991-2017 Amebis
+
+ This file is part of atlex.
+
+ 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 <http://www.gnu.org/licenses/>.
+*/
+
+#pragma once
+
+#include <Security.h>
+
+///
+/// \defgroup ATLSecurityAPI Security API
+/// Integrates ATL classes with Microsoft Security API
+///
+/// @{
+
+///
+/// Retrieves the name of the user or other security principal associated with the
calling thread and stores it in a ATL::CAtlStringA string.
+///
+/// \sa [GetUserNameEx
function](https://msdn.microsoft.com/en-us/library/windows/desktop/ms724435…
+///
+BOOLEAN GetUserNameExA(_In_ EXTENDED_NAME_FORMAT NameFormat, _Out_ ATL::CAtlStringA
&sName)
+{
+ CHAR szStackBuffer[ATL_STACK_BUFFER_BYTES/sizeof(CHAR)];
+ ULONG ulSize = _countof(szStackBuffer);
+
+ // Try with stack buffer first.
+ if (::GetUserNameExA(NameFormat, szStackBuffer, &ulSize)) {
+ // Allocate buffer on heap, copy from stack buffer, and zero terminate.
+ LPSTR szBuffer = sName.GetBuffer(ulSize);
+ if (!szBuffer) {
+ SetLastError(ERROR_OUTOFMEMORY);
+ return FALSE;
+ }
+ memcpy(szBuffer, szStackBuffer, ulSize);
+ sName.ReleaseBuffer(ulSize);
+ return TRUE;
+ } else {
+ if (::GetLastError() == ERROR_MORE_DATA) {
+ // Allocate buffer on heap and retry.
+ LPSTR szBuffer = sName.GetBuffer(ulSize - 1);
+ if (!szBuffer) {
+ SetLastError(ERROR_OUTOFMEMORY);
+ return FALSE;
+ }
+ if (::GetUserNameExA(NameFormat, szBuffer, &ulSize)) {
+ sName.ReleaseBuffer(ulSize);
+ return TRUE;
+ } else {
+ sName.ReleaseBuffer(0);
+ return FALSE;
+ }
+ } else {
+ // Return error.
+ return FALSE;
+ }
+ }
+}
+
+
+///
+/// Retrieves the name of the user or other security principal associated with the
calling thread and stores it in a ATL::CAtlStringW string.
+///
+/// \sa [GetUserNameEx
function](https://msdn.microsoft.com/en-us/library/windows/desktop/ms724435…
+///
+BOOLEAN GetUserNameExW(_In_ EXTENDED_NAME_FORMAT NameFormat, _Out_ ATL::CAtlStringW
&sName)
+{
+ WCHAR szStackBuffer[ATL_STACK_BUFFER_BYTES/sizeof(WCHAR)];
+ ULONG ulSize = _countof(szStackBuffer);
+
+ // Try with stack buffer first.
+ if (::GetUserNameExW(NameFormat, szStackBuffer, &ulSize)) {
+ // Allocate buffer on heap, copy from stack buffer, and zero terminate.
+ LPWSTR szBuffer = sName.GetBuffer(ulSize);
+ if (!szBuffer) {
+ SetLastError(ERROR_OUTOFMEMORY);
+ return FALSE;
+ }
+ wmemcpy(szBuffer, szStackBuffer, ulSize);
+ sName.ReleaseBuffer(ulSize);
+ return TRUE;
+ } else {
+ if (::GetLastError() == ERROR_MORE_DATA) {
+ // Allocate buffer on heap and retry.
+ LPWSTR szBuffer = sName.GetBuffer(ulSize - 1);
+ if (!szBuffer) {
+ SetLastError(ERROR_OUTOFMEMORY);
+ return FALSE;
+ }
+ if (::GetUserNameExW(NameFormat, szBuffer, &ulSize)) {
+ sName.ReleaseBuffer(ulSize);
+ return TRUE;
+ } else {
+ sName.ReleaseBuffer(0);
+ return FALSE;
+ }
+ } else {
+ // Return error.
+ return FALSE;
+ }
+ }
+}
+
+/// @}
Propchange: branches/GSoC_2017/rapps/reactos/sdk/include/reactos/atlex/atlsec.h
------------------------------------------------------------------------------
svn:eol-style = native
Added: branches/GSoC_2017/rapps/reactos/sdk/include/reactos/atlex/atlshlwapi.h
URL:
http://svn.reactos.org/svn/reactos/branches/GSoC_2017/rapps/reactos/sdk/inc…
==============================================================================
--- branches/GSoC_2017/rapps/reactos/sdk/include/reactos/atlex/atlshlwapi.h (added)
+++ branches/GSoC_2017/rapps/reactos/sdk/include/reactos/atlex/atlshlwapi.h [iso-8859-1]
Tue Jul 11 22:08:48 2017
@@ -0,0 +1,70 @@
+/*
+ Copyright 1991-2017 Amebis
+
+ This file is part of atlex.
+
+ 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 <http://www.gnu.org/licenses/>.
+*/
+
+#pragma once
+
+#include <atlstr.h>
+#include <Shlwapi.h>
+
+///
+/// \defgroup ATLShellWAPI Shell API
+/// Integrates ATL classes with Microsoft Shell API
+///
+/// @{
+
+///
+/// Simplifies a path by removing navigation elements such as "." and
".." to produce a direct, well-formed path, and stores it in a ATL::CAtlStringA
string.
+///
+/// \sa [PathCanonicalize
function](https://msdn.microsoft.com/en-us/library/windows/desktop/bb773569…
+///
+inline BOOL PathCanonicalizeA(__out ATL::CAtlStringA &sValue, __in LPCSTR pszPath)
+{
+ // Allocate buffer on heap and read into it.
+ LPSTR szBuffer = sValue.GetBuffer(MAX_PATH);
+ if (!szBuffer) {
+ ::SetLastError(ERROR_OUTOFMEMORY);
+ return FALSE;
+ }
+ BOOL bResult = ::PathCanonicalizeA(szBuffer, pszPath);
+ sValue.ReleaseBuffer(bResult ? (int)strnlen(szBuffer, MAX_PATH) : 0);
+ sValue.FreeExtra();
+ return bResult;
+}
+
+
+///
+/// Simplifies a path by removing navigation elements such as "." and
".." to produce a direct, well-formed path, and stores it in a ATL::CAtlStringW
string.
+///
+/// \sa [PathCanonicalize
function](https://msdn.microsoft.com/en-us/library/windows/desktop/bb773569…
+///
+inline BOOL PathCanonicalizeW(__out ATL::CAtlStringW &sValue, __in LPCWSTR pszPath)
+{
+ // Allocate buffer on heap and read into it.
+ LPWSTR szBuffer = sValue.GetBuffer(MAX_PATH);
+ if (!szBuffer) {
+ ::SetLastError(ERROR_OUTOFMEMORY);
+ return FALSE;
+ }
+ BOOL bResult = ::PathCanonicalizeW(szBuffer, pszPath);
+ sValue.ReleaseBuffer(bResult ? (int)wcsnlen(szBuffer, MAX_PATH) : 0);
+ sValue.FreeExtra();
+ return bResult;
+}
+
+/// @}
Propchange: branches/GSoC_2017/rapps/reactos/sdk/include/reactos/atlex/atlshlwapi.h
------------------------------------------------------------------------------
svn:eol-style = native
Added: branches/GSoC_2017/rapps/reactos/sdk/include/reactos/atlex/atlwin.h
URL:
http://svn.reactos.org/svn/reactos/branches/GSoC_2017/rapps/reactos/sdk/inc…
==============================================================================
--- branches/GSoC_2017/rapps/reactos/sdk/include/reactos/atlex/atlwin.h (added)
+++ branches/GSoC_2017/rapps/reactos/sdk/include/reactos/atlex/atlwin.h [iso-8859-1] Tue
Jul 11 22:08:48 2017
@@ -0,0 +1,623 @@
+/*
+ Copyright 1991-2017 Amebis
+
+ This file is part of atlex.
+
+ 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 <http://www.gnu.org/licenses/>.
+*/
+
+#pragma once
+
+#include "atlex.h"
+#include <atlcoll.h>
+#include <atlstr.h>
+#include <Windows.h>
+
+///
+/// \defgroup ATLWinAPI Windows API
+/// Integrates ATL classes with Microsoft Windows API
+///
+/// @{
+
+///
+/// Retrieves the fully qualified path for the file that contains the specified module
and stores it in a ATL::CAtlStringA string.
+///
+/// \sa [GetModuleFileName
function](https://msdn.microsoft.com/en-us/library/windows/desktop/ms683197…
+///
+inline DWORD GetModuleFileNameA(_In_opt_ HMODULE hModule, _Out_ ATL::CAtlStringA
&sValue)
+{
+ DWORD dwSize = 0;
+
+ for (;;) {
+ // Increment size and allocate buffer.
+ LPSTR szBuffer = sValue.GetBuffer(dwSize += 1024);
+ if (!szBuffer) {
+ ::SetLastError(ERROR_OUTOFMEMORY);
+ return 0;
+ }
+
+ // Try!
+ DWORD dwResult = ::GetModuleFileNameA(hModule, szBuffer, dwSize);
+ if (dwResult == 0) {
+ // Error.
+ sValue.ReleaseBuffer(0);
+ return 0;
+ } else if (dwResult < dwSize) {
+ DWORD dwLength = (DWORD)strnlen(szBuffer, dwSize);
+ sValue.ReleaseBuffer(dwLength++);
+ if (dwLength == dwSize) {
+ // Buffer was long exactly enough.
+ return dwResult;
+ } if (dwLength < dwSize) {
+ // Buffer was long enough to get entire string, and has some extra space
left.
+ sValue.FreeExtra();
+ return dwResult;
+ }
+ }
+ }
+}
+
+
+///
+/// Retrieves the fully qualified path for the file that contains the specified module
and stores it in a ATL::CAtlStringW string.
+///
+/// \sa [GetModuleFileName
function](https://msdn.microsoft.com/en-us/library/windows/desktop/ms683197…
+///
+inline DWORD GetModuleFileNameW(_In_opt_ HMODULE hModule, _Out_ ATL::CAtlStringW
&sValue)
+{
+ DWORD dwSize = 0;
+
+ for (;;) {
+ // Increment size and allocate buffer.
+ LPWSTR szBuffer = sValue.GetBuffer(dwSize += 1024);
+ if (!szBuffer) {
+ ::SetLastError(ERROR_OUTOFMEMORY);
+ return 0;
+ }
+
+ // Try!
+ DWORD dwResult = ::GetModuleFileNameW(hModule, szBuffer, dwSize);
+ if (dwResult == 0) {
+ // Error.
+ sValue.ReleaseBuffer(0);
+ return 0;
+ } else if (dwResult < dwSize) {
+ DWORD dwLength = (DWORD)wcsnlen(szBuffer, dwSize);
+ sValue.ReleaseBuffer(dwLength++);
+ if (dwLength == dwSize) {
+ // Buffer was long exactly enough.
+ return dwResult;
+ } if (dwLength < dwSize) {
+ // Buffer was long enough to get entire string, and has some extra space
left.
+ sValue.FreeExtra();
+ return dwResult;
+ }
+ }
+ }
+}
+
+
+///
+/// Copies the text of the specified window's title bar (if it has one) into a
ATL::CAtlStringA string.
+///
+/// \sa [GetWindowText
function](https://msdn.microsoft.com/en-us/library/windows/desktop/ms633520…
+///
+inline int GetWindowTextA(_In_ HWND hWnd, _Out_ ATL::CAtlStringA &sValue)
+{
+ int iResult;
+
+ // Query the final string length first.
+ iResult = ::GetWindowTextLengthA(hWnd);
+ if (iResult > 0) {
+ // Allocate buffer on heap and read the string data into it.
+ LPSTR szBuffer = sValue.GetBuffer(iResult++);
+ if (!szBuffer) {
+ SetLastError(ERROR_OUTOFMEMORY);
+ return 0;
+ }
+ iResult = ::GetWindowTextA(hWnd, szBuffer, iResult);
+ sValue.ReleaseBuffer(iResult);
+ return iResult;
+ } else {
+ // The result is empty.
+ sValue.Empty();
+ return 0;
+ }
+}
+
+
+///
+/// Copies the text of the specified window's title bar (if it has one) into a
ATL::CAtlStringW string.
+///
+/// \sa [GetWindowText
function](https://msdn.microsoft.com/en-us/library/windows/desktop/ms633520…
+///
+inline int GetWindowTextW(_In_ HWND hWnd, _Out_ ATL::CAtlStringW &sValue)
+{
+ int iResult;
+
+ // Query the final string length first.
+ iResult = ::GetWindowTextLengthW(hWnd);
+ if (iResult > 0) {
+ // Allocate buffer on heap and read the string data into it.
+ LPWSTR szBuffer = sValue.GetBuffer(iResult++);
+ if (!szBuffer) {
+ SetLastError(ERROR_OUTOFMEMORY);
+ return 0;
+ }
+ iResult = ::GetWindowTextW(hWnd, szBuffer, iResult);
+ sValue.ReleaseBuffer(iResult);
+ return iResult;
+ } else {
+ // The result is empty.
+ sValue.Empty();
+ return 0;
+ }
+}
+
+
+///
+/// Retrieves version information for the specified file and stores it in a
ATL::CAtlStringA string.
+///
+/// \sa [GetFileVersionInfo
function](https://msdn.microsoft.com/en-us/library/windows/desktop/ms647003…
+///
+inline BOOL GetFileVersionInfoA(_In_ LPCSTR lptstrFilename, __reserved DWORD dwHandle,
_Out_ ATL::CAtlArray<BYTE> &aValue)
+{
+ // Get version info size.
+ DWORD dwVerInfoSize = ::GetFileVersionInfoSizeA(lptstrFilename, &dwHandle);
+ if (dwVerInfoSize != 0) {
+ if (aValue.SetCount(dwVerInfoSize)) {
+ // Read version info.
+ return ::GetFileVersionInfoA(lptstrFilename, dwHandle, dwVerInfoSize,
aValue.GetData());
+ } else {
+ ::SetLastError(ERROR_OUTOFMEMORY);
+ return FALSE;
+ }
+ } else
+ return FALSE;
+}
+
+
+///
+/// Retrieves version information for the specified file and stores it in a
ATL::CAtlStringW string.
+///
+/// \sa [GetFileVersionInfo
function](https://msdn.microsoft.com/en-us/library/windows/desktop/ms647003…
+///
+inline BOOL GetFileVersionInfoW(_In_ LPCWSTR lptstrFilename, __reserved DWORD dwHandle,
_Out_ ATL::CAtlArray<BYTE> &aValue)
+{
+ // Get version info size.
+ DWORD dwVerInfoSize = ::GetFileVersionInfoSizeW(lptstrFilename, &dwHandle);
+ if (dwVerInfoSize != 0) {
+ if (aValue.SetCount(dwVerInfoSize)) {
+ // Read version info.
+ return ::GetFileVersionInfoW(lptstrFilename, dwHandle, dwVerInfoSize,
aValue.GetData());
+ } else {
+ ::SetLastError(ERROR_OUTOFMEMORY);
+ return FALSE;
+ }
+ } else
+ return FALSE;
+}
+
+
+///
+/// Expands environment-variable strings, replaces them with the values defined for the
current user, and stores it in a ATL::CAtlStringA string.
+///
+/// \sa [ExpandEnvironmentStrings
function](https://msdn.microsoft.com/en-us/library/windows/desktop/ms724265…
+///
+inline DWORD ExpandEnvironmentStringsA(_In_ LPCSTR lpSrc, ATL::CAtlStringA &sValue)
+{
+ DWORD dwBufferSizeEst = (DWORD)strlen(lpSrc) + 0x100; // Initial estimate
+
+ for (;;) {
+ DWORD dwBufferSize = dwBufferSizeEst;
+ LPSTR szBuffer = sValue.GetBuffer(dwBufferSize);
+ if (!szBuffer) {
+ ::SetLastError(ERROR_OUTOFMEMORY);
+ return FALSE;
+ }
+ dwBufferSizeEst = ::ExpandEnvironmentStringsA(lpSrc, szBuffer, dwBufferSize);
+ if (dwBufferSizeEst > dwBufferSize) {
+ // The buffer was to small. Repeat with a bigger one.
+ sValue.ReleaseBuffer(0);
+ } else if (dwBufferSizeEst == 0) {
+ // Error.
+ sValue.ReleaseBuffer(0);
+ return 0;
+ } else {
+ // The buffer was sufficient. Break.
+ sValue.ReleaseBuffer();
+ sValue.FreeExtra();
+ return dwBufferSizeEst;
+ }
+ }
+}
+
+
+///
+/// Expands environment-variable strings, replaces them with the values defined for the
current user, and stores it in a ATL::CAtlStringW string.
+///
+/// \sa [ExpandEnvironmentStrings
function](https://msdn.microsoft.com/en-us/library/windows/desktop/ms724265…
+///
+inline DWORD ExpandEnvironmentStringsW(_In_ LPCWSTR lpSrc, ATL::CAtlStringW &sValue)
+{
+ DWORD dwBufferSizeEst = (DWORD)wcslen(lpSrc) + 0x100; // Initial estimate
+
+ for (;;) {
+ DWORD dwBufferSize = dwBufferSizeEst;
+ LPWSTR szBuffer = sValue.GetBuffer(dwBufferSize);
+ if (!szBuffer) {
+ ::SetLastError(ERROR_OUTOFMEMORY);
+ return FALSE;
+ }
+ dwBufferSizeEst = ::ExpandEnvironmentStringsW(lpSrc, szBuffer, dwBufferSize);
+ if (dwBufferSizeEst > dwBufferSize) {
+ // The buffer was to small. Repeat with a bigger one.
+ sValue.ReleaseBuffer(0);
+ } else if (dwBufferSizeEst == 0) {
+ // Error.
+ sValue.ReleaseBuffer(0);
+ return 0;
+ } else {
+ // The buffer was sufficient. Break.
+ sValue.ReleaseBuffer();
+ sValue.FreeExtra();
+ return dwBufferSizeEst;
+ }
+ }
+}
+
+
+///
+/// Formats GUID and stores it in a ATL::CAtlStringA string.
+///
+/// \param[in] lpGuid Pointer to GUID
+/// \param[out] str String to store the result to
+///
+inline VOID GuidToString(_In_ LPCGUID lpGuid, _Out_ ATL::CAtlStringA &str)
+{
+ str.Format("{%08X-%04X-%04X-%02X%02X-%02X%02X%02X%02X%02X%02X}",
+ lpGuid->Data1,
+ lpGuid->Data2,
+ lpGuid->Data3,
+ lpGuid->Data4[0], lpGuid->Data4[1],
+ lpGuid->Data4[2], lpGuid->Data4[3], lpGuid->Data4[4],
lpGuid->Data4[5], lpGuid->Data4[6], lpGuid->Data4[7]);
+}
+
+
+///
+/// Formats GUID and stores it in a ATL::CAtlStringW string.
+///
+/// \param[in] lpGuid Pointer to GUID
+/// \param[out] str String to store the result to
+///
+inline VOID GuidToString(_In_ LPCGUID lpGuid, _Out_ ATL::CAtlStringW &str)
+{
+ str.Format(L"{%08X-%04X-%04X-%02X%02X-%02X%02X%02X%02X%02X%02X}",
+ lpGuid->Data1,
+ lpGuid->Data2,
+ lpGuid->Data3,
+ lpGuid->Data4[0], lpGuid->Data4[1],
+ lpGuid->Data4[2], lpGuid->Data4[3], lpGuid->Data4[4],
lpGuid->Data4[5], lpGuid->Data4[6], lpGuid->Data4[7]);
+}
+
+
+///
+/// Queries for a string value in the registry and stores it in a ATL::CAtlStringA
string.
+///
+/// `REG_EXPAND_SZ` are expanded using `ExpandEnvironmentStrings()` before storing to
sValue.
+///
+/// \param[in] hReg A handle to an open registry key. The key must have been opened with
the KEY_QUERY_VALUE access right.
+/// \param[in] pszName The name of the registry value. If lpValueName is NULL or an empty
string, "", the function retrieves the type and data for the key's unnamed
or default value, if any.
+/// \param[out] sValue String to store the value to
+/// \return
+/// - `ERROR_SUCCESS` when query succeeds;
+/// - `ERROR_INVALID_DATA` when the registy value type is not `REG_SZ`, `REG_MULTI_SZ`,
or `REG_EXPAND_SZ`;
+/// - `ERROR_OUTOFMEMORY` when the memory allocation for the sValue buffer fails;
+/// - Error code when query fails. See `RegQueryValueEx()` for the list of error codes.
+/// \sa [RegQueryValueEx
function](https://msdn.microsoft.com/en-us/library/windows/desktop/ms724911…
+/// \sa [ExpandEnvironmentStrings
function](https://msdn.microsoft.com/en-us/library/windows/desktop/ms724265…
+///
+inline LSTATUS RegQueryStringValue(_In_ HKEY hReg, _In_z_ LPCSTR pszName, _Out_
ATL::CAtlStringA &sValue)
+{
+ LSTATUS lResult;
+ BYTE aStackBuffer[ATL_STACK_BUFFER_BYTES];
+ DWORD dwSize = sizeof(aStackBuffer), dwType;
+
+ // Try with stack buffer first.
+ lResult = ::RegQueryValueExA(hReg, pszName, NULL, &dwType, aStackBuffer,
&dwSize);
+ if (lResult == ERROR_SUCCESS) {
+ if (dwType == REG_SZ || dwType == REG_MULTI_SZ) {
+ // The value is REG_SZ or REG_MULTI_SZ. Allocate buffer on heap, copy from
stack buffer.
+ LPSTR szBuffer = sValue.GetBuffer(dwSize / sizeof(CHAR));
+ if (!szBuffer) return ERROR_OUTOFMEMORY;
+ memcpy(szBuffer, aStackBuffer, dwSize);
+ sValue.ReleaseBuffer();
+ } else if (dwType == REG_EXPAND_SZ) {
+ // The value is REG_EXPAND_SZ. Expand it from stack buffer.
+ if (::ExpandEnvironmentStringsA((const CHAR*)aStackBuffer, sValue) == 0)
+ lResult = ::GetLastError();
+ } else {
+ // The value is not a string type.
+ lResult = ERROR_INVALID_DATA;
+ }
+ } else if (lResult == ERROR_MORE_DATA) {
+ if (dwType == REG_SZ || dwType == REG_MULTI_SZ) {
+ // The value is REG_SZ or REG_MULTI_SZ. Read it now.
+ LPSTR szBuffer = sValue.GetBuffer(dwSize / sizeof(CHAR));
+ if (!szBuffer) return ERROR_OUTOFMEMORY;
+ if ((lResult = ::RegQueryValueExA(hReg, pszName, NULL, NULL,
(LPBYTE)szBuffer, &dwSize)) == ERROR_SUCCESS) {
+ sValue.ReleaseBuffer();
+ } else {
+ // Reading of the value failed.
+ sValue.ReleaseBuffer(0);
+ }
+ } else if (dwType == REG_EXPAND_SZ) {
+ // The value is REG_EXPAND_SZ. Read it and expand environment variables.
+ ATL::CTempBuffer<CHAR> sTemp(dwSize / sizeof(CHAR));
+ if ((lResult = ::RegQueryValueExA(hReg, pszName, NULL, NULL,
(LPBYTE)(CHAR*)sTemp, &dwSize)) == ERROR_SUCCESS)
+ if (::ExpandEnvironmentStringsA((const CHAR*)sTemp, sValue) == 0)
+ lResult = ::GetLastError();
+ } else {
+ // The value is not a string type.
+ lResult = ERROR_INVALID_DATA;
+ }
+ }
+
+ return lResult;
+}
+
+
+///
+/// Queries for a string value in the registry and stores it in a ATL::CAtlStringW
string.
+///
+/// `REG_EXPAND_SZ` are expanded using `ExpandEnvironmentStrings()` before storing to
sValue.
+///
+/// \param[in] hReg A handle to an open registry key. The key must have been opened with
the KEY_QUERY_VALUE access right.
+/// \param[in] pszName The name of the registry value. If lpValueName is NULL or an empty
string, "", the function retrieves the type and data for the key's unnamed
or default value, if any.
+/// \param[out] sValue String to store the value to
+/// \return
+/// - `ERROR_SUCCESS` when query succeeds;
+/// - `ERROR_INVALID_DATA` when the registy value type is not `REG_SZ`, `REG_MULTI_SZ`,
or `REG_EXPAND_SZ`;
+/// - `ERROR_OUTOFMEMORY` when the memory allocation for the sValue buffer fails;
+/// - Error code when query fails. See `RegQueryValueEx()` for the list of error codes.
+/// \sa [RegQueryValueEx
function](https://msdn.microsoft.com/en-us/library/windows/desktop/ms724911…
+/// \sa [ExpandEnvironmentStrings
function](https://msdn.microsoft.com/en-us/library/windows/desktop/ms724265…
+///
+inline LSTATUS RegQueryStringValue(_In_ HKEY hReg, _In_z_ LPCWSTR pszName, _Out_
ATL::CAtlStringW &sValue)
+{
+ LSTATUS lResult;
+ BYTE aStackBuffer[ATL_STACK_BUFFER_BYTES];
+ DWORD dwSize = sizeof(aStackBuffer), dwType;
+
+ // Try with stack buffer first.
+ lResult = ::RegQueryValueExW(hReg, pszName, NULL, &dwType, aStackBuffer,
&dwSize);
+ if (lResult == ERROR_SUCCESS) {
+ if (dwType == REG_SZ || dwType == REG_MULTI_SZ) {
+ // The value is REG_SZ or REG_MULTI_SZ. Allocate buffer on heap, copy from
stack buffer.
+ LPWSTR szBuffer = sValue.GetBuffer(dwSize / sizeof(WCHAR));
+ if (!szBuffer) return ERROR_OUTOFMEMORY;
+ memcpy(szBuffer, aStackBuffer, dwSize);
+ sValue.ReleaseBuffer();
+ } else if (dwType == REG_EXPAND_SZ) {
+ // The value is REG_EXPAND_SZ. Expand it from stack buffer.
+ if (::ExpandEnvironmentStringsW((const WCHAR*)aStackBuffer, sValue) == 0)
+ lResult = ::GetLastError();
+ } else {
+ // The value is not a string type.
+ lResult = ERROR_INVALID_DATA;
+ }
+ } else if (lResult == ERROR_MORE_DATA) {
+ if (dwType == REG_SZ || dwType == REG_MULTI_SZ) {
+ // The value is REG_SZ or REG_MULTI_SZ. Read it now.
+ LPWSTR szBuffer = sValue.GetBuffer(dwSize / sizeof(WCHAR));
+ if (!szBuffer) return ERROR_OUTOFMEMORY;
+ if ((lResult = ::RegQueryValueExW(hReg, pszName, NULL, NULL,
(LPBYTE)szBuffer, &dwSize)) == ERROR_SUCCESS) {
+ sValue.ReleaseBuffer();
+ } else {
+ // Reading of the value failed.
+ sValue.ReleaseBuffer(0);
+ }
+ } else if (dwType == REG_EXPAND_SZ) {
+ // The value is REG_EXPAND_SZ. Read it and expand environment variables.
+ ATL::CTempBuffer<WCHAR> sTemp(dwSize / sizeof(WCHAR));
+ if ((lResult = ::RegQueryValueExW(hReg, pszName, NULL, NULL,
(LPBYTE)(WCHAR*)sTemp, &dwSize)) == ERROR_SUCCESS)
+ if (::ExpandEnvironmentStringsW((const WCHAR*)sTemp, sValue) == 0)
+ lResult = ::GetLastError();
+ } else {
+ // The value is not a string type.
+ lResult = ERROR_INVALID_DATA;
+ }
+ }
+
+ return lResult;
+}
+
+
+///
+/// Retrieves the type and data for the specified value name associated with an open
registry key and stores the data in a ATL::CAtlArray<BYTE> buffer.
+///
+/// \sa [RegQueryValueEx
function](https://msdn.microsoft.com/en-us/library/windows/desktop/ms724911…
+///
+inline LSTATUS RegQueryValueExA(_In_ HKEY hKey, _In_opt_ LPCSTR lpValueName, __reserved
LPDWORD lpReserved, _Out_opt_ LPDWORD lpType, _Out_ ATL::CAtlArray<BYTE>
&aData)
+{
+ LSTATUS lResult;
+ BYTE aStackBuffer[ATL_STACK_BUFFER_BYTES];
+ DWORD dwSize = sizeof(aStackBuffer);
+
+ // Try with stack buffer first.
+ lResult = RegQueryValueExA(hKey, lpValueName, lpReserved, NULL, aStackBuffer,
&dwSize);
+ if (lResult == ERROR_SUCCESS) {
+ // Allocate buffer on heap, copy from stack buffer.
+ if (!aData.SetCount(dwSize)) return ERROR_OUTOFMEMORY;
+ memcpy(aData.GetData(), aStackBuffer, dwSize);
+ } else if (lResult == ERROR_MORE_DATA) {
+ // Allocate buffer on heap and retry.
+ if (!aData.SetCount(dwSize)) return ERROR_OUTOFMEMORY;
+ if ((lResult = RegQueryValueExA(hKey, lpValueName, lpReserved, lpType,
aData.GetData(), &dwSize)) != ERROR_SUCCESS)
+ aData.SetCount(0);
+ }
+
+ return lResult;
+}
+
+
+///
+/// Retrieves the type and data for the specified value name associated with an open
registry key and stores the data in a ATL::CAtlArray<BYTE> buffer.
+///
+/// \sa [RegQueryValueEx
function](https://msdn.microsoft.com/en-us/library/windows/desktop/ms724911…
+///
+inline LSTATUS RegQueryValueExW(_In_ HKEY hKey, _In_opt_ LPCWSTR lpValueName, __reserved
LPDWORD lpReserved, _Out_opt_ LPDWORD lpType, _Out_ ATL::CAtlArray<BYTE>
&aData)
+{
+ LSTATUS lResult;
+ BYTE aStackBuffer[ATL_STACK_BUFFER_BYTES];
+ DWORD dwSize = sizeof(aStackBuffer);
+
+ // Try with stack buffer first.
+ lResult = RegQueryValueExW(hKey, lpValueName, lpReserved, NULL, aStackBuffer,
&dwSize);
+ if (lResult == ERROR_SUCCESS) {
+ // Allocate buffer on heap, copy from stack buffer.
+ if (!aData.SetCount(dwSize)) return ERROR_OUTOFMEMORY;
+ memcpy(aData.GetData(), aStackBuffer, dwSize);
+ } else if (lResult == ERROR_MORE_DATA) {
+ // Allocate buffer on heap and retry.
+ if (!aData.SetCount(dwSize)) return ERROR_OUTOFMEMORY;
+ if ((lResult = RegQueryValueExW(hKey, lpValueName, lpReserved, lpType,
aData.GetData(), &dwSize)) != ERROR_SUCCESS)
+ aData.SetCount(0);
+ }
+
+ return lResult;
+}
+
+
+#if _WIN32_WINNT >= _WIN32_WINNT_VISTA
+
+///
+/// Loads the specified string from the specified key and subkey, and stores it in a
ATL::CAtlStringA string.
+///
+/// \sa [RegLoadMUIString
function](https://msdn.microsoft.com/en-us/library/windows/desktop/ms724890…
+///
+inline LSTATUS RegLoadMUIStringA(_In_ HKEY hKey, _In_opt_ LPCSTR pszValue, _Out_
ATL::CAtlStringA &sOut, _In_ DWORD Flags, _In_opt_ LPCSTR pszDirectory)
+{
+ LSTATUS lResult;
+ CHAR szStackBuffer[ATL_STACK_BUFFER_BYTES/sizeof(CHAR)];
+ DWORD dwSize;
+
+ Flags &= ~REG_MUI_STRING_TRUNCATE;
+
+ // Try with stack buffer first.
+ lResult = RegLoadMUIStringA(hKey, pszValue, szStackBuffer, _countof(szStackBuffer),
&dwSize, Flags, pszDirectory);
+ if (lResult == ERROR_SUCCESS) {
+ // Allocate buffer on heap, copy from stack buffer.
+ LPSTR szBuffer = sOut.GetBuffer(dwSize);
+ if (!szBuffer) return ERROR_OUTOFMEMORY;
+ memcpy(szBuffer, szStackBuffer, dwSize);
+ sOut.ReleaseBuffer(dwSize);
+ } else if (lResult == ERROR_MORE_DATA) {
+ // Allocate buffer on heap and retry.
+ LPSTR szBuffer = sOut.GetBuffer(dwSize);
+ if (!szBuffer) return ERROR_OUTOFMEMORY;
+ sOut.ReleaseBuffer((lResult = RegLoadMUIStringA(hKey, pszValue, szBuffer, dwSize,
&dwSize, Flags, pszDirectory)) == ERROR_SUCCESS ? dwSize : 0);
+ }
+
+ return lResult;
+}
+
+
+///
+/// Loads the specified string from the specified key and subkey, and stores it in a
ATL::CAtlStringW string.
+///
+/// \sa [RegLoadMUIString
function](https://msdn.microsoft.com/en-us/library/windows/desktop/ms724890…
+///
+inline LSTATUS RegLoadMUIStringW(_In_ HKEY hKey, _In_opt_ LPCWSTR pszValue, _Out_
ATL::CAtlStringW &sOut, _In_ DWORD Flags, _In_opt_ LPCWSTR pszDirectory)
+{
+ LSTATUS lResult;
+ WCHAR szStackBuffer[ATL_STACK_BUFFER_BYTES/sizeof(WCHAR)];
+ DWORD dwSize;
+
+ Flags &= ~REG_MUI_STRING_TRUNCATE;
+
+ // Try with stack buffer first.
+ lResult = RegLoadMUIStringW(hKey, pszValue, szStackBuffer, _countof(szStackBuffer),
&dwSize, Flags, pszDirectory);
+ if (lResult == ERROR_SUCCESS) {
+ // Allocate buffer on heap, copy from stack buffer.
+ LPWSTR szBuffer = sOut.GetBuffer(dwSize);
+ if (!szBuffer) return ERROR_OUTOFMEMORY;
+ wmemcpy(szBuffer, szStackBuffer, dwSize);
+ sOut.ReleaseBuffer(dwSize);
+ } else if (lResult == ERROR_MORE_DATA) {
+ // Allocate buffer on heap and retry.
+ LPWSTR szBuffer = sOut.GetBuffer(dwSize);
+ if (!szBuffer) return ERROR_OUTOFMEMORY;
+ sOut.ReleaseBuffer((lResult = RegLoadMUIStringW(hKey, pszValue, szBuffer, dwSize,
&dwSize, Flags, pszDirectory)) == ERROR_SUCCESS ? dwSize : 0);
+ }
+
+ return lResult;
+}
+
+#endif
+
+/// @}
+
+
+namespace ATL
+{
+ /// \addtogroup ATLWinAPI
+ /// @{
+
+ ///
+ /// Module handle wrapper
+ ///
+ class CAtlLibrary : public CObjectWithHandleT<HMODULE>
+ {
+ public:
+ ///
+ /// Frees the module.
+ ///
+ /// \sa
[
FreeLibrary](https://msdn.microsoft.com/en-us/library/windows/desktop/ms683…
+ ///
+ virtual ~CAtlLibrary()
+ {
+ if (m_h)
+ FreeLibrary(m_h);
+ }
+
+ ///
+ /// Loads the specified module into the address space of the calling process.
+ ///
+ /// \sa
[
LoadLibraryEx](https://msdn.microsoft.com/en-us/library/windows/desktop/ms6…
+ ///
+ inline BOOL Load(_In_ LPCTSTR lpFileName, __reserved HANDLE hFile, _In_ DWORD
dwFlags)
+ {
+ HANDLE h = LoadLibraryEx(lpFileName, hFile, dwFlags);
+ if (h) {
+ Attach(h);
+ return TRUE;
+ } else
+ return FALSE;
+ }
+
+ protected:
+ ///
+ /// Frees the module.
+ ///
+ /// \sa
[
FreeLibrary](https://msdn.microsoft.com/en-us/library/windows/desktop/ms683…
+ ///
+ virtual void InternalFree()
+ {
+ FreeLibrary(m_h);
+ }
+ };
+
+ /// @}
+}
Propchange: branches/GSoC_2017/rapps/reactos/sdk/include/reactos/atlex/atlwin.h
------------------------------------------------------------------------------
svn:eol-style = native
Added: branches/GSoC_2017/rapps/reactos/sdk/include/reactos/atlex/atlwlan.h
URL:
http://svn.reactos.org/svn/reactos/branches/GSoC_2017/rapps/reactos/sdk/inc…
==============================================================================
--- branches/GSoC_2017/rapps/reactos/sdk/include/reactos/atlex/atlwlan.h (added)
+++ branches/GSoC_2017/rapps/reactos/sdk/include/reactos/atlex/atlwlan.h [iso-8859-1] Tue
Jul 11 22:08:48 2017
@@ -0,0 +1,79 @@
+/*
+ Copyright 1991-2017 Amebis
+
+ This file is part of atlex.
+
+ 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 <http://www.gnu.org/licenses/>.
+*/
+
+#pragma once
+
+#include <atlstr.h>
+#include <wlanapi.h>
+
+
+// Must not statically link to Wlanapi.dll as it is not available on Windows
+// without a WLAN interface.
+extern DWORD (WINAPI *pfnWlanReasonCodeToString)(__in DWORD dwReasonCode, __in DWORD
dwBufferSize, __in_ecount(dwBufferSize) PWCHAR pStringBuffer, __reserved PVOID
pReserved);
+
+
+///
+/// \defgroup ATLWLANAPI WLAN API
+/// Integrates ATL classes with Microsoft WLAN API
+///
+/// @{
+
+///
+/// Retrieves a string that describes a specified reason code and stores it in a
ATL::CAtlStringW string.
+///
+/// \sa [WlanReasonCodeToString
function](https://msdn.microsoft.com/en-us/library/windows/desktop/ms706768…
+///
+/// \note
+/// Since Wlanapi.dll is not always present, the \c pfnWlanReasonCodeToString pointer to
\c WlanReasonCodeToString
+/// function must be loaded dynamically.
+///
+inline DWORD WlanReasonCodeToString(_In_ DWORD dwReasonCode, _Out_ ATL::CAtlStringW
&sValue, __reserved PVOID pReserved)
+{
+ DWORD dwSize = 0;
+
+ if (!::pfnWlanReasonCodeToString)
+ return ERROR_CALL_NOT_IMPLEMENTED;
+
+ for (;;) {
+ // Increment size and allocate buffer.
+ LPWSTR szBuffer = sValue.GetBuffer(dwSize += 1024);
+ if (!szBuffer) return ERROR_OUTOFMEMORY;
+
+ // Try!
+ DWORD dwResult = ::pfnWlanReasonCodeToString(dwReasonCode, dwSize, szBuffer,
pReserved);
+ if (dwResult == NO_ERROR) {
+ DWORD dwLength = (DWORD)wcsnlen(szBuffer, dwSize);
+ sValue.ReleaseBuffer(dwLength++);
+ if (dwLength == dwSize) {
+ // Buffer was long exactly enough.
+ return NO_ERROR;
+ } else if (dwLength < dwSize) {
+ // Buffer was long enough to get entire string, and has some extra space
left.
+ sValue.FreeExtra();
+ return NO_ERROR;
+ }
+ } else {
+ // Return error code.
+ sValue.ReleaseBuffer(0);
+ return dwResult;
+ }
+ }
+}
+
+/// @}
Propchange: branches/GSoC_2017/rapps/reactos/sdk/include/reactos/atlex/atlwlan.h
------------------------------------------------------------------------------
svn:eol-style = native