GetSpecialFolderLocation - no lib required

BlitzPlus Forums/BlitzPlus Programming/GetSpecialFolderLocation - no lib required

JoshK(Posted 2005) [#1]
This code does not require any dll's. Now you can write installers for your programs.

Someone should convert the compression routines in the archives to compress a bank - this makes a lot more sense than creating a compressed file on your hard drive.

Maybe ASPack or UPX could be used to compress the installer.

;.lib "shell32.dll"
;SHGetSpecialFolderLocation%(hwnd%,folder%,pidl*)
;SHGetPathFromIDList%(pidl%,pszPath*)

Notify GetSpecialFolderLocation(CSIDL_PROGRAMS)


Const MAX_PATH=260

Const CSIDL_PROGRAMS=2					;Program Groups Folder
Const CSIDL_PERSONAL=5					;Personal Documents Folder
Const CSIDL_FAVORITES=6					;Favorites Folder
Const CSIDL_STARTUP=7					;Startup Group Folder
Const CSIDL_RECENT=8					;Recently Used Documents Folder
Const CSIDL_SENDTO=9   					;Send To Folder
Const CSIDL_STARTMENU=11  				;Start Menu Folder
Const CSIDL_DESKTOPDIRECTORY=16  		;Desktop Folder
Const CSIDL_NETHOOD=19					;Network Neighborhood Folder
Const CSIDL_TEMPLATES=21				;Document Templates Folder
Const CSIDL_COMMON_STARTMENU=22			;Common Start Menu Folder
Const CSIDL_COMMON_PROGRAMS=23			;Common Program Groups Folder
Const CSIDL_COMMON_STARTUP=24			;Common Startup Group Folder
Const CSIDL_COMMON_DESKTOPDIRECTORY=25	;Common Desktop Folder
Const CSIDL_APPDATA=26					;Application Data Folder
Const CSIDL_PRINTHOOD=27				;Printers Folder
Const CSIDL_COMMON_FAVORITES=1			;Common Favorites Folder
Const CSIDL_INTERNET_CACHE=32			;Temp. Internet Files Folder
Const CSIDL_COOKIES=33					;Cookies Folder
Const CSIDL_HISTORY=34					;History Folder

Function GetSpecialFolderLocation$(folder)
temp=CreateBank(4)
SHGetSpecialFolderLocation(0,2,temp)
pidl=PeekInt(temp,0)
FreeBank temp
If Not pidl Return
temp=CreateBank(MAX_PATH)
SHGetPathFromIDList(pidl,temp)
s$=PeekString(temp,0)
FreeBank temp
Return s
End Function



TAS(Posted 2008) [#2]
Should
SHGetSpecialFolderLocation(0,2,temp)
actually be
SHGetSpecialFolderLocation(0,folder,temp)
in the function GetSpecialFolderLocation$(folder) ?


epiblitikos(Posted 2009) [#3]
@TAS: Yeah, I think that is right. Did you get an error about that function? Mine says the function can't be found.


siread(Posted 2009) [#4]
Anyone used this successfully on Vista? I created the decls file and put it in user libs. Copied the PeekString function from the code archive but get the error "Bank offset out of range" at the following line...

Function PeekString$(bank,offset)
	l = PeekInt(bank,offset)
	s$ = ""
	For i = 1 To l
>>>>>>>>s$ = s$ + Chr$(PeekByte(bank,offset+i+3))<<<<<<<<<
	Next
	Return s$
End Function



epiblitikos(Posted 2009) [#5]
If it's any comfort, I get the same error in XP. took off the + 3 and it still gets it.


Yue(Posted 2012) [#6]
Has anyone gotten this to work?


Yue(Posted 2012) [#7]
Function PeekString$(bank,offset)
	l = PeekInt(bank,offset)
	s$ = ""
	For i = 0 To MAX_PATH%
        s$ = s$ + Chr$(PeekByte(bank,offset+i))
	Next
	Return s$
End Function


This is a nightmare, my life with blitz products is summarized in trial and error, trial and error ...

Last edited 1917

Last edited 2012


_PJ_(Posted 2013) [#8]
1:
There needs to be a check for a terminator (Byte 0 ) in the String reading

2:
It DOES require DLLs, specifically, the Shell32.dll which is a part of Windows

3:
There's no need to read the integer first in PeekString- I'm really not sure what that's there for.

4:
Siread, you almost got it, but are starting at 1, not 0 and reading beyond the end of the allocated space by 4 bytes (The value of l plus an extra 3)

5:
MAX PATH may fail if the path is longer than 260 characters.

6:
The function ought to be:

(Note: I've separated the PeekString from the main function since it's very handy and can be used in other situations too!)