// RuntimeForStatic base library | C+- (SysRoutine) | Author: Sergei Y.Kitáev
#include "Precompiled.h"
#include "SharedIncludes.h"
#include "LE.internal.h"
namespace RuntimeForStatic {
//==================================================================================================

bool $LE::SetWin32Error(DWORD dwError) $ret_false
{
   return SetSystemError( nullptr, dwError );
}

//--------------------------------------------------------------------------------------------------

bool $LE::SetWin32Error($A, PCWSTR message ) $ret_false
{
   SetErrorEx( $ErrorSign::CreateWin32(), message );
   return $RESET_LAST_SYS_ERROR( false );
}

bool $LE::SetWin32ErrorFmt($A, PCWSTR messageFmt, ... ) $ret_false
{
   $$VERIFY_POINTER_ARG( messageFmt );
   va_list argList;
   SetWin32ErrorFmtVA($ci, $VA_COMPLEMENT( messageFmt, argList ) );
   va_end( argList );
   return false;
}
bool $LE::SetWin32ErrorFmtVA($A, PCWSTR messageFmt, va_list argList ) $ret_false
{
   SetErrorExFmtVA($ci, $ErrorSign::CreateWin32(), messageFmt, argList );
   return $RESET_LAST_SYS_ERROR( false );
}

//--------------------------------------------------------------------------------------------------

bool $LE::SetWin32Error( PCWSTR headerMessage $optional, DWORD dwError ) $ret_false
{
   return SetSystemError( headerMessage, dwError );
}
bool $LE::SetWin32ErrorFmt($A, DWORD dwError, PCWSTR headerMessageFmt, ... ) $ret_false
{
   $$VERIFY_POINTER_ARG( headerMessageFmt );
   va_list argList;
   SetWin32ErrorFmtVA($ci, dwError, $VA_COMPLEMENT( headerMessageFmt, argList ) );
   va_end( argList );
   return false;
}
bool $LE::SetWin32ErrorFmtVA($A, DWORD dwError, PCWSTR headerMessageFmt,
                                                va_list argList ) $ret_false
{
   $$VERIFY_POINTER_ARG( headerMessageFmt );
   PWSTR pHeaderMessage = HelpersRT::FormatAllocVA($, headerMessageFmt, argList );
   $AUTO_FREE( pHeaderMessage );
   return pHeaderMessage ? SetWin32Error( pHeaderMessage, dwError ) : SetFormatAllocFailure();
}

//--------------------------------------------------------------------------------------------------

bool $LE::SetWin32FuncFailure($A, PCWSTR functionName ) $ret_false
{
   $$VERIFY_POINTER_ARG( functionName );
   return SetWin32ErrorFmt($ci, $TEXT(
      L"Win32-function “%s” has failed.",
      L"Win32-функция “%s” потерпела неудачу." ),
      functionName );
}

//==================================================================================================
} // RuntimeForStatic
