Click here to Skip to main content
12,511,665 members (44,644 online)
Click here to Skip to main content
Add your own
alternative version

Stats

374.7K views
12K downloads
279 bookmarked
Posted

The Win32 Foundation Classes (WFC) - Version 45

, 16 May 2000
Rate this:
Please Sign up or sign in to vote.
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

Introduction

Win32 Foundation Classes (WFC) is a library of C++ classes that extend Microsoft Foundation Classes (MFC) to do NT specific things. Microsoft has chosen to focus their efforts on making MFC do pretty GUI things rather that application development things. MFC views the world through GUI colored glasses. There's no real support for doing any sort of interesting application in MFC. Oh sure, there's database support but that is GUI-slanted (assumes the application will present the database in a GUI).

Peaceful Coexistence

My strategy in building applications is to divide the problem into two domains, Engine and Interface. The Engine is what does what the application is supposed to do.

Latest Updates

Warning! The versions of WFC distributed from Sam's homepage are in PAX format for reasons of size. The downloadable versions from CodeProject are in the usual ZIP format.

Samples

What's the best way to learn WFC? An example teaches, not much else does. Checkout the samples page.

Codeing Guidlines

WFC was created with these coding guidelines.

The Win32 Classes

CAccessAllowedEntryEncapsulates the ACCESS_ALLOWED_ACE structure.
CAccessControlEntryHeaderEncapsulates the ACE_HEADER structure.
CAccessControlListEncapsulates the ACL structure.
CAccessDeniedEntryEncapsulates the ACCESS_DENIED_ACE structure.
CAccessTimeoutEncapsulates the ACCESSTIMEOUT structure.
CAppleTalkProjectionResultexcapsulates the RAS_PPP_ATCP_RESULT structure.
CBase64CodingSimple base64 encoder/decoder. This is what MIME uses to send binary data in e-mail.
CBitArrayTreats bits like they were just any other array. Patterned after CByteArray except it plays with bits instead of bytes.
CBitmapCoreHeaderEncapsulates the BITMAPCOREHEADER structure.
CBitmapFileHeaderEncapsulates the BITMAPFILEHEADER structure.
CBitmapInfoHeaderEncapsulates the BITMAPINFOHEADER structure.
CCommunicationsConfigurationEncapsulates the COMM_CONFIG data structure.
CCommunicationPropertiesEncapsulates the COMMPROP data structure.
CCompVarsEncapsulates the COMPVARS structure.
CColorAdjustmentEncapsulates the COLORADJUSTMENT structure.
CCriticalSectionGuardLocks a CCriticalSection (an MFC class) in the constructor and unlocks it in the destructor.
CCryptographicAlgorithmencapsulates the PROV_ENUMALGS structure.
CCryptographicHashencapsulates the hash portions of the CryptoAPI.
CCryptographicKeyencapsulates the key portions of the CryptoAPI.
CCryptographicProviderencapsulates the cryptographic provider portion of the CryptoAPI.
CCryptographyThis is the base class for all cryptographic classes that provide functionality.
CDataChunkAllows for handling of data chunks. Patterned after RIFF.
CDataFileA derivative of CFile that makes it easy to read/write CDataChunk's.
CDataMemoryHandles a collection of RIFF chunks.
CDataParserGeneric data parsing class.
CDataSocketA derivative of CDataFile that allows you to transmit CDataChunk's over a CSimpleSocket.
CDesktopEncapsulates the desktop API.
CDeviceControlBlockEncapsulates DCB structure used in serial communications.
CDocInfoEncapsulates the DOCINFO structure.
CDragQueryEncapsulates the HDROP handle and API. Useful when handling the WM_DROPFILES message (or OnDropFiles method in MFC).
CDummyFileA class that traps all calls to CFile that would blow up if you weren't a disk file.
CEventLogThe event logger. Makes working with log events easier. Allows you to read event log messages, create custom event logs, clear logs, pretty much anything you would ever want to do with an event log.
CEventLogRecordencapsulates the EVENTLOGRECORD structure.
CExtensibleMarkupLanguageAttributeclass that encapulates an XML attribute.
CExtensibleMarkupLanguageDocumentclass that encapulates an XML document.
CExtensibleMarkupLanguageElementclass that encapulates an XML element.
CFileDirectoryThis class gives you the capability to retrieve the names of files (complete full-path filenames) in a directory. You can fill in a CStringArray with the filenames or execute a callback function. You can process the files in a single directory or recurse through the subdirectories.
CFileTimeEncapsulates the FILETIME structure/API.
CFileTransferProtocolMakes it a little easier to play with ftp. It retrieves directory listings or files. Easier to use than the MFC counterparts.
CFilterKeysEncapsulates the FILTERKEYS structure.
CGarbageCollectorMakes rolling your own copy-on-write objects easy.
CInternetworkPacketExchangeProjectionResultencapsulates the RAS_PPP_IPXCP_RESULT structure.
CInternetProtocolProjectionResultencapsulates the RAS_PPP_IPCP_RESULT data structure.
CListeningSocketEstablishes a socket that people can connect to (i.e., makes a server socket).
CLZFileHandles the LZxxx API (compressed files)
CMemoryFileA simple memory mapped file class. It handles the annoyance of mapping a file on an allocation granularity boundary.
CMemoryStatusEncapsulates the MEMORYSTATUS structure
CMicrosoftTapeChild of CTape that knows about the Microsoft Tape Format used by NTBACKUP.EXE This is an unfinished class.
CMixerMixer API stuff.
CMixerCapabilitiesEncapsulates the MIXERCAPS structure.
CMixerControlEncapsulates the MIXERCONTROL structure.
CMixerControlDetailsMixer API stuff.
CMixerControlDetailsDataMixer API stuff.
CMixerControlInstanceMixer API stuff.
CMixerDestinationMixer API stuff.
CMixerLineMixer API stuff.
CMixerSourceMixer API stuff.
CMixerSourceSelectorMixer API stuff.
CMixerSpeakersMixer API stuff.
CMixerSwitchControlMixer API stuff.
CMixerVolumeControlMixer API stuff.
CMixerWaveInMixer API stuff.
CModemA class that hangs off of CSerialFile that makes it easy to play with modems
CMouseKeysEncapsulates the MOUSEKEYS structure.
CMTFDataBlockHeader Encapsulates the MTF_DB_HDR structure.
CMTFDateTimeEncapsulates the MTF_DATE_TIME structure.
CMTFTapeEncapsulates the MTF_TAPE structure.
CMTFTapeAddressEncapsulates the MTF_TAPE_ADDRESS structure.
CNamedPipeUnfinished class. Will be derived from CDummyFile
CNetBEUIFramerProjectionResultencapsulates the RAS_PPP_NBFCP_RESULT structure.
CNetworkBase class for all networking functionality.
CNetworkConnectionInformationClass based on CONNECTION_INFO_1 structure. It allows you to enumerate through the people that are connected to your machine.
CNetworkConnectionsClass that plays with network connections.
CNetworkFileInformationClass based on FILE_INFO_3 structure.
CNetworkFilesClass that plays with network files.
CNetworkInformationEncapsulates the NETINFOSTRUCT structure.
CNetworkResourcesClass that plays with network resources.
CNetworkResourceInformationClass based on NETRESOURCE structure.
CNetScheduleJobLet's you schedule jobs. It interfaces with the Scheduler Service.
CNetworkSessionsClass that plays with network sessions.
CNetworkSessionInformationClass based on SESSION_INFO_502 structure.
CNetworkShareInformationClass based on SHARE_INFO_2 structure.
CNetworkSharesAllows you to query machines about their shares, add new shares, delete existing ones, etc.
CNetWorkstationGathers information about the workstation.
CNetworkUserInformationEncapsulates and combines the USER_INFO_xxx data structures.
CNetworkUsersPlays with the NetUserxxx API. Makes it easy to enumerate, add and delete users.
COFStructEncapsulates the OFSTRUCT structure.
COperatingSystemVersionInformationEncapsulates the OSVERSIONINFO structure.
COutlineTextMetricEncapsulates the OUTLINETEXTMETRIC structure.
COverlappedPlays with OVERLAPPED structure.
CParsePointClass that holds a location in s data stream. Used in parsing data with the CDataParser class.
CPasswordChangeFilterA class that makes it easy to intercept password changes.
CPerfCounterDefinitionEncapsulates the PERF_COUNTER_DEFINITION structure.
CPerfInstanceDefinitionEncapsulates the PERF_INSTANCE_DEFINITION structure.
CPhysicalDiskFileThis class makes it easy to read data from a disk in raw format. In other words, this class reads a disk like it was a file without regard to file system on that disk. Want to read an individual sector on the disk? This is the class for you.
CPingA class that allows you to programmatically ping another machine.
CPingResultsHolds the results of the ping call
CPixelFormatDescriptorEncapsulates the PIXELFORMATDESCRIPTOR structure.
CQueueA simple thread-safe high-performance data queue. It is designed so that one thread can add to the queue and another can get from it without the two threads blocking on each other.
CPointToPointProtocolProjectionResultencapsulates the RAS_PPP_PROJECTION_RESULT structure.
CPortInformationProvides the same information as PORT_INFO_2 data structures. Used in enumerating ports on a machine (i.e. CNetwork::EnumeratePorts).
CPasswordChangeFilterA class that makes it easy to intercept password changes.
CRandomNumberGeneratorGives you better random numbers than rand(). It has about 900 million starting points, each starting point is good for 10^30 values before it starts to repeat.
CRandomNumberGenerator2Gives you better random numbers than rand(). It is good for (2^19937)-1 values before it starts to repeat. It is also faster than the other random number generators in WFC.
CRasterizerStatusEncapsulates the RASTERIZER_STATUS structure.
CReedSolomonErrorCorrectionCodeAllows you to put a forward error correction code onto a block of data. This class blocks data into 255 byte chunks. Up to 16 of those bytes can be scrambled and the errors will automatically be fixed.
CRegistryEncapsulates the Registration Database (Registry API).
CRemoteAccessServiceRemote Access Services. Otherwise known as Dial Up Networking. This class allows you to establish connections, hang up connections,
CRemoteAccessServiceAdministrationA work in progress. Handles the administration of RAS.
CRemoteAccessServiceAuthenticationMessageBlockEncapsulates the RASAMB structure.
CRemoteAccessServiceConnectionProjectionencapsulates the RAS_PORT_STATISTICS structure.
CRemoteAccessServiceInternetProtocolEncapsulates the RASPPPIP structure.
CRemoteAccessServiceInternetworkPacketExchangeEncapsulates the RASPPPIPX structure.
CRemoteAccessServiceNetBEUIFramerEncapsulates the RASPPPNBF structure.
CRemoteAccessServicePortEncapsulates the RAS_PORT_0 data structure.
CRemoteAccessServicePortStatisticsencapsulates the RAS_PORT_STATISTICS structure.
CRemoteAccessServiceUserEncapsulates the RAS_USER_0 data structure.
CSecurityAttributesEncapsulates the SECURITY_ATTRIBUTES structure.
CSecurityQualityOfServiceEncapsulates the SECURITY_QUALITY_OF_SERVICE structure.
CSerialFileTreats the serial port like it was a CFile. Makes doing RS232 communications easier.
CServerThis class allows you to gather information about a server. It can get you information similiar to the Server Control Panel applet. Decrypts data scrambled by NetServerGetInfo().
CServiceNT Services class. Makes creating services pretty brainless.
CServiceApplicationThis class encapsulates all of the logic behind installing, removing and running from a command line (to make debugging easier) needed by a service application.
CServiceConfigurationBasically duplicated QUERY_SERVICE_CONFIG structure.
CServiceControlManagerPlays with the Service Control Manager. Allows you to start, stop, install and remove services on the local machine or on a server on the net.
CServiceNameAndStatusEncapsulates the ENUM_SERVICE_STATUS structure.
CSessionInformationSession information based on SESSION_INFO_502 structure. Basically, gives you same info as Control Panel->Server->Users->Connected Users
CSharedMemoryObjectLet's you create shared memory segments easily.
CSimpleSocketBase class for TCP/IP sockets. Derived from CDummyFile.
CSimpleSocketFileTurns an existing CSimpleSocket into a CFile. Generally, this is called from CListeningSocket::OnNewConnection()
CSoundSentryEncapsulates the SOUNDSENTRY structure.
CStickyKeysEncapsulates the STICKYKEYS structure.
CSystemAuditEntryEncapsulates the SYSTEM_AUDIT_ACE structure.
CSystemTimeEncapsulates the SYSTEMTIME structure/API. It also allows you to get and set the computer's clock.
CTalkingSocketA socket you can use to connect to existing sockets (you connect to a server).
CTapeHandles the Tape API. It finally works.
CTapeGetDriveParametersEncapsulates the TAPE_GET_DRIVE_PARAMETERS data structure.
CTapeGetMediaParametersEncapsulates the TAPE_GET_MEDIA_PARAMETERS data structure.
CTapeSetDriveParametersEncapsulates the TAPE_SET_DRIVE_PARAMETERS data structure.
CTapeSetMediaParametersEncapsulates the TAPE_SET_MEDIA_PARAMETERS data structure.
CTextMetricEncapsulates the TEXTMETRIC structure.
CToggleKeysEncapsulates the TOGGLEKEYS structure.
CUINT64Encapsulates the UINT64 structure.
CUniformResourceLocatorPlays with URL's Example: http://www.microsoft.com/hello.html
CUniversalNamingConventionPlays with UNC's Example: \\buckaroo\public\neato\readme.txt
CVolumeThis class let's you eject removable media (CD-ROM's JAZ drives, tapes, etc). It also let's you lock drives.
CWindowPlacementEncapsulates the WINDOWPLACEMENT structure.
CWorkstationTransportPatterend after WKSTA_TRANSPORT_INFO_0, gives you smurphy information about you network transports (ever wonder what your MAC address is?).
CWorkstationInformationPatterned after WKSTA_INFO_102, used in CNetWorkstation::Enumerate
CWorkstationUserPatterned after WKSTA_USER_INFO_1, used in CNetWorkstation::Enumerate
CXMLArchiveThis class is modeled after the CArchive MFC class. It allows you to serialize (or persist) objects to and from XML documents.

