PB4 Beta 6

Just starting out? Need help? Post your questions and find answers here.
Ninja
New User
New User
Posts: 7
Joined: Mon Mar 06, 2006 5:13 pm

PB4 Beta 6

Post by Ninja »

Hi,
Why does this not work?

Code: Select all

Procedure.s GetSpecialfolder(CSIDL) 

Structure shItemID 
    cb.l 
    abID.b 
EndStructure 
Structure ItemIDlist 
    mkid.shItemID 
EndStructure 

    r = SHGetSpecialFolderLocation_(0, CSIDL, @IDL.ITEMIDLIST) 
    If r = #NOERROR 
        Path$ = Space(512) 
        r = SHGetPathFromIDList_(IDL\mkid\cb, Path$) 
        folder$ = Trim(Path$)        
       Else 
        folder$="" 
    EndIf
    
    ProcedureReturn folder$ 
    
EndProcedure 

Even if i write:

Code: Select all

Procedure.s GetSpecialfolder(CSIDL) 

    r = SHGetSpecialFolderLocation_(0, CSIDL, @IDL.ITEMIDLIST) 
    If r = #NOERROR 
        Path$ = Space(512) 
        r = SHGetPathFromIDList_(IDL\mkid\cb, Path$) 
        folder$ = Trim(Path$)        
       Else 
        folder$="" 
    EndIf
    
    ProcedureReturn folder$ 
    
EndProcedure 
I hope someone is able to help me!

greez Ninja[/code]
MrMat
Enthusiast
Enthusiast
Posts: 762
Joined: Sun Sep 05, 2004 6:27 am
Location: England

Post by MrMat »

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.
Mat
Ninja
New User
New User
Posts: 7
Joined: Mon Mar 06, 2006 5:13 pm

Post by Ninja »

thanks, it works.
Ninja
New User
New User
Posts: 7
Joined: Mon Mar 06, 2006 5:13 pm

Post by Ninja »

uhm i just saw it doesnt work correct..

i changed to

Code: Select all

Procedure.s GetSpecialfolder(CSIDL) 


r = SHGetSpecialFolderLocation_(1, CSIDL, @IDL.ITEMIDLIST) 
If r = #NOERROR 
        Path$ = Space(512) 
        r = SHGetPathFromIDList_(@*IDL, Path$) 
        folder$ = Trim(Path$)        
       Else 
        folder$="" 
EndIf   
    ProcedureReturn folder$ 
    
EndProcedure
but it always returns C:\Dokumente und Einstellungen\MeinPC\Desktop on every CSIDL..
User avatar
ts-soft
Always Here
Always Here
Posts: 5756
Joined: Thu Jun 24, 2004 2:44 pm
Location: Berlin - Germany

Post by ts-soft »

Code: Select all

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.
Image
Ninja
New User
New User
Posts: 7
Joined: Mon Mar 06, 2006 5:13 pm

Post by Ninja »

Thank you!
MrMat
Enthusiast
Enthusiast
Posts: 762
Joined: Sun Sep 05, 2004 6:27 am
Location: England

Post by MrMat »

Sorry i should have checked that better! Thanks for the fix ts-soft :)
Mat
Post Reply