Intel® Fortran Compiler
Build applications that can scale for the future with optimized code designed for Intel® Xeon® and compatible processors.

shgetspecialfolderlocation

bigguy
Beginner
974 Views
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
0 Kudos
2 Replies
Jugoslav_Dujic
Valued Contributor II
974 Views
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.
0 Kudos
Jugoslav_Dujic
Valued Contributor II
974 Views
...here it is
0 Kudos
Reply