Jump to content
alank2

SHGetSpecialFolderLocation in FireMonkey

Recommended Posts

I am trying to get the programdata folder.  I've been using:

 

cppbuilder 10.3.3

LPITEMIDLIST pidl

SHGetSpecialFolderLocation(NULL, CSIDL_COMMON_APPDATA, &pidl)

SHGetPathFromIDListW(pidl, APath)

 

This works fine in a VCL application, but a FireMonkey application, none of it is recognized.

 

I tried to include <shlobj_core.h>, but this gives 1500+ warnings about the below and then fails.

 

[bcc32 Warning] shobjidl_core.h(26477): W8026 Functions with exception specifications are not expanded inline
  Full parser context
    mycode.cpp(33): #include c:\program files (x86)\embarcadero\studio\20.0\include\windows\sdk\shlobj_core.h
    shlobj_core.h(86): #include c:\program files (x86)\embarcadero\studio\20.0\include\windows\sdk\shobjidl_core.h
    shobjidl_core.h(26477): decision to instantiate: ACTIVATEOPTIONS |(ACTIVATEOPTIONS,ACTIVATEOPTIONS) throw()
    --- Resetting parser context for instantiation...

 

I was using this function because this code has to run on some older compilers, but if I can't get it to work I can use something else.

 

Share this post


Link to post
30 minutes ago, alank2 said:

LPITEMIDLIST pidl

SHGetSpecialFolderLocation(NULL, CSIDL_COMMON_APPDATA, &pidl)

SHGetPathFromIDListW(pidl, APath)

 

This works fine in a VCL application, but a FireMonkey application, none of it is recognized.

Correct, since FMX is cross-platform, but you are trying to use platform-specific code.  So, you will have to #ifdef your code for Windows, and then #include the relevant header files, in this case <windows.h> and <shlobj.h> (NOT <shlobj_core.h> directly).

 

Also, FYI, SHGetSpecialFolderLocation() is very old, so you should be using SHGetFolderPathW() instead, or even SHGetKnownFolderPath().

30 minutes ago, alank2 said:

[bcc32 Warning] shobjidl_core.h(26477): W8026 Functions with exception specifications are not expanded inline

That is just a warning. Ignore it, and or turn it off in the compiler settings.

30 minutes ago, alank2 said:

I was using this function because this code has to run on some older compilers

SHGetFolderPath() was introduced in Windows 2000.  Any old compiler that doesn't recognize it is too old to support FireMonkey anyway.

  • Like 1

Share this post


Link to post

Thank you - I disabled the warnings and that did solve the problem:

 

#pragma warn -8026
#pragma warn -8027
#include <shlobj_core.h>
#pragma warn .8027
#pragma warn .8026

 

I like that better than my other approach.

 

Share this post


Link to post

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

×