Classes That Ain't Exactly Win32:

CBubbleCreates a tooltip window where ever and how many ever you want.
CCircleDraws a circle on the screen.
CConstellationThis ain't exactly Win32 encapsulation of something useful. It is related to CSquiggle but instead of displaying data as a squiggley line across the screen (like an oscilloscope), it displays lots of little dots. It looks like a constellation of stars.
CConstellationDataData to be displayed by CConstellation.
CDrawingObjectGridA grid of drawing objects like CCircle, etc.
CEllipseDraws an ellipse on the screen.
CGarbageCollectorImplements a garbage collection scheme (modeled after COM) that allows objects to govern their own lifetimes.
CLabeledGridA subclass of CDrawingObjectGrid that adds text labels to the objects.
CPagerA virtual base class to handle pagers.
CQueueImplements a thread-safe generic queue.
CRectangleDraws a rectangle on the screen.
CRoundedRectangleDraw a rectangle with rounded corners.
CSkyWordMakes it easy to send messages to SkyTel alphanumeric pagers.
CSprintSpectrumMakes it easy to send text messages to Sprint Spectrum PCS phones.
CSquareDraws a square on the screen. Admittedly not very exciting and ground breaking but I was learning how to do these types of things and was shocked that MFC couldn't do something this simple.
CSquiggleA type of CRectangle that makes creating oscilloscope type displays real easy.
CSquiggleDataData taken from o-scopes to be given to CSquiggle.
CWaitCursorYe Olde Wait Cursor class. It turns your cursor into an hour glass in the constructor and returns it to normal in the destructor.
CWeatherThis class normalizes data associated with weather reports.
CWfcTraceTracing class. Used for adding automagically indented debug statements.

