Checking GetLastError() from C

Checking GetLastError() from C

Postby Antonio Linares » Sun Feb 06, 2022 8:42 am

Sometimes we have the need to check the value that returns Windows GetLastError(), so this code is required:

Code: Select all  Expand view  RUN
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
User avatar
Antonio Linares
Site Admin
 
Posts: 42100
Joined: Thu Oct 06, 2005 5:47 pm
Location: Spain

Return to FiveWin for Harbour/xHarbour

Who is online

Users browsing this forum: Google [Bot], Silvio.Falconi and 110 guests