1. SHBrowseForFolder

Derek Parnell wrote:
> I don't remember getting this. Anyhow, there is a Windows API function 
> all
> "SHBrowseForFolder". It looks a bit complicated to use so I'll do some
> experiments with it first. Feel free to do some research of your own 
> though.
Derek,

I too have worked with this API and got bogged down when it came to 
retrieving the full path from the ITEMIDLIST structure.  Here's the code 
up to where I left off (I was having trouble getting the length of the 
first item in the list):

include win32lib.ew
with trace

atom xSHBrowseForFolder, binfo, result, rtn_code, cb1, cb2
sequence folder, folder_path

xSHBrowseForFolder = registerw32Function(shell32, "SHBrowseForFolder", 
{C_POINTER}, C_POINTER)

global constant
bfOwner = allot( Long ),
bfpidlRoot = allot( Long ),
bfDisplayName = allot( Lpsz ),
bfTitle = allot( Lpsz ),
bfFlags = allot( Long ),
bfFunction = allot( Long ),
bfParam = allot( Long ),
bfImage = allot( Long ),
SIZEOF_BROWSEINFO = allotted_size()

binfo = acquire_mem(0, SIZEOF_BROWSEINFO)

store( binfo, bfOwner, 0)
store( binfo, bfpidlRoot, NULL)
store( binfo, bfDisplayName, "")
store( binfo, bfTitle, "Select a Folder")
store( binfo, bfFlags, NULL)
store( binfo, bfFunction, NULL)
store( binfo, bfParam, NULL)
store( binfo, bfImage, NULL)

result = w32Func(xSHBrowseForFolder, {binfo})
folder = fetch( binfo, bfDisplayName )
trace(1)
cb1 = peek(result)
cb2 = peek(result)
folder_path = peek({result+2,cb1-2})
rtn_code = message_box("Folder: " & folder_path, "Test", MB_OK)
release_mem(binfo)

With this code the dialog does appear and you can select a folder but I 
can't seem to figure out how to get the path from "result".  I will keep 
plugging away and maybe between the two of us we can figure it out.  I 
have some places where I would also like to select a folder.

Jonas

new topic     » topic index » view message » categorize

2. Re: SHBrowseForFolder

> Derek Parnell wrote:
>> I don't remember getting this. Anyhow, there is a Windows API function 
>> all
>> "SHBrowseForFolder". It looks a bit complicated to use so I'll do some
>> experiments with it first. Feel free to do some research of your own 
>> though.
> Derek,

> I too have worked with this API and got bogged down when it came to 
> retrieving the full path from the ITEMIDLIST structure.  Here's the code 
> up to where I left off (I was having trouble getting the length of the 
> first item in the list):

> include win32lib.ew
> with trace

> atom xSHBrowseForFolder, binfo, result, rtn_code, cb1, cb2
> sequence folder, folder_path

> xSHBrowseForFolder = registerw32Function(shell32, "SHBrowseForFolder", 
> {C_POINTER}, C_POINTER)

> global constant
> bfOwner = allot( Long ),
> bfpidlRoot = allot( Long ),
> bfDisplayName = allot( Lpsz ),
> bfTitle = allot( Lpsz ),
> bfFlags = allot( Long ),
> bfFunction = allot( Long ),
> bfParam = allot( Long ),
> bfImage = allot( Long ),
> SIZEOF_BROWSEINFO = allotted_size()

> binfo = acquire_mem(0, SIZEOF_BROWSEINFO)

> store( binfo, bfOwner, 0)
> store( binfo, bfpidlRoot, NULL)
> store( binfo, bfDisplayName, "")
> store( binfo, bfTitle, "Select a Folder")
> store( binfo, bfFlags, NULL)
> store( binfo, bfFunction, NULL)
> store( binfo, bfParam, NULL)
> store( binfo, bfImage, NULL)

> result = w32Func(xSHBrowseForFolder, {binfo})
> folder = fetch( binfo, bfDisplayName )
> trace(1)
> cb1 = peek(result)
> cb2 = peek(result)
> folder_path = peek({result+2,cb1-2})
> rtn_code = message_box("Folder: " & folder_path, "Test", MB_OK)
> release_mem(binfo)

> With this code the dialog does appear and you can select a folder but I 
> can't seem to figure out how to get the path from "result".  I will keep 
> plugging away and maybe between the two of us we can figure it out.  I 
> have some places where I would also like to select a folder.

> Jonas

You need to user SHGetPathFromIDList (from user32.dll, takes a LONG and a
string pointer) on "result", something like:

folder = allocate_string(repeat(512,0))
if w32Func(xSHGetPathFromIDList,{result,folder}} then
   --the string pointed to by folder now contains the path
end if

That code is totally untested because I really want to get some sleep
soon :) I'll try and do it properly sometime tomorrow :)

Thomas Parslow (PatRat) ICQ #:26359483
Rat Software
http://www.rat-software.com/
Please leave quoted text in place when replying

new topic     » goto parent     » topic index » view message » categorize

3. Re: SHBrowseForFolder

> I too have worked with this API and got bogged down when it came to
> retrieving the full path from the ITEMIDLIST structure.  Here's the code 
> up to where I left off (I was having trouble getting the length of the 
> first item in the list):

Hi,

I've modified your code so that it uses SHGetPathFromIDList to
convert the result (tested and working):

include win32lib.ew
with trace

atom binfo, result,memfolder
sequence folder

constant xSHBrowseForFolder = registerw32Function(shell32, "SHBrowseForFolder", 
{C_POINTER}, C_POINTER)

constant xSHGetPathFromIDList =
registerw32Function(shell32,"SHGetPathFromIDList",{C_ULONG,C_POINTER},C_ULONG)

global constant
bfOwner = allot( Long ),
bfpidlRoot = allot( Long ),
bfDisplayName = allot( Lpsz ),
bfTitle = allot( Lpsz ),
bfFlags = allot( Long ),
bfFunction = allot( Long ),
bfParam = allot( Long ),
bfImage = allot( Long ),
SIZEOF_BROWSEINFO = allotted_size()

binfo = acquire_mem(0, SIZEOF_BROWSEINFO)

store( binfo, bfOwner, 0)
store( binfo, bfpidlRoot, NULL)
store( binfo, bfDisplayName, "")
store( binfo, bfTitle, "Select a Folder")
store( binfo, bfFlags, NULL)
store( binfo, bfFunction, NULL)
store( binfo, bfParam, NULL)
store( binfo, bfImage, NULL)

result = w32Func(xSHBrowseForFolder, {binfo})

memfolder= allocate_string(repeat(512,0))
if w32Func(xSHGetPathFromIDList,{result,memfolder}) then
   --the string pointed to by folder now contains the path
   folder = peek_string(memfolder)
else
   folder = ""
end if
free(memfolder)
release_mem(binfo)

if message_box("Folder: " & folder, "Test", MB_OK) then end if

Thomas Parslow (PatRat) ICQ #:26359483
Rat Software
http://www.rat-software.com/
Please leave quoted text in place when replying

new topic     » goto parent     » topic index » view message » categorize

4. Re: SHBrowseForFolder

Thomas, etc:

Is this the latest anyone has done for the browsing for a folder dialog?  It
crashes for me under both Win32Lib 55.1 & 57.5, with an illegal operation
error, when I look deeper than about 2 or 3 levels:

EXW caused an invalid page fault in
module KERNEL32.DLL at 015f:bff7a128.
Registers:
EAX=036e6954 CS=015f EIP=bff7a128 EFLGS=00010202
EBX=007520bc SS=0167 ESP=0056fb44 EBP=0056fb78
ECX=62694c32 DS=0167 ESI=007520ac FS=1347
EDX=4950415c ES=0167 EDI=036e6964 GS=0000
Bytes at CS:EIP:
89 51 08 8b 53 08 8b 43 04 8d 8b 0b 10 00 00 c1
Stack dump:
0056fb78 007520ac 00650000 00594dcc bff7b30e 00650000 007520ac 00000010
00000200 00650000 03280000 00594dcc 007520ac 0056fba6 00401a1f 00650000

