Click here to Skip to main content
Click here to Skip to main content

Accessing Windows 2000 specific APIs

, 28 Feb 2000
Rate this:
Please Sign up or sign in to vote.
Having trouble accessing the new Windows 2000 APIs? This article may help.

In order to access Win2000 specific APIs etc, one needs the following #define in the application's stdafx.h (before any other #includes)

#define _WIN32_WINNT 0x0500
With the latest platform SDK, this also has the side effect of changing the definition for the OPENFILENAME struct; in particular it makes it larger. This is because of the following lines in the "CommDlg.h"
typedef struct tagOFNA {
	DWORD        lStructSize;
	LPCSTR       lpTemplateName;
#ifdef _MAC
	LPEDITMENU   lpEditInfo;
	LPCSTR       lpstrPrompt;
#if (_WIN32_WINNT >= 0x0500)
	void *       pvReserved;
	DWORD        dwReserved;
	DWORD        FlagsEx;
#endif // (_WIN32_WINNT >= 0x0500)

This means when the definition of class CFileDialog is compiled, it's m_ofn member will have a different size than in the MFC dlls. This is because CFileDialog is defined as:

class CFileDialog : public CCommonDialog
	// Attributes
	OPENFILENAME m_ofn; // open file parameter block

When a CFileDialog is used in your code and is destructed, the wrong offsets into memory for member varialbes will be unsed, and in particular, the m_strFilter will not destruct properly.

The work-around for this is to #undef _WIN32_WINNT before the #include <afxext.h> in the application's stdafx.h:

#define _WIN32_WINNT 0x0500     // allow Win2000 specific calls
#define VC_EXTRALEAN            // Exclude rarely-used stuff from Windows headers
#include <afxwin.h>             // MFC core and standard components
#undef _WIN32_WINNT             // allow CFileDialog to build with the correct size
#include <afxext.h>             // MFC extensions
#include <afxdtctl.h>           // MFC support for Internet Explorer 4 Common Controls
#include <afxcmn.h>             // MFC support for Windows Common Controls

Now, <afxext.h> will (indrectly) #include <CommDlg.h> and define CFileDIalog all without the offending _WIN32_WINNT.

NOTE: This only works because the VC_EXTRALEAN stops <afxwin.h> from including CommDlg.h earlier.


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

About the Author

Roger Onslow

United States United States
No Biography provided

Comments and Discussions

GeneralFor VC++ 6.0 and extended functions PinmemberRobCC10-Sep-08 7:56 
After a long time reading through lots of articles about the destructor crash following using the Open file dialog and _WIN32_WINNT == 0x0500, like by Paul Dilascia, this article gave me the clue for the solution.
Not that its exactly difficult, but a little info goes a long way in this business.
Okay so implementing the define / undefine frig solves the problem, but functions like CoInitialiseEx disappear.
The solution is to follow the #undef as follows:
#undef _WIN32_WINNT
#def _WIN32_WINNT 0x400
This then brings into scope the extended function and now my app compliles.
Thanks Roger!!
The real problem with Microsoft is that they dont work for their clients, they just fuss around looking for ways to tie us forever into their nasty API´s and constant changes. Look at the IE style open dialog! There is just no easy way to get and set the view style the user sets, and not even on IE7 does it remain permanent! What a pain!
QuestionIs this fix still required for VC 2005? Pinmemberpsandrene3-Oct-07 7:25 
GeneralHelps also with CFileDialog Pinmemberarschimedes22-Feb-07 3:52 
Generalgood stuff Pinmembercarl124830-Jan-04 0:19 
Questionhow to get user highlighted text in Internet Explorer? PinmemberHolly Lee24-Feb-03 17:51 
GeneralAnother Solution PinmemberAlois Kraus14-Nov-02 6:13 
GeneralRe: Another Solution PinmemberPandele Florin7-Feb-07 22:17 
GeneralFor those of you who still need to access NT functions... PinsussOpus7-Sep-00 8:39 
GeneralRe: For those of you who still need to access NT functions... Pinmemberinner31-Mar-04 7:49 
GeneralBut builds wont work in 98 PinsussCheekyboy10-Apr-00 19:26 
GeneralRe: But builds wont work in 98 PinsussRoger Onslow10-Apr-00 19:38 
GeneralRe: But builds wont work in 98 PinsussCheekyboy11-Apr-00 21:29 
GeneralRe: But builds wont work in 98 PinsussBovineOne30-Apr-00 2:21 
GeneralRe: But builds wont work in 98 PinmemberEhsan Akhgari5-Jan-02 8:26 
GeneralRe: But builds wont work in 98 PinmemberDaniel Turini29-Jul-02 11:48 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    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 | Mobile
Web01 | 2.8.140721.1 | Last Updated 29 Feb 2000
Article Copyright 2000 by Roger Onslow
Everything else Copyright © CodeProject, 1999-2014
Terms of Service
Layout: fixed | fluid