Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

Using SHGetFolderPath or SHGetKnownFolderPath according to OS ver

1,430 views
Skip to first unread message

swt...@gmail.com

unread,
Nov 26, 2008, 7:03:26 AM11/26/08
to
Upto WinXP SHGetFolderPath is supported and with Windows Vista it is
to be no longer used says MSDN. I don't want to break compability with
Win XP by using SHGetKnownFolderPath. I need my program to use
SHGetFolderPath if running in XP and older systems and use
SHGetKnownFolderPath if running in Vista or higher. Is there any
provision for this in ShlObj.h? I am running VC++ 2008 Express.

maverik

unread,
Nov 26, 2008, 7:46:16 AM11/26/08
to

#if (WINVER > 0x0501)
// Vista or higher
#else
// Upto WinXP
#endif

or if you want

#if (WINVER <= 0x0501)
// Upto WinXP
#else
// Vista, ...
#endif

Timo Kunze

unread,
Nov 26, 2008, 7:59:56 AM11/26/08
to
maverik schrieb:

> #if (WINVER > 0x0501)
> // Vista or higher
> #else
> // Upto WinXP
> #endif
>
> or if you want
>
> #if (WINVER <= 0x0501)
> // Upto WinXP
> #else
> // Vista, ...
> #endif
Don't you need different builds for XP and Vista then?

I'd do it this way:
- Determine the OS version using GetVersionEx
- Depending on the determined version:
a) use SHGetFolderPath
b) use SHGetKnownFolderPath
In both cases you shouldn't call SHGet... directly, because then your
program won't load if one of both functions isn't available on the
user's system. It's better to use LoadLibrary/GetModuleHandle and
GetProcAdress to retrieve the address of the function you want to use
and call the function based on this address.
So you'll end up with something like this (the code is for
SHGetKnownFolderIDList):

typedef HRESULT WINAPI SHGetKnownFolderIDListFn(REFKNOWNFOLDERID rfid,
DWORD dwFlags, HANDLE hToken, __out PIDLIST_ABSOLUTE* ppidl);
HMODULE hShell32 = GetModuleHandle(TEXT("shell32.dll"));
if(hShell32) {
pfnSHGetKnownFolderIDList =
reinterpret_cast<SHGetKnownFolderIDListFn*>(GetProcAddress(hShell32,
"SHGetKnownFolderIDList"));
if(pfnSHGetKnownFolderIDList) {
return pfnSHGetKnownFolderIDList(folderID, flags, hToken, ppIDL);
}
}

Hope this helps
Timo
--
www.TimoSoft-Software.de - Unicode controls for VB6
"Those who sacrifice freedom for safety deserve neither."
"Demokratie ist per Definition unsicher. Ihr Schutz entsteht aus der
Überzeugung, dass die demokratischen Kräfte überwiegen und sich – auf
demokratischem Wege – durchsetzen."

seb

unread,
Nov 26, 2008, 11:12:53 AM11/26/08
to

<swt...@gmail.com> wrote in message
news:6910a6a0-e4cc-4f2f...@s1g2000prg.googlegroups.com...

> Upto WinXP SHGetFolderPath is supported and with Windows Vista it is
> to be no longer used says MSDN.

It says it's a wrapper for SHGetKnownFolderPath and it's always exported
Then you can use it without problem on Vista


swt...@gmail.com

unread,
Nov 27, 2008, 12:23:21 AM11/27/08
to
> --www.TimoSoft-Software.de- Unicode controls for VB6

> "Those who sacrifice freedom for safety deserve neither."
> "Demokratie ist per Definition unsicher. Ihr Schutz entsteht aus der
> Überzeugung, dass die demokratischen Kräfte überwiegen und sich – auf
> demokratischem Wege – durchsetzen."

So I will have to implement it myself? Ok then.
By the way, I am using your ExplorerTreeView control. Good work on
that Timo. I wanted to leave a thanks message on ur site but it
required me to register a username (I even tried signning up but never
got an email!). I hope you will make things less complicated for
people wanting to say 'thanks'. Keep contributing...

Piotr

unread,
Feb 2, 2014, 10:13:11 AM2/2/14
to
You determine the OS version using compiler directives which actually determine the OS the program was built on, not necessarily the OS the program is actually running on.
0 new messages