Added support for:
GetModuleFileName() GetFileVersionInfo() PathCanonicalize() Aesthetic modifications
This commit is contained in:
@@ -105,6 +105,7 @@
|
||||
<ItemGroup>
|
||||
<ClInclude Include="atlcrypt.h" />
|
||||
<ClInclude Include="atlmsi.h" />
|
||||
<ClInclude Include="atlshlwapi.h" />
|
||||
<ClInclude Include="atlwin.h" />
|
||||
<ClInclude Include="atlwlan.h" />
|
||||
<ClInclude Include="stdafx.h" />
|
||||
|
||||
@@ -31,5 +31,8 @@
|
||||
<ClInclude Include="atlwlan.h">
|
||||
<Filter>Header Files</Filter>
|
||||
</ClInclude>
|
||||
<ClInclude Include="atlshlwapi.h">
|
||||
<Filter>Header Files</Filter>
|
||||
</ClInclude>
|
||||
</ItemGroup>
|
||||
</Project>
|
||||
53
atlshlwapi.h
Normal file
53
atlshlwapi.h
Normal file
@@ -0,0 +1,53 @@
|
||||
/*
|
||||
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 <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
#pragma once
|
||||
|
||||
#include <atlstr.h>
|
||||
#include <Shlwapi.h>
|
||||
|
||||
|
||||
inline BOOL PathCanonicalizeA(__out ATL::CAtlStringA &sValue, __in LPCSTR pszPath)
|
||||
{
|
||||
// Prepare the buffer data 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 ? strnlen(szBuffer, MAX_PATH) : 0);
|
||||
sValue.FreeExtra();
|
||||
return bResult;
|
||||
}
|
||||
|
||||
|
||||
inline BOOL PathCanonicalizeW(__out ATL::CAtlStringW &sValue, __in LPCWSTR pszPath)
|
||||
{
|
||||
// Prepare the buffer data 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 ? wcsnlen(szBuffer, MAX_PATH) : 0);
|
||||
sValue.FreeExtra();
|
||||
return bResult;
|
||||
}
|
||||
103
atlwin.h
103
atlwin.h
@@ -19,10 +19,79 @@
|
||||
|
||||
#pragma once
|
||||
|
||||
#include <atlcoll.h>
|
||||
#include <atlstr.h>
|
||||
#include <Windows.h>
|
||||
|
||||
|
||||
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;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
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;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
inline int GetWindowTextA(__in HWND hWnd, __out ATL::CAtlStringA &sValue)
|
||||
{
|
||||
int iResult;
|
||||
@@ -65,6 +134,40 @@ inline int GetWindowTextW(__in HWND hWnd, __out ATL::CAtlStringW &sValue)
|
||||
}
|
||||
|
||||
|
||||
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;
|
||||
}
|
||||
|
||||
|
||||
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;
|
||||
}
|
||||
|
||||
|
||||
inline BOOL RegQueryStringValue(_In_ HKEY hReg, _In_z_ LPCSTR pszName, _Inout_ ATL::CAtlStringA &sValue)
|
||||
{
|
||||
DWORD dwSize = 0;
|
||||
|
||||
@@ -36,9 +36,12 @@ inline DWORD WlanReasonCodeToString(__in DWORD dwReasonCode, __out ATL::CAtlStri
|
||||
DWORD dwResult = ::WlanReasonCodeToString(dwReasonCode, dwSize, szBuffer, pReserved);
|
||||
if (dwResult == NO_ERROR) {
|
||||
DWORD dwLength = (DWORD)wcsnlen(szBuffer, dwSize);
|
||||
sValue.ReleaseBuffer(dwLength);
|
||||
if (dwLength < dwSize - 1) {
|
||||
// Buffer was long enough to get entire string.
|
||||
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;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user