// NativeLib DLL (for DotNetHelpers) | C+- (SysRoutine) | Author: Sergei Y.Kitáev
#include "Precompiled.h"
#include "SharedIncludes.h"
namespace NativeLib {
//==================================================================================================

bool NLFailure::SetErrorFmtVA($A, PCWSTR messageFmt, va_list argList )
{
   return SetErrorFmtVA($ci, NLErrorCat_General, 0, 0, messageFmt, argList );
}
bool NLFailure::SetErrorFmtVA($A, INT code $optional,
                                  PCWSTR messageFmt, va_list argList ) $ret_false
{
   return SetErrorFmtVA($ci, NLErrorCat_General, code, 0, messageFmt, argList );
}
bool NLFailure::SetErrorFmtVA($A, UINT uCode $optional,
                                  PCWSTR messageFmt, va_list argList ) $ret_false
{
   return SetErrorFmtVA($ci, NLErrorCat_General, uCode, 0, messageFmt, argList );
}
bool NLFailure::SetErrorFmtVA($A, INT code $optional, DWORD value $optional,
                                  PCWSTR messageFmt, va_list argList ) $ret_false
{
   return SetErrorFmtVA($ci, NLErrorCat_General, code, value, messageFmt, argList );
}
bool NLFailure::SetErrorFmtVA($A, UINT uCode $optional, DWORD value $optional,
                                  PCWSTR messageFmt, va_list argList ) $ret_false
{
   return SetErrorFmtVA($ci, NLErrorCat_General, uCode, value, messageFmt, argList );
}

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

bool NLFailure::SetErrorFmtVA($A, NLErrorCat category $optional,
                                  PCWSTR messageFmt, va_list argList ) $ret_false
{
   return SetErrorFmtVA($ci, category, 0, 0, messageFmt, argList );
}
bool NLFailure::SetErrorFmtVA($A, NLErrorCat category $optional, INT code $optional,
                                  PCWSTR messageFmt, va_list argList ) $ret_false
{
   return SetErrorFmtVA($ci, category, code, 0, messageFmt, argList );
}
bool NLFailure::SetErrorFmtVA($A, NLErrorCat category $optional, UINT uCode $optional,
                                  PCWSTR messageFmt, va_list argList ) $ret_false
{
   return SetErrorFmtVA($ci, category, uCode, 0, messageFmt, argList );
}
bool NLFailure::SetErrorFmtVA($A, NLErrorCat category $optional,
                                  INT code $optional, DWORD value $optional,
                                  PCWSTR messageFmt, va_list argList ) $ret_false
{
   return SetErrorFmtVA($ci, category, (UINT)code, value, messageFmt, argList );
}
bool NLFailure::SetErrorFmtVA($A, NLErrorCat category $optional,
                                  UINT uCode $optional, DWORD value $optional,
                                  PCWSTR messageFmt, va_list argList ) $ret_false
{
   $VERIFY_POINTER_ARG( messageFmt );
   $VERIFY_POINTER_ARG( argList );
   PWSTR pMessage = $SZ::FormatAllocVANS($ci,$, messageFmt, argList );
   if ( !pMessage )
      return SetFormatAllocFailure();
   NLError &data = *FreeErrorData();
   data.Category = category;
   data.MessagePtr = pMessage;
   data.IsAllocatedMsg = true;
   data.Code32 = uCode;
   data.Value32 = value;
   return false;
}

//==================================================================================================

bool NLFailure::SetArgumentErrorFmtVA($A, PCWSTR messageFmt, va_list argList ) $ret_false
{
   return SetErrorFmtVA($ci, NLErrorCat_Argument, messageFmt, argList );
}

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

bool NLFailure::SetSpecialErrorFmtVA($A, PCWSTR messageFmt, va_list argList )
{
   return SetSpecialErrorFmtVA($ci, 0, 0, messageFmt, argList );
}
bool NLFailure::SetSpecialErrorFmtVA($A, INT code $optional,
                                         PCWSTR messageFmt, va_list argList ) $ret_false
{
   return SetSpecialErrorFmtVA($ci, code, 0, messageFmt, argList );
}
bool NLFailure::SetSpecialErrorFmtVA($A, UINT uCode $optional,
                                         PCWSTR messageFmt, va_list argList ) $ret_false
{
   return SetSpecialErrorFmtVA($ci, uCode, 0, messageFmt, argList );
}
bool NLFailure::SetSpecialErrorFmtVA($A, INT code $optional, DWORD value $optional,
                                         PCWSTR messageFmt, va_list argList ) $ret_false
{
   return SetErrorFmtVA($ci, NLErrorCat_Special, code, value, messageFmt, argList );
}
bool NLFailure::SetSpecialErrorFmtVA($A, UINT uCode $optional, DWORD value $optional,
                                         PCWSTR messageFmt, va_list argList ) $ret_false
{
   return SetErrorFmtVA($ci, NLErrorCat_Special, uCode, value, messageFmt, argList );
}

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

bool NLFailure::SetSystemErrorFmtVA($A, PCWSTR messageFmt, va_list argList ) $ret_false
{
   return SetErrorFmtVA($ci, NLErrorCat_System, messageFmt, argList );
}

bool NLFailure::SetWin32ErrorFmtVA($A, DWORD dwError, PCWSTR headerMessageFmt,
                                                      va_list argList ) $ret_false
{
   $$VERIFY_POINTER_ARG( headerMessageFmt );
   PWSTR pHeaderMessage = $SZ::FormatAllocVANS($, headerMessageFmt, argList );
   $AUTO_FREE( pHeaderMessage );
   return pHeaderMessage ? SetSystemError( pHeaderMessage, dwError ) : SetFormatAllocFailure();
}

bool NLFailure::SetCOMErrorFmtVA($A, HRESULT hResult, PCWSTR headerMessageFmt,
                                                      va_list argList ) $ret_false
{
   $$VERIFY_POINTER_ARG( headerMessageFmt );
   PWSTR pHeaderMessage = $SZ::FormatAllocVANS($, headerMessageFmt, argList );
   $AUTO_FREE( pHeaderMessage );
   return pHeaderMessage ? SetCOMError( pHeaderMessage, hResult ) : SetFormatAllocFailure();
}

bool NLFailure::SetFromLastRTErrorFmtVA($A, PCWSTR headerMessageFmt, va_list argList ) $ret_false
{
   $$VERIFY_POINTER_ARG( headerMessageFmt );
   PWSTR pHeaderMessage = $SZ::FormatAllocVANS($, headerMessageFmt, argList );
   $AUTO_FREE( pHeaderMessage );
   return pHeaderMessage ? SetFromLastRTError( pHeaderMessage ) : SetFormatAllocFailure();
}

//==================================================================================================
} // NativeLib