Miscellaneous Functions:

Convert_NERR_Code_to_StringConverts NERR_* error codes to text; the FormatMessage() trick doesn't work on these error codes.
bit_clearMacro to set a bit to zero.
bit_setMacro to set a bit to one.
bit_testTest the value of a bit.
wfc_am_i_administratorC Function that returns TRUE if you have Administrator priveleges.
wfc_append_string_to_CByteArrayC Function that appends a string to an array of bytes.
wfc_append_text_to_edit_controlC Function that appends text to an edit control.
wfc_close_handleC function that returns TRUE if CloseHandle() returns not FALSE. This helps in debugging when you pass an invalid handle to CloseHandle().
wfc_convert_lpcwstr_to_cstring()This eliminated a lot of code in the networking classes. Microsoft (even in Visual C++ version 4.2) has the networking API header files all screwed up. The string parameters are mis-typed. I used to have a lot of code in the classes to detect and fix this but it was real ugly (and prevented const correctness). Adding this function allowed me to fix Microsoft's mistake in one function.
wfc_create_hard_linkC function that creates two directory entries for one file. It implements the upcoming NT 5.0 API named CreateHardLink().
wfc_delete_oldest_fileC function that deletes the oldest file in a directory. It will return TRUE if a file was deleted or FALSE it a file was not deleted. This is useful in a file cache management system.
wfc_enable_privilegeA little routine to enable a specific privilege by name.
wfc_enable_all_privilegesA routine I wrote because I hate Microsoft's error messages. They are 100% accurate and totally useless. For example, "Access is Denied." which access is denied???? Another brilliant message was "class failed to initialize" It came from a COM application. Wouldn't it be helpful to know which of the four cudzillion COM object on the system failed to load??? Anyway, wfc_enable_all_privileges simply acquires as many privileges as is possible.
wfc_get_directory_usage_percentageC function that returns an integer percentage of the space used on a volume by a directory. This is useful in a file cache management system.
wfc_get_error_stringC function that cryptic error codes into something humanly readable.
wfc_get_executable_directoryC function that returns the directory name (ending in a slash) that the executable calling this function exists in. This is good for finding configuration files that must exist in the same directory as the executable.
wfc_get_filename_from_handleC function that returns the file name given a file's handle. It uses the partially documented NtQueryInformationFile to perform this magic.
wfc_get_operating_system_version_stringFills a CString with a nice OS version string (including service pack level).
wfc_get_web_page()Retrieves a URL and puts the page into a CStringArray. This is great for retrieving data from the web.
wfc_move_file_at_reboot()This function let's you schedule a file to be moved at the next reboot. This is how system DLL's are upgraded.
wfc_parse_iso_8601_stringThis function parses ISO8601 dates into a CTime or COleDateTime object.
wfc_start_screen_saverC function that activates the screen saver.
wfc_undocumented_get_system_process_listUses an undocumented function to get a list of all processes running in an NT system.

