Author Topic: SHGetIDListFromPath and SHBrowseForFolder  (Read 2755 times)

jj2007

  • Member
  • *****
  • Posts: 8735
  • Assembler is fun ;-)
    • MasmBasic
SHGetIDListFromPath and SHBrowseForFolder
« on: August 24, 2012, 11:04:56 PM »
To supply SHBrowseForFolder with a proper start folder, I searched for SHGetIDListFromPath and found no official version but an undocumented reference to ordinal #162 in Shell32.dll

The good news is it works under Win7 :biggrin:
The bad news is it's pretty useless, you see the dialog and the folder, but you cannot go anywhere else, it's the only folder available :(

Any ideas? Special flags etc? I attach a test program, curious to see which Windows versions support it. Might produce an exception - who knows what happens inside Shell32 ;)

include \masm32\MasmBasic\MasmBasic.inc   ; download (version 24 August needed)
.data?
bInfo   BROWSEINFO <>
buffer   db MAX_PATH dup(?)

  Init

  Dll "Shell32"      ; #162 found in some VB forums
  Declare #162=SHGetIDListFromPathW, 1
  mov bInfo.pidlRoot, SHGetIDListFromPathW(wChr$("C:\Masm32\Examples"))

  mov edi, offset buffer
  mov bInfo.pszDisplayName, edi
  mov bInfo.lpszTitle, Chr$("Select a folder")
  invoke SHBrowseForFolder, addr bInfo
  .if eax
   invoke SHGetPathFromIDList, eax, edi
  .else
   mov edi, Chr$("Nothing selected")
  .endif
  Inkey "Selected folder: [", edi, "]"
  Exit
end start

Tedd

  • Member
  • ***
  • Posts: 353
  • Procrastinor Extraordinaire
Re: SHGetIDListFromPath and SHBrowseForFolder
« Reply #1 on: August 25, 2012, 08:14:27 AM »
Assuming this is what you actually want to do, have some code ;)

Potato2

jj2007

  • Member
  • *****
  • Posts: 8735
  • Assembler is fun ;-)
    • MasmBasic
Re: SHGetIDListFromPath and SHBrowseForFolder
« Reply #2 on: August 25, 2012, 09:08:03 AM »
Code: [Select]
    .IF (eax == BFFM_INITIALIZED)
        invoke SendMessage, hwnd,BFFM_SETSELECTION,TRUE,lpData
    .ENDIF

Really cute trick, Tedd :t

In the meantime, I opted for GetOpenFileName, simply because it allows to set wildcards (\Masm32\*.asm), too. Thanks a lot for BFFM_SETSELECTION, it will serve in another occasion ;-)

Still, I'd like to see an occasion where the pidlRoot method yields useful results :icon_cool: