Page 1 of 1

PB4 Beta 6

Posted: Sat Mar 11, 2006 6:32 pm
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]

Posted: Sat Mar 11, 2006 7:19 pm
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.

Posted: Sat Mar 11, 2006 8:21 pm
by Ninja
thanks, it works.

Posted: Sun Mar 12, 2006 9:04 am
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..

Posted: Sun Mar 12, 2006 9:13 am
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)

Posted: Sun Mar 12, 2006 10:54 am
by Ninja
Thank you!

Posted: Sun Mar 12, 2006 3:18 pm
by MrMat
Sorry i should have checked that better! Thanks for the fix ts-soft :)