Dan Moyer

----- Original Message -----
From: "Thomas Parslow (PatRat)" <patrat at rat-software.com>
To: "EUforum" <EUforum at topica.com>
Sent: Thursday, September 06, 2001 3:02 AM
Subject: Re[2]: SHBrowseForFolder


>
> > Hi Thomas,
>
> > Too bad.
> > On an NT4 platform i sporadically get a:
> > "The instruction at 00417608 referenced memory at 455c3a4c. The memory
could not be written"
>
> > This seems to occur when the selected folder is deeply nested (say over
4-5 levels) but not always.
>
> > Henri
>
> Hi,
>
> I seem to get that on deeply nested folders as well. I tracked down
> the crash to the "free(foldermem)" line. It seems to work if you use
> win32lib's memory management routines...
>
> This version works for me even with very deeply nested folders:
>
> include win32lib.ew
> with trace
>
> atom binfo, result,memfolder
> sequence folder
>
> constant xSHBrowseForFolder = registerw32Function(shell32,
"SHBrowseForFolder",
> {C_POINTER}, C_POINTER)
>
> constant xSHGetPathFromIDList =
registerw32Function(shell32,"SHGetPathFromIDList",{C_ULONG,C_POINTER},C_ULON
G)
>
> global constant
> bfOwner = allot( Long ),
> bfpidlRoot = allot( Long ),
> bfDisplayName = allot( Lpsz ),
> bfTitle = allot( Lpsz ),
> bfFlags = allot( Long ),
> bfFunction = allot( Long ),
> bfParam = allot( Long ),
> bfImage = allot( Long ),
> SIZEOF_BROWSEINFO = allotted_size()
>
> binfo = acquire_mem(0, SIZEOF_BROWSEINFO)
>
> store( binfo, bfOwner, 0)
> store( binfo, bfpidlRoot, NULL)
> store( binfo, bfDisplayName, "")
> store( binfo, bfTitle, "Select a Folder")
> store( binfo, bfFlags, NULL)
> store( binfo, bfFunction, NULL)
> store( binfo, bfParam, NULL)
> store( binfo, bfImage, NULL)
>
> result = w32Func(xSHBrowseForFolder, {binfo})
>
> memfolder= acquire_mem(0,repeat(512,0))
> if w32Func(xSHGetPathFromIDList,{result,memfolder}) then
>    --the string pointed to by folder now contains the path
>    folder = peek_string(memfolder)
> else
>    folder = ""
> end if
> release_mem(memfolder)
> release_mem(binfo)
>
> if message_box("Folder: " & folder, "Test", MB_OK) then end if
>
> Thomas Parslow (PatRat) ICQ #:26359483
> Rat Software
> http://www.rat-software.com/
> Please leave quoted text in place when replying
>

new topic     » goto parent     » topic index » view message » categorize

5. Re: SHBrowseForFolder

Thomas,

Actually, it may not be the depth of a folder that gives me a problem, but
rather the number of folders;  I can get 4 deep in a directory that has 121
folders total, but crash at 2 deep in a folder that has 130 folders total.

Dan Moyer

----- Original Message -----
From: "Dan Moyer" <DANIELMOYER at prodigy.net>
To: <EUforum at topica.com>
Subject: Re: SHBrowseForFolder


