FiveTech Support Forums

FiveWin / Harbour / xBase community
Board index FiveWin for Harbour/xHarbour Checking GetLastError() from C
Posts: 44162
Joined: Thu Oct 06, 2005 05:47 PM
Checking GetLastError() from C
Posted: Sun Feb 06, 2022 08:42 AM
Sometimes we have the need to check the value that returns Windows GetLastError(), so this code is required:

Code (fw): Select all Collapse
void ShowErrorTxt( DWORD dwError )
{
   LPVOID lpMsgBuf;
   char buffer[ 6 ];

   FormatMessage( FORMAT_MESSAGE_ALLOCATE_BUFFER | FORMAT_MESSAGE_FROM_SYSTEM,
                  NULL,
                  dwError,
                  MAKELANGID( LANG_NEUTRAL, SUBLANG_DEFAULT ), // Default language
                  ( LPTSTR ) &lpMsgBuf,
                  0,
                  NULL );
   sprintf_s( buffer, "%i", dwError );
   MessageBox( 0, ( char * ) lpMsgBuf, buffer, 0 );               
   LocalFree( lpMsgBuf );
}


I post it here so it is usefull for all and I can find it next time :-)
regards, saludos

Antonio Linares
www.fivetechsoft.com

Continue the discussion