physi has asked for the wisdom of the Perl Monks concerning the following question:

Hi all,
I'm a little bit confused about the following behavior of the Win32::OLE Module.
My goal is to print a Word.doc by using Win32::OLE. This is quite simple.
But now I want to be able to select a file from a menu and put some more Information to the file, print it and store the additional information in a DB.

This little example shows the problem:

use strict; use Win32::OLE::Const 'Microsoft Word'; use Tk; #### my $mw = MainWindow->new; my $file = "c:\\TEMP\\test.doc"; my $Word = Win32::OLE->new('Word.Application', 'Quit'); $Word->Documents->Open($file) || die("Unable to open document", Win32: +:OLE->LastError()); my $last_printer=$Word->{ActivePrinter}; $Word->{ActivePrinter} ='PS2FILE'; $Word->ActiveDocument->PrintOut({ Background => 0, Append => 0, Range => wdPrintAllDocument, Item => wdPrintDocumentContent, Copies => 1, PageType => wdPrintAllPages, }); $Word->{ActivePrinter} = $last_printer; ### MainLoop;

The upper example works great

use strict; use Win32::OLE::Const 'Microsoft Word'; use Tk; my $mw = MainWindow->new; my $file = "c:\\TEMP\\test.doc"; my $Word = Win32::OLE->new('Word.Application', 'Quit'); $Word->Documents->Open($file) || die("Unable to open document", Win32: +:OLE->LastError()); my $last_printer=$Word->{ActivePrinter}; $Word->{ActivePrinter} ='PS2FILE'; $Word->ActiveDocument->PrintOut({ Background => 0, Append => 0, Range => wdPrintAllDocument, Item => wdPrintDocumentContent, Copies => 1, PageType => wdPrintAllPages, }); $Word->{ActivePrinter} = $last_printer; MainLoop;

and now it doesn't anymore

The only diffence between them is that I open a Tk MainWindow in the second example. Nothing else. You can bring the second one to run, if you delete either the  $mw = MainwWindow ... or the $Word->{ActivePrinter} ='PS2FILE' line.

So what's going on here ? Why does this OLE-set-a-Active-Printer Action doesn't work with a Tk widget ?

Any suggestions are very welcome ..

----------------------------------- --the good, the bad and the physi-- -----------------------------------

Replies are listed 'Best First'.
Re: Win32::OLE + Tk BUG ??
by c-era (Curate) on Jun 27, 2001 at 17:42 UTC
    Running through it quick, the line that it is dieing on is  $Word->{ActivePrinter} = $last_printer; If you remove that line everything runs fine.

    Using the debuger, it fails when making a call to Win32::OLE::Tie::STORE if you want to look at the exact line it is failing on, open 'path_to_lib/Win32/OLE/Lite.pm' and look at line 222 (that is where it hangs). I'm guessing that you are correct and this is a bug. You may want to contact the maintainers of the win32::ole module and let them know.

Re: Win32::OLE + Tk BUG ??
by mattr (Curate) on Jun 27, 2001 at 17:25 UTC
    You need someone else to answer your question besides me, but I did find this on the net which might help - TOCX - A Tcl/tk module that allows load and manipulation of 32 bit ActiveX/ OLE Controls. (Currently only available for 32 bit Windows platforms.) Server is very slow.