IDL.ITEMIDLIST is a 3 byte structure, whereas SHGetSpecialFolderLocation expects the address of a pointer for it's last argument (i.e. it wants 4 bytes that it can write the address into). So change IDL.ITEMIDLIST to @*IDL.ITEMIDLIST or just @*IDL (since we won't access the contents of the structure it is pointing to) or even just @IDL. Then SHGetPathFromIDList wants the pointer we just received as it's first argument so pass *IDL (or IDL if you used @IDL). Also, instead of 512 you could use #MAX_PATH.
Procedure.s GetSpecialFolder(CSIDL.l)
Protected Path.s, Result.l
Result = SHGetSpecialFolderLocation_(0, CSIDL, @*IDL.ITEMIDLIST)
If Result = #NOERROR
Path = Space(#MAX_PATH)
Result = SHGetPathFromIDList_(@*IDL\mkid\cb, Path)
If Right(Path, 1) <> "\" : Path + "\" : EndIf
Else
Path = ""
EndIf
ProcedureReturn Path
EndProcedure
Debug GetSpecialfolder(5)
PureBasic 5.73 | SpiderBasic 2.30 | Windows 10 Pro (x64) | Linux Mint 20.1 (x64)
Old bugs good, new bugs bad! Updates are evil: might fix old bugs and introduce no new ones.