GetUserNameEx() wrapper added.
This commit is contained in:
@@ -107,6 +107,7 @@
|
||||
<ClInclude Include="atleap.h" />
|
||||
<ClInclude Include="atlex.h" />
|
||||
<ClInclude Include="atlmsi.h" />
|
||||
<ClInclude Include="atlsec.h" />
|
||||
<ClInclude Include="atlshlwapi.h" />
|
||||
<ClInclude Include="atlwin.h" />
|
||||
<ClInclude Include="atlwlan.h" />
|
||||
|
@@ -40,5 +40,8 @@
|
||||
<ClInclude Include="atleap.h">
|
||||
<Filter>Header Files</Filter>
|
||||
</ClInclude>
|
||||
<ClInclude Include="atlsec.h">
|
||||
<Filter>Header Files</Filter>
|
||||
</ClInclude>
|
||||
</ItemGroup>
|
||||
</Project>
|
84
atlsec.h
Normal file
84
atlsec.h
Normal file
@@ -0,0 +1,84 @@
|
||||
/*
|
||||
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/>.
|
||||
*/
|
||||
|
||||
#include <Security.h>
|
||||
|
||||
|
||||
BOOLEAN GetUserNameExA(__in EXTENDED_NAME_FORMAT NameFormat, __out ATL::CAtlStringA &sName)
|
||||
{
|
||||
ULONG ulSize = 0;
|
||||
|
||||
// Query the final string length first.
|
||||
if (!::GetUserNameExA(NameFormat, NULL, &ulSize)) {
|
||||
if (::GetLastError() == ERROR_MORE_DATA) {
|
||||
// Prepare the buffer 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;
|
||||
}
|
||||
} else {
|
||||
// The result is empty.
|
||||
sName.Empty();
|
||||
return NO_ERROR;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
BOOLEAN GetUserNameExW(__in EXTENDED_NAME_FORMAT NameFormat, __out ATL::CAtlStringW &sName)
|
||||
{
|
||||
ULONG ulSize = 0;
|
||||
|
||||
// Query the final string length first.
|
||||
if (!::GetUserNameExW(NameFormat, NULL, &ulSize)) {
|
||||
if (::GetLastError() == ERROR_MORE_DATA) {
|
||||
// Prepare the buffer 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;
|
||||
}
|
||||
} else {
|
||||
// The result is empty.
|
||||
sName.Empty();
|
||||
return NO_ERROR;
|
||||
}
|
||||
}
|
@@ -32,7 +32,7 @@ inline BOOL PathCanonicalizeA(__out ATL::CAtlStringA &sValue, __in LPCSTR pszPat
|
||||
return FALSE;
|
||||
}
|
||||
BOOL bResult = ::PathCanonicalizeA(szBuffer, pszPath);
|
||||
sValue.ReleaseBuffer(bResult ? strnlen(szBuffer, MAX_PATH) : 0);
|
||||
sValue.ReleaseBuffer(bResult ? (int)strnlen(szBuffer, MAX_PATH) : 0);
|
||||
sValue.FreeExtra();
|
||||
return bResult;
|
||||
}
|
||||
@@ -47,7 +47,7 @@ inline BOOL PathCanonicalizeW(__out ATL::CAtlStringW &sValue, __in LPCWSTR pszPa
|
||||
return FALSE;
|
||||
}
|
||||
BOOL bResult = ::PathCanonicalizeW(szBuffer, pszPath);
|
||||
sValue.ReleaseBuffer(bResult ? wcsnlen(szBuffer, MAX_PATH) : 0);
|
||||
sValue.ReleaseBuffer(bResult ? (int)wcsnlen(szBuffer, MAX_PATH) : 0);
|
||||
sValue.FreeExtra();
|
||||
return bResult;
|
||||
}
|
||||
|
8
stdafx.h
8
stdafx.h
@@ -22,4 +22,12 @@
|
||||
#include "atlwin.h"
|
||||
|
||||
#include "atlcrypt.h"
|
||||
#include "atleap.h"
|
||||
#include "atlex.h"
|
||||
#include "atlmsi.h"
|
||||
#if defined(SECURITY_WIN32) || defined(SECURITY_KERNEL) || defined(SECURITY_MAC)
|
||||
#include "atlsec.h"
|
||||
#endif
|
||||
#include "atlshlwapi.h"
|
||||
#include "atlwin.h"
|
||||
#include "atlwlan.h"
|
||||
|
Reference in New Issue
Block a user