Win32::OLE messes up dialogs?

Z

zorg.borg

Hi all,

i'm experiencing some strange problems when using the module Win32::OLE
together with windows dialogs.

In the following code snippet, I use an opendialog to pick a file. The
dialog works as expected: when a different file type is selected in the
combobox, the file listing changes accordingly.

However, if I uncomment the two Win32::OLE lines, the behaviour
changes: if
I pick any file type the file list becomes empty, not even showing
folders. The only way to have some file names displayed is typing
something like '*.*' in the file name box and then clicking 'Open'.

I first experienced this problem using Tk's getopenfile. I switched to
Win32::FileOp as I was thinking it was a Tk problem (as it had other
problem, like the handling od unicode file names).

I'm using activestate perl 810, Win32::FileOp 0.14.1.0 and Win32::OLE
0.1702.0.0, both from http://www.bribes.org/perl/, and I get the same
results under win98, win2000 and winxp sp2.

anyone experiencing the same thing? any suggestions?

thanks,
davide

[code snippet follows]

use strict;
use warnings;
#use Win32::OLE;
#my $EXC = Win32::OLE->GetActiveObject('Excel.Application');

use Win32::FileOp;
use File::Slurp;

my %parameters = (
title => 'test',
filters => [ 'log files' => '*.log;*.txt',
'Files .log' => '*.log',
'Files .txt' => '*.txt',
'All files' => '*.*'],
defaultfilter => 1,
dir => 'c:\\',
options => (OFN_HIDEREADONLY, OFN_OVERWRITEPROMPT),
);


my $file = OpenDialog %parameters;
exit unless ($file);
print "you picked $file\n";
my $contents=read_file($file);

print "----------------\n$contents\n--------------\n";
 
A

A. Sinan Unur

(e-mail address removed) wrote in
Hi all,

i'm experiencing some strange problems when using the module
Win32::OLE together with windows dialogs.

In the following code snippet, I use an opendialog to pick a file. The
dialog works as expected: when a different file type is selected in
the combobox, the file listing changes accordingly.

However, if I uncomment the two Win32::OLE lines, the behaviour
changes: if
I pick any file type the file list becomes empty, not even showing
folders. The only way to have some file names displayed is typing
something like '*.*' in the file name box and then clicking 'Open'.

I do not see this problem when I run the code you provided. However, I
do get a warning:

D:\Home\asu1\UseNet\clpmisc> fo
Odd number of elements in hash assignment at D:\Home\asu1\UseNet\clpmisc
\fo.pl line 9 said:
use strict;
use warnings;
#use Win32::OLE;
#my $EXC = Win32::OLE->GetActiveObject('Excel.Application');

use Win32::FileOp;
use File::Slurp;

my %parameters = (
title => 'test',
filters => [ 'log files' => '*.log;*.txt',
'Files .log' => '*.log',
'Files .txt' => '*.txt',
'All files' => '*.*'],
defaultfilter => 1,
dir => 'c:\\',
options => (OFN_HIDEREADONLY, OFN_OVERWRITEPROMPT),

The warning is probably caused by this line.

You probably want to use

options => OFN_HIDEREADONLY | OFN_OVERWRITEPROMPT,

instead.

Sinan
 
M

Matt Garrish

A. Sinan Unur said:
(e-mail address removed) wrote in


I do not see this problem when I run the code you provided. However, I
do get a warning:

Did you uncomment the two lines? I can get the same behaviour with build 813
on an XP SP2 box, even making the change you noted to the OP. If you call
the GetActiveObject method before OpenDialog the problem the OP noted
occurs.

I would hazard a guess from the documentation that this is the source of the
problem:

<quote>
There is a little problem with the underlying function. You have to
preallocate a buffer for the selected filenames and if the buffer is too
smallyou will not get any results. I've consulted this with the guys on
Perl-Win32-Users and there is not any nice solution. The default size of
buffer is 256B if the options do not include OFN_ALLOWMULTISELECT and 64KB
if they do. You may change the later via variable
$Win32::FileOp::BufferSize.
</quote>

If I set the ofn_allowmultiselect option the problem disappears (albeit you
get a different dialog, too). I couldn't tell you why the call to
GetActiveObject affects the buffer; you should probably try emailing the
author.

Matt
 
Z

zorg.borg

Sinan, thanks for the heads up on the options.

Matt, I don't know if the problems are related to the buffer. I would
guess they aren't, as the problem comes up only when using Win32::OLE.

I'll try to contact the authors

thanks,
davide
 
Z

zorg.borg

For the record:
here's what Jan Dubois replied to me in perl-win32-users on
activestate.com: it fixes the problem.

ciao
davide

----------------------------------
Please call

Win32::OLE-> Initialize(Win32::OLE::COINIT_OLEINITIALIZE);

*before* you instantiate any Win32::OLE objects. This should fix the
problem
with the Windows Common Dialogs. Since you are writing a program with
a message
loop there should be no bad side effects of running in apartment
threading mode.

Cheers,
-Jan


______
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,969
Messages
2,570,161
Members
46,705
Latest member
Stefkari24

Latest Threads

Top