Some fixes for AzCore

Signed-off-by: Esteban Papp <81431996+amznestebanpapp@users.noreply.github.com>
monroegm-disable-blank-issue-2
Esteban Papp 5 years ago
parent f21fc79dc4
commit b86349c3bf

@ -90,7 +90,7 @@ namespace AZ {
{
case CBA_EVENT:
evt = (PIMAGEHLP_CBA_EVENT)CallbackData;
_tprintf(_T("%s"), (PTSTR)evt->desc);
_tprintf(_T("%s"), evt->desc);
break;
default:
@ -300,7 +300,7 @@ namespace AZ {
return;
}
const HMODULE hNtDll = GetModuleHandle(_T("ntdll.dll"));
const HMODULE hNtDll = GetModuleHandleW(L"ntdll.dll");
m_LdrRegisterDllNotification = reinterpret_cast<PLDR_REGISTER_DLL_NOTIFICATION>(GetProcAddress(hNtDll, "LdrRegisterDllNotification"));
if (m_LdrRegisterDllNotification)
@ -324,7 +324,7 @@ namespace AZ {
return;
}
const HMODULE hNtDll = GetModuleHandle(_T("ntdll.dll"));
const HMODULE hNtDll = GetModuleHandleW(L"ntdll.dll");
m_LdrUnregisterDllNotification = reinterpret_cast<PLDR_UNREGISTER_DLL_NOTIFICATION>(GetProcAddress(hNtDll, "LdrUnregisterDllNotification"));
if (m_LdrUnregisterDllNotification)
@ -609,8 +609,8 @@ namespace AZ {
if (GetFileVersionInfoA(szImg, dwHandle, dwSize, vData) != 0)
{
UINT len;
TCHAR szSubBlock[] = _T("\\");
if (VerQueryValue(vData, szSubBlock, (LPVOID*) &fInfo, &len) == 0)
TCHAR szSubBlock[] = L"\\";
if (VerQueryValueW(vData, szSubBlock, (LPVOID*) &fInfo, &len) == 0)
{
fInfo = NULL;
}
@ -711,7 +711,7 @@ namespace AZ {
typedef BOOL (__stdcall * tM32N)(HANDLE hSnapshot, LPMODULEENTRY32 lpme);
// try both dlls...
const TCHAR* dllname[] = { _T("kernel32.dll"), _T("tlhelp32.dll") };
const TCHAR* dllname[] = { L"kernel32.dll", L"tlhelp32.dll" };
HINSTANCE hToolhelp = NULL;
tCT32S pCT32S = NULL;
tM32F pM32F = NULL;
@ -822,7 +822,7 @@ namespace AZ {
const SIZE_T TTBUFLEN = 8096;
int cnt = 0;
hPsapi = LoadLibrary(_T("psapi.dll"));
hPsapi = LoadLibraryW(L"psapi.dll");
if (hPsapi == NULL)
{
return FALSE;
@ -956,10 +956,10 @@ cleanup:
// In that scenario, we may try to load and older dbghelp.dll which could cause issues
// To overcome this, we try to load dbghelp.dll from the Win 10 SDK folder, if that doesn't
// work, load the default.
g_dbgHelpDll = LoadLibrary(_T(R"(C:\Program Files (x86)\Windows Kits\10\Debuggers\x64\dbghelp.dll)"));
g_dbgHelpDll = LoadLibraryW(LR"(C:\Program Files (x86)\Windows Kits\10\Debuggers\x64\dbghelp.dll)");
if (g_dbgHelpDll == NULL)
{
g_dbgHelpDll = LoadLibrary(_T("dbghelp.dll"));
g_dbgHelpDll = LoadLibrary(L"dbghelp.dll");
}
}
if (g_dbgHelpDll == NULL)

@ -16,6 +16,7 @@
#include <AzCore/std/typetraits/decay.h>
#include <AzCore/std/typetraits/is_unsigned.h>
#include <AzCore/StringFunc/StringFunc.h>
#include <AzCore/std/string/conversions.h>
namespace AZ::IO
{
@ -467,8 +468,10 @@ namespace AZ::IO
DWORD createFlags = m_constructionOptions.m_enableUnbufferedReads ? (FILE_FLAG_OVERLAPPED | FILE_FLAG_NO_BUFFERING) : FILE_FLAG_OVERLAPPED;
DWORD shareMode = (m_constructionOptions.m_enableSharing || data.m_sharedRead) ? FILE_SHARE_READ: 0;
file = ::CreateFile(
data.m_path.GetAbsolutePath(), // file name
AZStd::wstring filenameW;
AZStd::to_wstring(filenameW, data.m_path.GetAbsolutePath());
file = ::CreateFileW(
filenameW.c_str(), // file name
FILE_GENERIC_READ, // desired access
shareMode, // share mode
nullptr, // security attributes
@ -806,7 +809,9 @@ namespace AZ::IO
}
WIN32_FILE_ATTRIBUTE_DATA attributes;
if (::GetFileAttributesEx(fileExists.m_path.GetAbsolutePath(), GetFileExInfoStandard, &attributes))
AZStd::wstring filenameW;
AZStd::to_wstring(filenameW, fileExists.m_path.GetAbsolutePath());
if (::GetFileAttributesExW(filenameW.c_str(), GetFileExInfoStandard, &attributes))
{
if ((attributes.dwFileAttributes != INVALID_FILE_ATTRIBUTES) &&
((attributes.dwFileAttributes & FILE_ATTRIBUTE_DIRECTORY) == 0))
@ -863,7 +868,9 @@ namespace AZ::IO
else
{
WIN32_FILE_ATTRIBUTE_DATA attributes;
if (::GetFileAttributesEx(command.m_path.GetAbsolutePath(), GetFileExInfoStandard, &attributes) &&
AZStd::wstring filenameW;
AZStd::to_wstring(filenameW, command.m_path.GetAbsolutePath());
if (::GetFileAttributesExW(filenameW.c_str(), GetFileExInfoStandard, &attributes) &&
(attributes.dwFileAttributes != INVALID_FILE_ATTRIBUTES) && ((attributes.dwFileAttributes & FILE_ATTRIBUTE_DIRECTORY) == 0))
{
fileSize.LowPart = attributes.nFileSizeLow;

@ -10,6 +10,7 @@
#include <AzCore/IPC/SharedMemory.h>
#include <AzCore/std/parallel/spin_mutex.h>
#include <AzCore/std/string/conversions.h>
namespace AZ
{
@ -41,7 +42,9 @@ namespace AZ
SetSecurityDescriptorDacl(secAttr.lpSecurityDescriptor, TRUE, 0, FALSE);
// Obtain global mutex
m_globalMutex = CreateMutex(&secAttr, FALSE, fullName);
AZStd::wstring fullNameW;
AZStd::to_wstring(fullNameW, fullName);
m_globalMutex = CreateMutexW(&secAttr, FALSE, fullNameW.c_str());
DWORD error = GetLastError();
if (m_globalMutex == NULL || (error == ERROR_ALREADY_EXISTS && openIfCreated == false))
{
@ -51,7 +54,7 @@ namespace AZ
// Create the file mapping.
azsnprintf(fullName, AZ_ARRAY_SIZE(fullName), "%s_Data", name);
m_mapHandle = CreateFileMapping(INVALID_HANDLE_VALUE, &secAttr, PAGE_READWRITE, 0, size, fullName);
m_mapHandle = CreateFileMappingW(INVALID_HANDLE_VALUE, &secAttr, PAGE_READWRITE, 0, size, fullNameW.c_str());
error = GetLastError();
if (m_mapHandle == NULL || (error == ERROR_ALREADY_EXISTS && openIfCreated == false))
{
@ -66,8 +69,10 @@ namespace AZ
{
char fullName[256];
ComposeMutexName(fullName, AZ_ARRAY_SIZE(fullName), name);
AZStd::wstring fullNameW;
AZStd::to_wstring(fullNameW, fullName);
m_globalMutex = OpenMutex(SYNCHRONIZE, TRUE, fullName);
m_globalMutex = OpenMutex(SYNCHRONIZE, TRUE, fullNameW.c_str());
AZ_Warning("AZSystem", m_globalMutex != NULL, "Failed to open OS mutex [%s]\n", m_name);
if (m_globalMutex == NULL)
{
@ -76,7 +81,7 @@ namespace AZ
}
azsnprintf(fullName, AZ_ARRAY_SIZE(fullName), "%s_Data", name);
m_mapHandle = OpenFileMapping(FILE_MAP_WRITE, false, fullName);
m_mapHandle = OpenFileMapping(FILE_MAP_WRITE, false, fullNameW.c_str());
if (m_mapHandle == NULL)
{
AZ_TracePrintf("AZSystem", "OpenFileMapping %s failed with error %d\n", m_name, GetLastError());

@ -10,6 +10,7 @@
#include <AzCore/Math/MathUtils.h>
#include <AzCore/PlatformIncl.h>
#include <AzCore/std/string/conversions.h>
namespace
{
@ -105,11 +106,17 @@ namespace
{
// Set the text for window title, message, buttons.
info = (DlgInfo*)lParam;
SetWindowText(hDlg, info->m_title.c_str());
SetWindowText(GetDlgItem(hDlg, 0), info->m_message.c_str());
AZStd::wstring titleW;
AZStd::to_wstring(titleW, info->m_title.c_str());
SetWindowTextW(hDlg, titleW.c_str());
AZStd::wstring messageW;
AZStd::to_wstring(messageW, info->m_message.c_str());
SetWindowTextW(GetDlgItem(hDlg, 0), messageW.c_str());
for (int i = 0; i < info->m_options.size(); i++)
{
SetWindowText(GetDlgItem(hDlg, i + 1), info->m_options[i].c_str());
AZStd::wstring optionW;
AZStd::to_wstring(optionW, info->m_options[i].c_str());
SetWindowTextW(GetDlgItem(hDlg, i + 1), optionW.c_str());
}
}
break;

@ -37,7 +37,7 @@ namespace AZ
{
DWORD dataType = REG_SZ;
DWORD dataSize = sizeof(machineInfo);
ret = RegQueryValueEx(key, "MachineGuid", 0, &dataType, (LPBYTE)machineInfo, &dataSize);
ret = RegQueryValueExW(key, L"MachineGuid", 0, &dataType, (LPBYTE)machineInfo, &dataSize);
RegCloseKey(key);
}
else
@ -45,7 +45,7 @@ namespace AZ
AZ_Error("System", false, "Failed to open HKEY_LOCAL_MACHINE\\SOFTWARE\\Microsoft\\Cryptography\\MachineGuid!")
}
TCHAR* hostname = machineInfo + _tcslen(machineInfo);
TCHAR* hostname = machineInfo + wcslen(machineInfo);
// salt the guid time with ComputerName/UserName
DWORD bufCharCount = DWORD(sizeof(machineInfo) - (hostname - machineInfo));
if (!::GetComputerName(hostname, &bufCharCount))
@ -53,7 +53,7 @@ namespace AZ
AZ_Error("System", false, "GetComputerName filed with code %d", GetLastError());
}
TCHAR* username = hostname + _tcslen(hostname);
TCHAR* username = hostname + wcslen(hostname);
bufCharCount = DWORD(sizeof(machineInfo) - (username - machineInfo));
if( !GetUserName( username, &bufCharCount ) )
{
@ -62,7 +62,7 @@ namespace AZ
Sha1 hash;
AZ::u32 digest[5] = { 0 };
hash.ProcessBytes(machineInfo, _tcslen(machineInfo) * sizeof(TCHAR));
hash.ProcessBytes(machineInfo, wcslen(machineInfo) * sizeof(TCHAR));
hash.GetDigest(digest);
s_machineId = digest[0];
if (s_machineId == 0)

@ -8,6 +8,7 @@
#include <AzCore/Utils/Utils.h>
#include <AzCore/PlatformIncl.h>
#include <AzCore/std/string/conversions.h>
#include <stdlib.h>
@ -15,7 +16,11 @@ namespace AZ::Utils
{
void NativeErrorMessageBox(const char* title, const char* message)
{
::MessageBox(0, message, title, MB_OK | MB_ICONERROR);
AZStd::wstring wtitle;
AZStd::to_wstring(wtitle, title);
AZStd::wstring wmessage;
AZStd::to_wstring(wmessage, message);
::MessageBoxW(0, wmessage.c_str(), wtitle.c_str(), MB_OK | MB_ICONERROR);
}
AZ::IO::FixedMaxPathString GetHomeDirectory()

@ -8,6 +8,7 @@
#include <AzCore/PlatformIncl.h>
#include <AzCore/std/parallel/thread.h>
#include <AzCore/std/string/conversions.h>
#include <process.h>
@ -37,17 +38,20 @@ namespace AZStd
// SetThreadDescription was added in 1607 (aka RS1). Since we can't guarantee the user is running 1607 or later, we need to ask for the function from the kernel.
using SetThreadDescriptionFunc = HRESULT(WINAPI*)(_In_ HANDLE hThread, _In_ PCWSTR lpThreadDescription);
auto setThreadDescription = reinterpret_cast<SetThreadDescriptionFunc>(::GetProcAddress(::GetModuleHandle("Kernel32.dll"), "SetThreadDescription"));
if (setThreadDescription)
HMODULE kernel32Handle = ::GetModuleHandleW(L"Kernel32.dll");
if (kernel32Handle)
{
// Convert the thread name to Unicode
wchar_t threadNameW[MAX_PATH];
size_t numCharsConverted;
errno_t wcharResult = mbstowcs_s(&numCharsConverted, threadNameW, threadName, AZ_ARRAY_SIZE(threadNameW) - 1);
if (wcharResult == 0)
SetThreadDescriptionFunc setThreadDescription = reinterpret_cast<SetThreadDescriptionFunc>(::GetProcAddress(kernel32Handle, "SetThreadDescription"));
if (setThreadDescription)
{
setThreadDescription(hThread, threadNameW);
return true;
// Convert the thread name to Unicode
AZStd::wstring threadNameW;
AZStd::to_wstring(threadNameW, threadName);
if (!threadNameW.empty())
{
setThreadDescription(hThread, threadNameW.c_str());
return true;
}
}
}

Loading…
Cancel
Save