Technical Notes


Frequently Asked Questions

This frequently asked questions (FAQ) document is meant answer the most commonly asked questions about WFC.

1. WFC FAQ Information and Credits

1.1 What is WFC?

WFC started out as a simple little class library that attempts to represent the Win32 API as a set of C++ classes. Over time, more non-Win32 related classes have crept in as I have encountered problems that needed solving. Also, things that have interested me, (like forward error correction) wind up being encapsulated in a generic class and included.

1.2 Who Wrote WFC?

I (Sam Blackburn) did mostly. I have had many people submit bug reports and improvement suggestions. I have incorporated most of those submissions. I can't take credit for other people's work so where ever a bug has been reported and fixed, I include a comment in the code giving thanks to the programmer that found it. I will also surf Internet looking for good freeware code that I can roll into the library. When I do, I try to keep the original author's name in there. I usually wind up rewriting the code to make it more readable (i.e. so I can understand it).

1.3 Did Microsoft Steal Your Name?

Not really. They have a Java product called Windows Foundations Classes (WFC).

2. A Brief History of WFC

2.1 When was WFC Written?

3. Philosophical Questions

3.1 Why is the Source Code so Wordy?

I tend to think of source code as a medium by which humans communicate ideas from one to another. There are a lot of programmers out there that think source code is primarily something that a compiler ingests. The opinion of the programmer producing the code directly relates to the maintainability (and reusability) of that code. If a programmer thinks source code is for compiling, their code tends to be be full of abbreviations and short cuts that save a CPU-cycle here and there. This code is very expensive to reuse. Humans naturally want to solve any given problem using the most knowledge they have at that time. What generally happens is advanced programmers use advanced solutions to simple problems whether or not an "advanced technique" is appropriate. The environment I work in has aggressive delivery schedules. If I cannot reuse code from many dissimilar projects, I will not meet my deadlines. This means in order for code to be quickly reused, it must be painfully obvious what that code does (and in the case of debugging, what that code is supposed to do).

