Hello
- good little function that.
Hope you don't mind, I modified your code a bit to implement the <Make Memory> command and use memory pointers instead of using memblocks.
Memblocks are very handy but sometimes just a simple pointer or two will do the job also.
It's always nice to know there's more than one way to do a particular task
Still though, good snippet!
Rem Project: Special Folders
` Microsoft constansts
` whole list of them can be used, see this link;
` http://msdn.microsoft.com/library/default.asp?url=/library/en-us/shellcc/platform/shell/reference/enums/csidl.asp
#constant max_path 0x200
#constant CSIDL_DESKTOP 0x0000
#constant CSIDL_PERSONAL 0x0005
#constant CSIDL_PROGRAM_FILES 0x0026
#constant CSIDL_SYSTEM 0x0025
#constant CSIDL_WINDOWS 0x0024
` which memory and dll numbers to use
global dll_Shell32 = 1
global pszPath as dword
global ppidl as dword
getpath_start() : ` only load dll once = more efficient if dll is to be called multiple times
print "Desktop = "; GetPath(CSIDL_DESKTOP)
print "Documents = "; GetPath(CSIDL_PERSONAL)
print "Programs = "; GetPath(CSIDL_PROGRAM_FILES)
print "System = "; GetPath(CSIDL_SYSTEM)
print "Windows = "; GetPath(CSIDL_WINDOWS)
` you can also just loop through and print all known special paths;
` the number (f) corresponds to the list of Microsoft constants
print
for f = 0 to 56
p$ = GetPath(f)
if (p$ <> "")
print f; " = "; p$
endif
next f
getpath_end() : ` only delete dll when finished = more efficient
print
print "End."
wait key
end
function getpath_start()
if dll exist(dll_Shell32 )=0
load dll "shell32.dll",dll_Shell32
endif
pszPath = Make Memory(max_path)
ppIDL = Make Memory(16)
endfunction
function getpath_end()
if dll exist(dll_Shell32 )=1
delete dll dll_Shell32
endif
Delete Memory pszPath
Delete Memory ppidl
endfunction
function GetPath(nFolder)
Local retStr as string
Local ptr as dword
Local tmpByte as byte
if (0 = call dll(dll_Shell32 , "SHGetFolderLocation","", nFolder, "", 0, ppidl))
if (call dll(dll_Shell32 ,"SHGetPathFromIDList", *ppidl, pszPath))
for b = 0 to max_path-1
ptr = pszPath + b
tmpByte = *ptr
if (tmpByte <> 0)
retStr = retStr + chr$(tmpByte)
else
exit
endif
next b
endif
endif
endfunction retStr