shgetspecialfolderlocation

shgetspecialfolderlocation

Hi all:
has anyone ever used SHGetSpecialFolderLocation to get the user's personal files directory on a windows based machine? Would hihgly appreciate an example on how to call this in a Fortran environment.

Thanks

3 posts / 0 new
Last post
For more complete information about compiler optimizations, see our Optimization Notice.
Jugoslav Dujic's picture

You'd be better off using SHGetSpecialFolderPath; SH...Location returns a PIDL which is useful in things like managing shell namespace's tree view, but ShGetSpecialFolderPath should be simpler to use.

To my surprise, I don't find INTERFACE for ShGet... functions in SHELL32.f90 of 6.6B. I wrote my own module with interfaces (attached) (Please remove extra declarations from it if the compiler complains about redeclarations of symbols).

I discovered that on NT systems the function returns a UNICODE string, while on 9x systems it returns an ANSI string; so, a run-time test is required (the sample is for "application data" folder):

USE SHELL
TYPE (T_OSVERSIONINFO)::      VI
CHARACTER(512),AUTOMATIC::    wLocalDir
CHARACTER(256)::              sLocalDir

iSt = SHGetSpecialFolderPath(hFrame, wLocalDir, CSIDL_APPDATA, .TRUE.)
VI%dwOSVersionInfoSize = SIZEOF(VI)
iSt = GetVersionEx(VI)
IF (VI%dwPlatformId .EQ. VER_PLATFORM_WIN32_NT) THEN
   iSt = WideCharToMultiByte(0, 0, wLocalDir, -1, & 
   sLocalDir, LEN(sLocalDir), 0, 0)
ELSE
   sLocalDir = wLocalDir
END IF

(It uses declaration of WideCharToMultiByte from attached file; you might need to adjust type declarations or insert LOCs if 6.6B complains -- the original code was written for 5.0D which didn't have any of INTERFACEs used and thus no possibility of conflict with DFWIN).

HTH
Jugoslav

P.S. D'oh, "attach files" feature doesn't work again. I'll try in the next message or paste the code as-is.

Jugoslav www.xeffort.com
Jugoslav Dujic's picture

...here it is

Jugoslav www.xeffort.com

Login to leave a comment.