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.
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):
TYPE (T_OSVERSIONINFO):: VI
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)
sLocalDir = wLocalDir
(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).
P.S. D'oh, "attach files" feature doesn't work again. I'll try in the next message or paste the code as-is.
...here it is