3.1 Which is More Important, Reuse or Object Oriented?

Reuse. I have seen many object oriented (OO) pundits think reuse is a by-product of an OO system. It is not. Reuse is easier with OO designs but all to many times the implementations of those designs are so tied to the original application that reuse is impossible. It is very easy for designers to focus on "solving this problem" when they should be focusing on "solving problems like this."

4. Installation Questions

4.1 How do I install WFC?

See Technical note 2. Note that the WFC zips from CodeProject are in ZIP format, and not in PAX.

5. Build Questions

5.1 How do I build WFC?

See Technical note 2. Note that the WFC zips from CodeProject are in ZIP format, and not in PAX.

5.2 Can I use WFC as a static library?

Yes, go into the WFC project to the Project->Settings->General->Microsoft Foundtion Classes: and select Use MFC in a Static Library. Then recompile everything. Don't forget to change this setting in your project also. If you compile WFC for MFC in a static library, but your project uses MFC in a DLL, you will get linker errors for things like new being multiply defined.

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

Share

About the Author

Sam Blackburn
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/.

You may also be interested in...

Comments and Discussions

 
QuestionWhere have you been all my life? Pin
jrivero3-Oct-07 2:13
memberjrivero3-Oct-07 2:13 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.

| Advertise | Privacy | Terms of Use | Mobile
Web02 | 2.8.160929.1 | Last Updated 17 May 2000
Article Copyright 2000 by Sam Blackburn
Everything else Copyright © CodeProject, 1999-2016
Layout: fixed | fluid