> Thomas, etc:
>
> Is this the latest anyone has done for the browsing for a folder dialog?
It
> crashes for me under both Win32Lib 55.1 & 57.5, with an illegal operation
> error, when I look deeper than about 2 or 3 levels:
>
> EXW caused an invalid page fault in
> module KERNEL32.DLL at 015f:bff7a128.
> Registers:
> EAX=036e6954 CS=015f EIP=bff7a128 EFLGS=00010202
> EBX=007520bc SS=0167 ESP=0056fb44 EBP=0056fb78
> ECX=62694c32 DS=0167 ESI=007520ac FS=1347
> EDX=4950415c ES=0167 EDI=036e6964 GS=0000
> Bytes at CS:EIP:
> 89 51 08 8b 53 08 8b 43 04 8d 8b 0b 10 00 00 c1
> Stack dump:
> 0056fb78 007520ac 00650000 00594dcc bff7b30e 00650000 007520ac 00000010
> 00000200 00650000 03280000 00594dcc 007520ac 0056fba6 00401a1f 00650000
>
> Dan Moyer
>
> ----- Original Message -----
> From: "Thomas Parslow (PatRat)" <patrat at rat-software.com>
> To: "EUforum" <EUforum at topica.com>
> Sent: Thursday, September 06, 2001 3:02 AM
> Subject: Re[2]: SHBrowseForFolder
>
>
> >
> > > Hi Thomas,
> >
> > > Too bad.
> > > On an NT4 platform i sporadically get a:
> > > "The instruction at 00417608 referenced memory at 455c3a4c. The memory
> could not be written"
> >
> > > This seems to occur when the selected folder is deeply nested (say
over
> 4-5 levels) but not always.
> >
> > > Henri
> >
> > Hi,
> >
> > I seem to get that on deeply nested folders as well. I tracked down
> > the crash to the "free(foldermem)" line. It seems to work if you use
> > win32lib's memory management routines...
> >
> > This version works for me even with very deeply nested folders:
> >
> > include win32lib.ew
> > with trace
> >
> > atom binfo, result,memfolder
> > sequence folder
> >
> > constant xSHBrowseForFolder = registerw32Function(shell32,
> "SHBrowseForFolder",
> > {C_POINTER}, C_POINTER)
> >
> > constant xSHGetPathFromIDList =
>
registerw32Function(shell32,"SHGetPathFromIDList",{C_ULONG,C_POINTER},C_ULON
> G)
> >
> > global constant
> > bfOwner = allot( Long ),
> > bfpidlRoot = allot( Long ),
> > bfDisplayName = allot( Lpsz ),
> > bfTitle = allot( Lpsz ),
> > bfFlags = allot( Long ),
> > bfFunction = allot( Long ),
> > bfParam = allot( Long ),
> > bfImage = allot( Long ),
> > SIZEOF_BROWSEINFO = allotted_size()
> >
> > binfo = acquire_mem(0, SIZEOF_BROWSEINFO)
> >
> > store( binfo, bfOwner, 0)
> > store( binfo, bfpidlRoot, NULL)
> > store( binfo, bfDisplayName, "")
> > store( binfo, bfTitle, "Select a Folder")
> > store( binfo, bfFlags, NULL)
> > store( binfo, bfFunction, NULL)
> > store( binfo, bfParam, NULL)
> > store( binfo, bfImage, NULL)
> >
> > result = w32Func(xSHBrowseForFolder, {binfo})
> >
> > memfolder= acquire_mem(0,repeat(512,0))
> > if w32Func(xSHGetPathFromIDList,{result,memfolder}) then
> >    --the string pointed to by folder now contains the path
> >    folder = peek_string(memfolder)
> > else
> >    folder = ""
> > end if
> > release_mem(memfolder)
> > release_mem(binfo)
> >
> > if message_box("Folder: " & folder, "Test", MB_OK) then end if
> >
> > Thomas Parslow (PatRat) ICQ #:26359483
> > Rat Software
> > http://www.rat-software.com/
> > Please leave quoted text in place when replying
> >
>

new topic     » goto parent     » topic index » view message » categorize

6. Re: SHBrowseForFolder

Thomas, etc:

Is this the latest anyone has done for the browsing for a folder dialog?  It
crashes for me under both Win32Lib 55.1 & 57.5, with an illegal operation
error, when I look deeper than about 2 or 3 levels:

