Click here to Skip to main content
11,934,443 members (52,346 online)
Rate this:
Please Sign up or sign in to vote.
See more: VC8.0 C++
i m using vs 2008 for my program which should work in winxp,vista,win7 ...
cfiledialog has a last parameter bVistaStyle which should be set to true
for vista style dialog

and also the doc says that the ApplyOFNToShellDialog(); function is called in domodal() and
UpdateOFNFromShellDialog(); in ok

and i compiling my program with
#define WINVER 0x0501
#define _WIN32_WINNT 0x0501

but the declarations of function ApplyOFNToShellDialog() and UpdateOFNFromShellDialog()
are inside the compiler if block
#if WINVER >= 0x0600


and still my programme is compiling properly.why?
and also the purpose of WINVER is setting the minimum version on which the application should work and keeping it in WINVER > = 0x0600 is wrong
because a program meant to work on winxp is also meant on any other higher verions
Posted 18-Jan-11 6:23am
Edited 18-Jan-11 6:35am

1 solution

Rate this: bad
Please Sign up or sign in to vote.

Solution 1

The CFileDialog constructor calls GetVersionEx to determine the current OS version. If you set the vista style to TRUE, and the app is running in a pre-Vista OS, it will reset the flag to FALSE.

And as to your code compiling, unless you explicitly try to call a method not defined for your version, it will compile. This actual determination of the OS is a runtime behavior.
Rajesh Katalkar 18-Jan-11 11:38am
if u see the domodal code of cfiledialog

if (m_bVistaStyle == TRUE)
HRESULT hr = (static_cast(m_pIFileDialog))->Show(m_ofn.hwndOwner);
nResult = (hr == S_OK) ? IDOK : IDCANCEL;

ApplyOFNToShellDialog(); is called explicitly
Nishant Sivakumar 18-Jan-11 11:44am
Yes, but m_bVistaStyle is set to FALSE in the constructor if you run it on a pre-Vista OS.
Rajesh Katalkar 18-Jan-11 11:51am
you are not getting the point .
m_bVistaStyle is a normal variable not a compiler variable

and ApplyOFNToShellDialog(); is decalred
#if WINVER >= 0x0600


and if my WINVER is less than 0x0600
the program should not compile because the function does not get declared in the first place.
Nishant Sivakumar 18-Jan-11 11:58am
I have VS 2010 and both ApplyOFNToShellDialog and UpdateOFNFromShellDialog are declared outside the #ifdef WINVER >= 0x0600 block.

Both their implementations assert if the vista flag is true via: ASSERT(m_bVistaStyle == TRUE). The assumption is these get called only if the flag is true. This is not compiler related at all.

That said, I notice you are on VS 2008. Let me see if I can check this out on a VS 2008 installation.
Rajesh Katalkar 18-Jan-11 12:07pm
my question is why does the program gets compiled when function is not declared at all.
putting it inside #if #endif is as good as not declaring it
Nishant Sivakumar 18-Jan-11 12:09pm
Ok I checked VS 2008 sources. The header file indeed has those functions inside the #ifdef block. That is a bug in my opinion, and one that they have rightly fixed in VS 2010.

Anyway it will compile for you, unless you try to call those methods yourself. The cpp file you are looking at is just provided for you, the actual code that is executed is from the pre-compiled DLLs which were compiled with the right version-macros defined.

When you do a build, dlgfile.cpp does not get compiled. Does that make sense?
Rajesh Katalkar 18-Jan-11 22:23pm
ok ..
so could you tell whats declared in vs2010 header file for cfiledialog and also the WINVER of #if block if should 0x501 and not 0x0600 according to me because its a minimum version on which an application can run and cfiledialog supports both vista and non-vista versions ..

one more thing could you tell in which precompiled dll is this cfiledialog going
Nishant Sivakumar 19-Jan-11 9:08am
I don't want to paste the header file here, but the methods you mentioned are not conditionally defined (means they are always present irrespective of the version definition). And as for the compiled DLL, I am not sure, it should be in one of the 2 or 3 major MFC DLLs that are shipped with the MFC runtime.

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

  Print Answers RSS
Top Experts
Last 24hrsThis month

Advertise | Privacy | Mobile
Web01 | 2.8.151126.1 | Last Updated 18 Jan 2011
Copyright © CodeProject, 1999-2015
All Rights Reserved. Terms of Service
Layout: fixed | fluid

CodeProject, 503-250 Ferrand Drive Toronto Ontario, M3C 3G8 Canada +1 416-849-8900 x 100