#include "Precompiled.h"
#include "SharedIncludes.h"
#include "HelpersRT.h"
//==================================================================================================
/*
class X
{
public:
   X() { wprintf( L"* X-construction ...\r\n" ); }
   ~X() { wprintf( L"* X-destruction ...\r\n" ); }
};
*/
int wmain(int argc,WCHAR *argv[],WCHAR *envp[])
{
   wprintf( L"=== RTLibTest: ===\n" );
//$RT::SpecifyDefaultModuleName( L"RTLibTest.exe" );
//$FatalError::Raise($, L"Artificial error at start." );
/*
   setlocale( LC_ALL, "" );
   //wprintf( L"%s\n", $LE::Message().T($) );
   //$DynText exeName($, L"RTLibTest.exe" );
   //auto exeName = $RootInfo::GetExeName();
   //wprintf( L"Executable module: “%s”.\n", $_( exeName.T($), L"???" ) );
   wprintf( L"Executable module: “%s”.\n", $RootInfo::ExeName().T($) );
   auto message = $DynText::Format($, L"System Ticks = %u.", ::GetTickCount() );
   wprintf( L"%s\n", message.T($) );
   //$FatalError::Raise($, L"Artificial error has occured in the program." );
*/
   $RuntimeParameters rtParams;
   rtParams.Prepare($, L"RTLibTest.exe", "", true ); // LC_ALL="", AllowDesktopInteraction=true
   //rtParams.ModuleParameters.MainModuleName = L"RTLibTest.exe";
   //rtParams.IsNativeThreadStartForbiddenVCRT = true;
   $DynText errorMessage;
   if ( !$RT::Initialize($, rtParams, errorMessage ) )
   {
      setlocale( LC_ALL, "" );
      wprintf( L"%s\n", errorMessage.T($) );
      return -1;
   }
   //$FatalError::Raise($, L"Artificial error has occured in the program." );
   wprintf( L"%s\n", $LE::Message().T($) );
/*
   wprintf(
      L"0x%.8X\n"
      L"0x%.8X\n"
      L"0x%.8X\n",
      PRIMARYLANGID( rtParams.ThreadSettingsPattern.LanguageId ),
      PRIMARYLANGID( $Locale::GetLanguageId() ), 
      LANG_RUSSIAN );
*/
   //::MessageBox( nullptr, $LE::Message().T($), $RT::ModuleName($), MB_ICONERROR );
   $LE::SetError( L"User error message." );
   wprintf( L"%s\n", $LE::Message().T($) );
   $LE::ResetError();
   wprintf( L"%s\n", $LE::Message().T($) );
   $RT::Finalize();
   wprintf( L"%s\n", $LE::Message().T($) );
   //$FatalError::Raise($, L"Artificial error of the program." );
   wprintf( L"Memory allocation test (new-array alloc.-n-delete):\n" );
   const int arrayLen = 100;
   //int arrayLen = -1; // (SIZE_T)arrayLen > INT_MAX // wrong array length (error test)
   int *pNumbers = new int[ arrayLen ]; // RTFS-allocator (std::malloc/_malloc_dbg)
   for (int i=0; i<arrayLen; i++)
      pNumbers[ i ] = (i+1)*2;
   for (int i=0; i<arrayLen; i++)
      wprintf( L"%d ", pNumbers[ i ] );
   wprintf( L"\n" );
   //pNumbers = nullptr; // null argument for disposer (error test)
   delete[] pNumbers; // RTFS-disposer (std::free/_free_dbg)
   wprintf( L"=== DONE. ===\n" );
   return 0;
}

//==================================================================================================
//--------------------------------------------------------------------------------------------------
//==================================================================================================