EXW caused an invalid page fault in
module KERNEL32.DLL at 015f:bff7a128.
Registers:
EAX=036e6954 CS=015f EIP=bff7a128 EFLGS=00010202
EBX=007520bc SS=0167 ESP=0056fb44 EBP=0056fb78
ECX=62694c32 DS=0167 ESI=007520ac FS=1347
EDX=4950415c ES=0167 EDI=036e6964 GS=0000
Bytes at CS:EIP:
89 51 08 8b 53 08 8b 43 04 8d 8b 0b 10 00 00 c1
Stack dump:
0056fb78 007520ac 00650000 00594dcc bff7b30e 00650000 007520ac 00000010
00000200 00650000 03280000 00594dcc 007520ac 0056fba6 00401a1f 00650000

Dan Moyer

----- Original Message -----
From: "Thomas Parslow (PatRat)" <patrat at rat-software.com>
To: "EUforum" <EUforum at topica.com>
Sent: Thursday, September 06, 2001 3:02 AM
Subject: Re[2]: SHBrowseForFolder


>
> > Hi Thomas,
>
> > Too bad.
> > On an NT4 platform i sporadically get a:
> > "The instruction at 00417608 referenced memory at 455c3a4c. The memory
could not be written"
>
> > This seems to occur when the selected folder is deeply nested (say over
4-5 levels) but not always.
>
> > Henri
>
> Hi,
>
> I seem to get that on deeply nested folders as well. I tracked down
> the crash to the "free(foldermem)" line. It seems to work if you use
> win32lib's memory management routines...
>
> This version works for me even with very deeply nested folders:
>
> include win32lib.ew
> with trace
>
> atom binfo, result,memfolder
> sequence folder
>
> constant xSHBrowseForFolder = registerw32Function(shell32,
"SHBrowseForFolder",
> {C_POINTER}, C_POINTER)
>
> constant xSHGetPathFromIDList =
registerw32Function(shell32,"SHGetPathFromIDList",{C_ULONG,C_POINTER},C_ULON
G)
>
> global constant
> bfOwner = allot( Long ),
> bfpidlRoot = allot( Long ),
> bfDisplayName = allot( Lpsz ),
> bfTitle = allot( Lpsz ),
> bfFlags = allot( Long ),
> bfFunction = allot( Long ),
> bfParam = allot( Long ),
> bfImage = allot( Long ),
> SIZEOF_BROWSEINFO = allotted_size()
>
> binfo = acquire_mem(0, SIZEOF_BROWSEINFO)
>
> store( binfo, bfOwner, 0)
> store( binfo, bfpidlRoot, NULL)
> store( binfo, bfDisplayName, "")
> store( binfo, bfTitle, "Select a Folder")
> store( binfo, bfFlags, NULL)
> store( binfo, bfFunction, NULL)
> store( binfo, bfParam, NULL)
> store( binfo, bfImage, NULL)
>
> result = w32Func(xSHBrowseForFolder, {binfo})
>
> memfolder= acquire_mem(0,repeat(512,0))
> if w32Func(xSHGetPathFromIDList,{result,memfolder}) then
>    --the string pointed to by folder now contains the path
>    folder = peek_string(memfolder)
> else
>    folder = ""
> end if
> release_mem(memfolder)
> release_mem(binfo)
>
> if message_box("Folder: " & folder, "Test", MB_OK) then end if
>
> Thomas Parslow (PatRat) ICQ #:26359483
> Rat Software
> http://www.rat-software.com/
> Please leave quoted text in place when replying
>

new topic     » goto parent     » topic index » view message » categorize

7. Re: SHBrowseForFolder

Thomas,

Actually, it may not be the depth of a folder that gives me a problem, but
rather the number of folders;  I can get 4 deep in a directory that has 121
folders total, but crash at 2 deep in a folder that has 130 folders total.

Dan Moyer

----- Original Message -----
From: "Dan Moyer" <DANIELMOYER at prodigy.net>
To: <EUforum at topica.com>
Subject: Re: SHBrowseForFolder


