Win32::OLE messes up dialogs?

Discussion in 'Perl Misc' started by zorg.borg@gmail.com, Aug 31, 2005.

  1. Guest

    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";
     
    , Aug 31, 2005
    #1
    1. Advertising

  2. wrote in
    news::

    > 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, <DATA> line 164.

    > 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
    --
    A. Sinan Unur <>
    (reverse each component and remove .invalid for email address)

    comp.lang.perl.misc guidelines on the WWW:
    http://mail.augustmail.com/~tadmc/clpmisc/clpmisc_guidelines.html
     
    A. Sinan Unur, Aug 31, 2005
    #2
    1. Advertising

  3. Matt Garrish Guest

    "A. Sinan Unur" <> wrote in message
    news:Xns96C3B68F74F67asu1cornelledu@127.0.0.1...
    > wrote in
    > news::
    >
    >> 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:
    >


    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
     
    Matt Garrish, Sep 1, 2005
    #3
  4. "Matt Garrish" <> wrote in
    news:LrrRe.4402$:

    >
    > "A. Sinan Unur" <> wrote in message
    > news:Xns96C3B68F74F67asu1cornelledu@127.0.0.1...
    >> wrote in
    >> news::
    >>

    ....
    >>> 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:
    >>

    >
    > Did you uncomment the two lines?


    Ooops! I thought I had, but apparently not. I can also replicate it with
    XPP SP2.

    Sorry about that.

    Sinan

    --
    A. Sinan Unur <>
    (reverse each component and remove .invalid for email address)

    comp.lang.perl.misc guidelines on the WWW:
    http://mail.augustmail.com/~tadmc/clpmisc/clpmisc_guidelines.html
     
    A. Sinan Unur, Sep 1, 2005
    #4
  5. Guest

    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
     
    , Sep 1, 2005
    #5
  6. Guest

    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


    ______
     
    , Sep 2, 2005
    #6
    1. Advertising

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

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Guest
    Replies:
    2
    Views:
    578
    Guest
    Feb 2, 2004
  2. Patrick.O.Ige

    Ole ole

    Patrick.O.Ige, Jul 16, 2006, in forum: ASP .Net
    Replies:
    0
    Views:
    524
    Patrick.O.Ige
    Jul 16, 2006
  3. Drew Pihera
    Replies:
    0
    Views:
    666
    Drew Pihera
    Feb 4, 2004
  4. Mr Roboto
    Replies:
    1
    Views:
    266
    Petr Jakes
    Jun 14, 2006
  5. Lance Hoffmeyer
    Replies:
    0
    Views:
    274
    Lance Hoffmeyer
    Nov 17, 2003
Loading...

Share This Page