Click here to Skip to main content
15,867,453 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 466.7K   12.6K   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_executable_directory.cpp $
** $Revision: 4 $
** $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_executable_directory( CString& directory_name_ending_in_a_slash )
{
   WFCLTRACEINIT( TEXT( "wfc_get_executable_directory()" ) );

   TCHAR path[ 4096 ];

   ZeroMemory( path, sizeof( path ) );

   if ( GetModuleFileName( NULL, path, DIMENSION_OF( path ) ) != 0 )
   {
      *( _tcsrchr( path, TEXT( '\\' ) ) + 1 ) = 0x00;

      directory_name_ending_in_a_slash = path;
   }
   else
   {
      directory_name_ending_in_a_slash = "\\";
   }
}

// End of source

#if 0
<HTML>

<HEAD>
<TITLE>WFC - wfc_get_executable_directory</TITLE>
<META name="keywords" content="WFC, MFC extension library, freeware class library, Win32">
<META name="description" content="Simple C function that gives you the full pathname to the exectuable.">
</HEAD>

<BODY>

<H1>wfc_get_executable_directory</H1>
$Revision: 4 $<HR>

<H2>Declaration</H2>
<PRE>void <B>wfc_get_executable_directory</B>( CString&amp; directory_name_ending_in_a_slash )</PRE>

<H2>Description</H2>
This function returns the complete path name to the executable. The
string will end in a slash for easy creation of filenames.
Interestingly enough, it is impossible to port this function to Unix.
It is not possible in Unix for a running process to determine which file
it came from. If you ever need an example of something NT can do that
Unix cannot, this is it.

<H2>Example</H2>

<PRE><CODE>int _tmain( int number_of_command_line_arguments, LPCTSTR command_line_arguments[] )
{
   <A HREF="WfcTrace.htm">WFCTRACEINIT</A>( TEXT( &quot;_tmain()&quot; ) );

   CString my_executable;

   <B>wfc_get_executable_directory</B>( my_executable );

   _tprintf( TEXT( &quot;Executing %s\n&quot;, (LPCTSTR) my_executable );

   return( EXIT_SUCCESS );
}</CODE></PRE>

<H2>API's Used</H2>

<B>wfc_get_executable_directory</B>() uses the following API's:
<UL>
<LI>GetModuleFileName
</UL>

<HR><I>Copyright, 2000, <A HREF="mailto:wfc@pobox.com">Samuel R. Blackburn</A></I><BR>
$Workfile: wfc_get_executable_directory.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