🚀 go-pugleaf

RetroBBS NetNews Server

Inspired by RockSolid Light RIP Retro Guy

Article View: borland.public.cppbuilder.nativeapi
Article #13288

Re: SHBrowseForFolder, BFFM_SETSELECTION, UNC paths (Windows bug?)

#13288
From: Dennis Jones
Date: Sat, 18 Oct 2003 06:16
52 lines
3083 bytes
"Remy Lebeau (TeamB)" <gambit47.no.spam@no.spam.yahoo.com> wrote in message
news:3f90cbe6@newsgroups.borland.com...
>
> "Dennis Jones" <djones@nospam.com> wrote in message
> news:3f90be9d@newsgroups.borland.com...
>
> > My latest version of code that is SUPPOSED to work follows.
> > Does anyone know why this does not work?  Is there a bug in
> > Windows that prevents this code form functioning properly?
>
> I tried your code as-is, under Win98, Win2K, and XP.  They all worked fine
> for me.  I had no troubles initializing the dialog using UNC paths when
they
> are converted to PIDLs first, other then a few secnods delay while the OS
> resolved the PIDLs for use.

Dang.  It must be an NT4 glitch.  When I execute this code in NT4, it
*always* highlights the "Desktop" item (which is at the root of the tree),
and expands the "Desktop\\Network Neighborhood\\Entire Network" branch.

> With that in mind, I would like to make some extra comments:
>
> 1) you have several variables that are not initialized before use,
> particularly your buffers.

In my defense, I didn't write any of this code (except for the button click
event)...it came straight from the newsgroup archives, and since I am just
trying to get it to "work," I made no attempt to clean it up or fix any
bugs.

> 2) for character buffers, you should allocate (MAX_PATH+1) characters, in
> case you happen to try working with paths that are exactly MAX_PATH
> characters in size, so that you always have extra room for a
> null-terminator.
>
> 3) you should never use strcpy() because it does not protect against
buffer
> overflows.  Use either strncpy() or StrLCopy() instead.

Yes, and normally I would be careful to test for those kinds of errors, but
this is really just quick and dirty proof-of-concept code at the moment.

> 4) to cut down on some code complexity, you can use CoTaskMemFree()
instead
> of using SHGetMalloc() and IMalloc::Free() manually.  CoTaskMemFree() uses
> IMalloc internally.

Thank you.  I am not very familiar with the Shell API, so that is good to
know.

- Dennis
Technical Details
Message-ID: <3f90daa2$1@newsgroups.borland.com>
Path: arc1-ca.pugleaf.net!archiver1.google.com!news2.google.com!news.maxwell.syr.edu!newsfeed00.sul.t-online.de!newsfeed01.sul.t-online.de!t-online.de!newsgroups.borland.com!not-for-mail
References: <3f90be9d@newsgroups.borland.com> <3f90cbe6@newsgroups.borland.com>

Show Full Headers
Complete Article Headers
X-Google-Language: ENGLISH,ASCII-7-bit
X-Google-Thread: 10cc67,8dd37dadfc9c37c0
X-Google-Attributes: gid10cc67,public
X-Google-ArrivalTime: 2003-10-17 23:38:52 PST
From: "Dennis Jones" <djones@nospam.com>
Newsgroups: borland.public.cppbuilder.nativeapi
References: <3f90be9d@newsgroups.borland.com> <3f90cbe6@newsgroups.borland.com>
Subject: Re: SHBrowseForFolder, BFFM_SETSELECTION, UNC paths (Windows bug?)
Date: Fri, 17 Oct 2003 23:16:04 -0700
Lines: 54
X-Priority: 3
X-MSMail-Priority: Normal
X-Newsreader: Microsoft Outlook Express 6.00.2800.1158
X-MimeOLE: Produced By Microsoft MimeOLE V6.00.2800.1165
NNTP-Posting-Host: 204.200.27.7
Message-ID: <3f90daa2$1@newsgroups.borland.com>
X-Trace: newsgroups.borland.com 1066457762 204.200.27.7 (17 Oct 2003 23:16:02 -0700)
Path: arc1-ca.pugleaf.net!archiver1.google.com!news2.google.com!news.maxwell.syr.edu!newsfeed00.sul.t-online.de!newsfeed01.sul.t-online.de!t-online.de!newsgroups.borland.com!not-for-mail