Click here to Skip to main content
15,891,763 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 469.4K   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 "ado2xml.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: get_table_names.cpp $
** $Revision: 2 $
** $Modtime: 3/21/00 5:11a $
** $Reuse Tracing Code: 1 $
*/

/*
** While I'm not known for writing obfuscated code, I did get this error
** while trying to compile this module:
** --------------------Configuration: ADO2XML - Win32 Debug--------------------
** Compiling...
** get_table_names.cpp
** Command line error D2030 : INTERNAL COMPILER ERROR in 'C:\Program Files\Microsoft Visual Studio\VC98\BIN\cl.exe'
**     Please choose the Technical Support command on the Visual C++
**     Help menu, or open the Technical Support help file for more information
** Error executing cl.exe.
**
** get_table_names.obj - 1 error(s), 0 warning(s)
**
** As usual, Microsoft provides us no information to debug the situation.
*/

#if ! defined( WFC_STL )

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

#endif // WFC_STL

bool get_table_names( _ConnectionPtr& connection_p, CStringArray& table_names )
{
   WFCTRACEINIT( TEXT( "get_table_names()" ) );

	table_names.RemoveAll();

   bool return_value = true;

   HRESULT result = S_OK;

   _RecordsetPtr recordset_p = NULL;

   try
   {
      try
      {
         recordset_p = connection_p->OpenSchema( adSchemaTables );
      }
      catch( _com_error &exception )
      {
         WFCTRACEVAL( TEXT( "COM exception caught at line " ), __LINE__ );
         print_COM_error( exception );
      }
      catch( ... )
      {
         WFCTRACEVAL( TEXT( "Exception caught at line " ), __LINE__ );
      }

      _bstr_t table_name;
      _bstr_t table_type;

      CString desired_table_type( TEXT( "TABLE" ) );

      while( ! recordset_p->EndOfFile )
      {
         try
         {
            table_name = recordset_p->Fields->GetItem( "TABLE_NAME" )->Value;
         }
         catch( _com_error &exception )
         {
            WFCTRACEVAL( TEXT( "COM exception caught at line " ), __LINE__ );
            print_COM_error( exception );
         }
         catch( ... )
         {
            WFCTRACEVAL( TEXT( "Exception caught at line " ), __LINE__ );
         }

         try
         {
            table_type = recordset_p->Fields->GetItem( "TABLE_TYPE" )->Value;
         }
         catch( _com_error &exception )
         {
            WFCTRACEVAL( TEXT( "COM exception caught at line " ), __LINE__ );
            print_COM_error( exception );
         }
         catch( ... )
         {
            WFCTRACEVAL( TEXT( "Exception caught at line " ), __LINE__ );
         }

         WFCTRACEVAL( TEXT( "Table Name " ), CString( (LPCTSTR) table_name ) );
         WFCTRACEVAL( TEXT( "Table Type " ), CString( (LPCTSTR) table_type ) );
         WFCTRACE( TEXT( "\n" ) );

         if ( desired_table_type.Compare( table_type ) == 0 )
         {
            // We found a normal table (not system related)

            table_names.Add( (LPCTSTR) table_name );
         }

         try
         {
            recordset_p->MoveNext();
         }
         catch( _com_error &exception )
         {
            WFCTRACEVAL( TEXT( "COM exception caught at line " ), __LINE__ );
            print_COM_error( exception );
            //return( false ); // Commented out to fix Microsoft's compiler error, see above
         }
         catch( ... )
         {
            WFCTRACEVAL( TEXT( "Exception caught at line " ), __LINE__ );
            //return( false ); // Commented out to fix Microsoft's compiler error, see above
         }
      }

      try
      {
         recordset_p->Close();
      }
      catch( _com_error &exception )
      {
         WFCTRACEVAL( TEXT( "COM exception caught at line " ), __LINE__ );
         print_COM_error( exception );
      }
      catch( ... )
      {
         WFCTRACEVAL( TEXT( "Exception caught at line " ), __LINE__ );
      }

      return( return_value );
   }
   catch( _com_error &exception )
   {
      print_provider_error( connection_p );
      print_COM_error( exception );
      return( false );
   }
   catch( ... )
   {
      return( false );
   }
}

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