Click here to Skip to main content
15,884,810 members
Articles / Desktop Programming / MFC

The Win32 Foundation Classes (WFC) - Version 45

Rate me:
Please Sign up or sign in to vote.
4.93/5 (40 votes)
16 May 2000 467.9K   12.7K   280  
The Win32 Foundation Classes (WFC) are a library of C++ classes that extend Microsoft Foundation Classes (MFC) beyond mere GUI applications, and provide extensive support for system and NT specific applications
#include <wfc.h>
#pragma hdrstop

/*
** Author: Samuel R. Blackburn
** Internet: wfc@pobox.com
**
** You can use it any way you like as long as you don't try to sell it.
**
** Any attempt to sell WFC in source code form must have the permission
** of the original author. You can produce commercial executables with
** WFC but you can't sell WFC.
**
** Copyright, 2000, Samuel R. Blackburn
**
** $Workfile: wfc_get_error_string.cpp $
** $Revision: 11 $
** $Modtime: 1/17/00 9:33a $
** $Reuse Tracing Code: 1 $
*/

#if defined( _DEBUG ) && ! defined( WFC_STL )
#undef THIS_FILE
static char THIS_FILE[] = __FILE__;
#define new DEBUG_NEW
#endif // _DEBUG

void PASCAL wfc_get_error_string( DWORD error_code, CString& error_string )
{
   error_string.Empty();

   LPVOID message_buffer = NULL;

   ::FormatMessage( FORMAT_MESSAGE_ALLOCATE_BUFFER |
                    FORMAT_MESSAGE_FROM_SYSTEM |
                    FORMAT_MESSAGE_IGNORE_INSERTS,
                    NULL,
                    error_code,
                    MAKELANGID( LANG_NEUTRAL, SUBLANG_SYS_DEFAULT ),
          (LPTSTR) &message_buffer,
                    0,
                    NULL );

   error_string = (LPCTSTR) message_buffer;

   ::LocalFree( message_buffer );
   message_buffer = NULL;

   error_string.TrimRight();

   if ( error_string.GetLength() == 0 )
   {
      error_string.Format( TEXT( "Unknown System Error %lu" ), error_code );
   }
}

// End of source

#if 0
<HTML>

<HEAD>
<TITLE>WFC - wfc_get_error_string</TITLE>
<META name="keywords" content="WFC, MFC extension library, freeware class library, Win32">
<META name="description" content="Simple C function that converts error codes to something humanly readable.">
</HEAD>

<BODY>

<H1>wfc_get_error_string</H1>
$Revision: 11 $<HR>

<H2>Declaration</H2>
<PRE>void <B>wfc_get_error_string</B>( DWORD error_code, CString&amp; error_string )</PRE>

<H2>Description</H2>
This function takes a value returned from GetLastError() and formats 
it into something humanly readable.

<H2>Example</H2>
<PRE><CODE>void print_error( void )
{
   <A HREF="WfcTrace.htm">WFCTRACEINIT</A>( TEXT( &quot;print_error()&quot; ) );

   DWORD error_code = GetLastError();

   CString something_a_human_can_understand;

   <B>wfc_get_error_string</B>( error_code, something_a_human_can_understand );

   _tprintf( TEXT( &quot;%s\n&quot; ), (LPCTSTR) something_a_human_can_understand );
}</CODE></PRE>

<H2>API's Used</H2>
<B>wfc_get_error_string</B>() uses the following API's:
<UL>
<LI>FormatMessage
<LI>LocalFree
</UL>

<HR><I>Copyright, 2000, <A HREF="mailto:wfc@pobox.com">Samuel R. Blackburn</A></I><BR>
$Workfile: wfc_get_error_string.cpp $<BR>
$Modtime: 1/17/00 9:33a $
</BODY>

</HTML>
#endif

By viewing downloads associated with this article you agree to the Terms of Service and the article's licence.

If a file you wish to view isn't highlighted, and is a text file (not binary), please let us know and we'll add colourisation support for it.

License

This article has no explicit license attached to it but may contain usage terms in the article text or the download files themselves. If in doubt please contact the author via the discussion board below.

A list of licenses authors might use can be found here


Written By
United States United States
I'm just a simple little NT programmer. Most of the work I do is remote controlling equipment in real time. I started out using Windows 3.0. Then came 3.1 and then NT. I started using NT but unfortunately, Microsoft didn't. I started using MFC but unfortunately, Microsoft didn't (and still doesn't) put any real support for NT into MFC so I wrote a bunch of C++ classes to make my life easier. Like all class libraries, mine grew. Now I'm giving it away, I call it Win32 Foundation Classes.

Check out Sam's homepage at www.SamBlackburn.com/wfc/.

Comments and Discussions