> Thomas, etc:
>
> Is this the latest anyone has done for the browsing for a folder dialog?
It
> crashes for me under both Win32Lib 55.1 & 57.5, with an illegal operation
> error, when I look deeper than about 2 or 3 levels:
>
> EXW caused an invalid page fault in
> module KERNEL32.DLL at 015f:bff7a128.
> Registers:
> EAX=036e6954 CS=015f EIP=bff7a128 EFLGS=00010202
> EBX=007520bc SS=0167 ESP=0056fb44 EBP=0056fb78
> ECX=62694c32 DS=0167 ESI=007520ac FS=1347
> EDX=4950415c ES=0167 EDI=036e6964 GS=0000
> Bytes at CS:EIP:
> 89 51 08 8b 53 08 8b 43 04 8d 8b 0b 10 00 00 c1
> Stack dump:
> 0056fb78 007520ac 00650000 00594dcc bff7b30e 00650000 007520ac 00000010
> 00000200 00650000 03280000 00594dcc 007520ac 0056fba6 00401a1f 00650000
>
> Dan Moyer
>
> ----- Original Message -----
> From: "Thomas Parslow (PatRat)" <patrat at rat-software.com>
> To: "EUforum" <EUforum at topica.com>
> Sent: Thursday, September 06, 2001 3:02 AM
> Subject: Re[2]: SHBrowseForFolder
>
>
> > > Hi Thomas,
> >
> > > Too bad.
> > > On an NT4 platform i sporadically get a:
> > > "The instruction at 00417608 referenced memory at 455c3a4c. The memory
> could not be written"
> >
> > > This seems to occur when the selected folder is deeply nested (say
over
> 4-5 levels) but not always.
> >
> > > Henri
> >
> > Hi,
> >
> > I seem to get that on deeply nested folders as well. I tracked down
> > the crash to the "free(foldermem)" line. It seems to work if you use
> > win32lib's memory management routines...
> >
> > This version works for me even with very deeply nested folders:
> >
> > include win32lib.ew
> > with trace
> >
> > atom binfo, result,memfolder
> > sequence folder
> >
> > constant xSHBrowseForFolder = registerw32Function(shell32,
> "SHBrowseForFolder",
> > {C_POINTER}, C_POINTER)
> >
> > constant xSHGetPathFromIDList =
>
registerw32Function(shell32,"SHGetPathFromIDList",{C_ULONG,C_POINTER},C_ULON
> G)
> >
> > global constant
> > bfOwner = allot( Long ),
> > bfpidlRoot = allot( Long ),
> > bfDisplayName = allot( Lpsz ),
> > bfTitle = allot( Lpsz ),
> > bfFlags = allot( Long ),
> > bfFunction = allot( Long ),
> > bfParam = allot( Long ),
> > bfImage = allot( Long ),
> > SIZEOF_BROWSEINFO = allotted_size()
> >
> > binfo = acquire_mem(0, SIZEOF_BROWSEINFO)
> >
> > store( binfo, bfOwner, 0)
> > store( binfo, bfpidlRoot, NULL)
> > store( binfo, bfDisplayName, "")
> > store( binfo, bfTitle, "Select a Folder")
> > store( binfo, bfFlags, NULL)
> > store( binfo, bfFunction, NULL)
> > store( binfo, bfParam, NULL)
> > store( binfo, bfImage, NULL)
> >
> > result = w32Func(xSHBrowseForFolder, {binfo})
> >
> > memfolder= acquire_mem(0,repeat(512,0))
> > if w32Func(xSHGetPathFromIDList,{result,memfolder}) then
> >    --the string pointed to by folder now contains the path
> >    folder = peek_string(memfolder)
> > else
> >    folder = ""
> > end if
> > release_mem(memfolder)
> > release_mem(binfo)
> >
> > if message_box("Folder: " & folder, "Test", MB_OK) then end if
> >
> > Thomas Parslow (PatRat) ICQ #:26359483
> > Rat Software
> > http://www.rat-software.com/
> > Please leave quoted text in place when replying
> >
>

new topic     » goto parent     » topic index » view message » categorize

Search



Quick Links

User menu

Not signed in.

Misc Menu