Click here to Skip to main content
15,884,176 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
See more:
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

.....
#endif

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
Updated 18-Jan-11 5:35am
v2

1 solution

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.
 
Share this answer
 
v2
Comments
Rajesh Katalkar 18-Jan-11 11:38am    
if u see the domodal code of cfiledialog

if (m_bVistaStyle == TRUE)
{
ApplyOFNToShellDialog();
HRESULT hr = (static_cast<ifiledialog*>(m_pIFileDialog))->Show(m_ofn.hwndOwner);
nResult = (hr == S_OK) ? IDOK : IDCANCEL;
}


ApplyOFNToShellDialog(); is called explicitly
Nish Nishant 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
inside
#if WINVER >= 0x0600

.....
#endif

and if my WINVER is less than 0x0600
the program should not compile because the function does not get declared in the first place.
Nish Nishant 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

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



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900