mirror of
https://port.numenaute.org/aleajactaest/khanat-opennel-code.git
synced 2024-11-17 21:11:39 +00:00
Changed: Reuse NLMISC::formatErrorMessage instead of native FormatMessage
This commit is contained in:
parent
b9851167d0
commit
00a57b43c5
4 changed files with 13 additions and 45 deletions
|
@ -685,10 +685,7 @@ bool killProgram(uint32 pid)
|
||||||
/*#elif defined(NL_OS_WINDOWS)
|
/*#elif defined(NL_OS_WINDOWS)
|
||||||
// it doesn't work because pid != handle and i don't know how to kill a pid or know the real handle of another service (not -1)
|
// it doesn't work because pid != handle and i don't know how to kill a pid or know the real handle of another service (not -1)
|
||||||
int res = TerminateProcess((HANDLE)pid, 888);
|
int res = TerminateProcess((HANDLE)pid, 888);
|
||||||
LPVOID lpMsgBuf;
|
|
||||||
FormatMessage(FORMAT_MESSAGE_ALLOCATE_BUFFER | FORMAT_MESSAGE_FROM_SYSTEM | FORMAT_MESSAGE_IGNORE_INSERTS, NULL, GetLastError(), MAKELANGID(LANG_NEUTRAL, SUBLANG_DEFAULT), (LPTSTR) &lpMsgBuf, 0, NULL);
|
|
||||||
nlwarning("Failed to kill '%d' err %d: '%s'", pid, GetLastError (), lpMsgBuf);
|
nlwarning("Failed to kill '%d' err %d: '%s'", pid, GetLastError (), lpMsgBuf);
|
||||||
LocalFree(lpMsgBuf);
|
|
||||||
return res != 0;
|
return res != 0;
|
||||||
*/
|
*/
|
||||||
#else
|
#else
|
||||||
|
@ -758,11 +755,12 @@ bool launchProgram(const std::string &programName, const std::string &arguments,
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
LPVOID lpMsgBuf;
|
|
||||||
FormatMessage(FORMAT_MESSAGE_ALLOCATE_BUFFER | FORMAT_MESSAGE_FROM_SYSTEM | FORMAT_MESSAGE_IGNORE_INSERTS, NULL, GetLastError(), MAKELANGID(LANG_NEUTRAL, SUBLANG_DEFAULT), (LPTSTR) &lpMsgBuf, 0, NULL);
|
|
||||||
if (log)
|
if (log)
|
||||||
nlwarning("LAUNCH: Failed launched '%s' with arg '%s' err %d: '%s'", programName.c_str(), arguments.c_str(), GetLastError(), lpMsgBuf);
|
{
|
||||||
LocalFree(lpMsgBuf);
|
sint lastError = getLastError();
|
||||||
|
nlwarning("LAUNCH: Failed launched '%s' with arg '%s' err %d: '%s'", programName.c_str(), arguments.c_str(), lastError, formatErrorMessage(lastError).c_str());
|
||||||
|
}
|
||||||
|
|
||||||
CloseHandle( pi.hProcess );
|
CloseHandle( pi.hProcess );
|
||||||
CloseHandle( pi.hThread );
|
CloseHandle( pi.hThread );
|
||||||
}
|
}
|
||||||
|
@ -920,13 +918,11 @@ sint launchProgramAndWaitForResult(const std::string &programName, const std::st
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
LPVOID lpMsgBuf;
|
|
||||||
FormatMessage(FORMAT_MESSAGE_ALLOCATE_BUFFER | FORMAT_MESSAGE_FROM_SYSTEM | FORMAT_MESSAGE_IGNORE_INSERTS, NULL, GetLastError(), MAKELANGID(LANG_NEUTRAL, SUBLANG_DEFAULT), (LPTSTR) &lpMsgBuf, 0, NULL);
|
|
||||||
|
|
||||||
if (log)
|
if (log)
|
||||||
nlwarning("LAUNCH: Failed launched '%s' with arg '%s' err %d: '%s'", programName.c_str(), arguments.c_str(), GetLastError(), lpMsgBuf);
|
{
|
||||||
|
sint lastError = getLastError();
|
||||||
LocalFree(lpMsgBuf);
|
nlwarning("LAUNCH: Failed launched '%s' with arg '%s' err %d: '%s'", programName.c_str(), arguments.c_str(), lastError, formatErrorMessage(lastError).c_str());
|
||||||
|
}
|
||||||
|
|
||||||
CloseHandle(pi.hProcess);
|
CloseHandle(pi.hProcess);
|
||||||
CloseHandle(pi.hThread);
|
CloseHandle(pi.hThread);
|
||||||
|
|
|
@ -81,11 +81,7 @@ inline void LeaveMutex( void *handle )
|
||||||
{
|
{
|
||||||
if (ReleaseMutex(handle) == 0)
|
if (ReleaseMutex(handle) == 0)
|
||||||
{
|
{
|
||||||
//LPVOID lpMsgBuf;
|
|
||||||
//FormatMessage( FORMAT_MESSAGE_ALLOCATE_BUFFER | FORMAT_MESSAGE_FROM_SYSTEM | FORMAT_MESSAGE_IGNORE_INSERTS,
|
|
||||||
// NULL, GetLastError(), MAKELANGID(LANG_NEUTRAL, SUBLANG_DEFAULT), (LPTSTR) &lpMsgBuf, 0, NULL );*/
|
|
||||||
nlerror ("error while releasing the mutex (0x%x %d), %p", GetLastError(), GetLastError(), handle);
|
nlerror ("error while releasing the mutex (0x%x %d), %p", GetLastError(), GetLastError(), handle);
|
||||||
//LocalFree( lpMsgBuf );
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -2358,23 +2358,13 @@ static bool CopyMoveFile(const std::string &dest, const std::string &src, bool c
|
||||||
#ifdef NL_OS_WINDOWS
|
#ifdef NL_OS_WINDOWS
|
||||||
if (MoveFile(ssrc.c_str(), sdest.c_str()) == 0)
|
if (MoveFile(ssrc.c_str(), sdest.c_str()) == 0)
|
||||||
{
|
{
|
||||||
LPVOID lpMsgBuf;
|
sint lastError = NLMISC::getLastError();
|
||||||
FormatMessage(FORMAT_MESSAGE_ALLOCATE_BUFFER |
|
|
||||||
FORMAT_MESSAGE_FROM_SYSTEM |
|
|
||||||
FORMAT_MESSAGE_IGNORE_INSERTS,
|
|
||||||
NULL,
|
|
||||||
GetLastError(),
|
|
||||||
MAKELANGID(LANG_NEUTRAL, SUBLANG_DEFAULT), // Default language
|
|
||||||
(LPTSTR) &lpMsgBuf,
|
|
||||||
0,
|
|
||||||
NULL );
|
|
||||||
nlwarning ("PATH: CopyMoveFile error: can't link/move '%s' into '%s', error %u (%s)",
|
nlwarning ("PATH: CopyMoveFile error: can't link/move '%s' into '%s', error %u (%s)",
|
||||||
ssrc.c_str(),
|
ssrc.c_str(),
|
||||||
sdest.c_str(),
|
sdest.c_str(),
|
||||||
GetLastError(),
|
lastError,
|
||||||
lpMsgBuf);
|
NLMISC::formatErrorMessage(lastError).c_str());
|
||||||
|
|
||||||
LocalFree(lpMsgBuf);
|
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
#else
|
#else
|
||||||
|
|
|
@ -411,21 +411,7 @@ typedef HRESULT (WINAPI* LPCREATEDXGIFACTORY)(REFIID, void**);
|
||||||
|
|
||||||
static std::string FormatError(HRESULT hr)
|
static std::string FormatError(HRESULT hr)
|
||||||
{
|
{
|
||||||
std::string res;
|
return NLMISC::toString("%s (0x%x)", formatErrorMessage(hr).c_str(), hr);
|
||||||
|
|
||||||
LPTSTR errorText = NULL;
|
|
||||||
|
|
||||||
FormatMessage(FORMAT_MESSAGE_FROM_SYSTEM|FORMAT_MESSAGE_ALLOCATE_BUFFER|FORMAT_MESSAGE_IGNORE_INSERTS,
|
|
||||||
NULL, hr, MAKELANGID(LANG_NEUTRAL, SUBLANG_DEFAULT), (LPTSTR)&errorText, 0, NULL);
|
|
||||||
|
|
||||||
if (errorText)
|
|
||||||
{
|
|
||||||
res = NLMISC::toString("%s (0x%x)", errorText, hr);
|
|
||||||
LocalFree(errorText);
|
|
||||||
errorText = NULL;
|
|
||||||
}
|
|
||||||
|
|
||||||
return res;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
struct SAdapter
|
struct SAdapter
|
||||||
|
|
Loading…
Reference in a new issue