Win32 FileOp BrowseForFolder - worries
am 20.11.2005 04:53:45 von g_m[ i am using:
ActiveState perl v.5.8.7, build 813,
on windows XP sp2, NTFS file system.
my question is about Win32::FileOp version 2.01 ]
I wanted a BrowseForFolder(), which Win32::GUI doesn't seem to have.
And I found that Win32::FolderOp has it, but not with access to "the new dialogue style"
( --- resizable, drag-and-drop capable, with CreateFolder button, ...etc )
So I tried to make it myself with Win32::API. And did not succeed.
But I did learn a lot.
I could see for example that one problem with Win32::FileOp
is that it doesn't even define BIF_NEWDIALOGSTYLE,
-- which happens to be == 0x0040.
And, as a matter of fact, the following does work
(for me anyway):
use Win32::FileOp qw(BrowseForFolder);
my $Folder = BrowseForFolder(" testing ", 0, 0x0040 );
if( defined $Folder ){ print "$Folder\n" } else { print "Canceled\n" }
(note: CSIDL_DESKTOP could be used for the 2nd argument,
but it would have to be explicitly imported, and 0 is easier to remember).
~
So here's my question.
The Microsoft documentation says this about BIF_NEWDIALOGSTYLE,
( and the related BIF_USENEWUI )
" To use this flag, you must call OleInitialize or CoInitialize
before calling SHBrowseForFolder "
And it doesn't say that about any of the other BIF_ flags.
So maybe there's a good reason why
BIF_NEWDIALOGSTYLE isn't defined in FileOp.
Maybe FileOp doesn't implement calling OleInitialize or CoInitialize.
(whatever that means...)
So why does 0x0040 work for me?
I read this somewhere:
# Kaki,
# >Is CoInitialize/OleInitialize called automatically in .Net?
# Yes
# Mattias
Now, I have to admit somewhere along here that
I just barely know what I'm talking about. That is to say,
I have been exposed to all this vocabulary before. But to what good,
I don't know. (not much though. i know that.)
And I fear that "something really bad has happened."
Dave Roth in "Win32 Perl Programming" makes this dire warning:
" A word of warning regarding the Win32::API extension: This extension
gives full, unlimited access to any DLL that a user can find. This can
easily cause damage to your computer by corrupting data files, the
Registry, and hard drives; other damage is possible. Before experimenting
with DLL functions you should consult the library's documentation. Before
doing something with this library, you should think very hard about
the results it can lead to. "
And a good tutorial i found: ( http://www.piotrkaluski.com/files/winguitest/docs/ch02s04.ht ml )
--had this to say, immediately after showing a couple of scripts
that looked perfectly harmless: ---
" If you are lucky your test script will crash immediately.
If not it will continue working, but something bad would happen
behind the scenes anyway. "
and
" If you run it and if you are lucky enough, the application which hosts
the list view control will crash immediately.
If not, you still have good chances that something really bad has happened. "
The first problem had to do with the subtleties of finding
and passing pointers to perl string-contents using pack and unpack.
The second had to do with the subtleties of marshalling.
In other words, I know just enough to be afraid,
and not enough to know if there's a good reason to be.
( that is, --about whether using 0x0040 as the 3rd argument to
Win32::FileOp::BrowseForFolder() is ok,-- as it seems to be for me,
--or a really bad idea!! )
~greg