Re: Does Win32::OLE suck?
by batkins (Chaplain) on Jan 24, 2003 at 23:44 UTC
|
Yes, it sucks, but only because OLE does. :)
Seriously, Win32::OLE isn't too bad. It doesn't need much documentation because it has different capabilities depending on the object created with it. Visual Basic code can be easily converted to Win32::OLE code. There was a section in Learning Perl on Win32 about that very topic.
Bill | [reply] |
|
| [reply] |
Re: Does Win32::OLE suck?
by grantm (Parson) on Jan 25, 2003 at 08:43 UTC
|
Will I be forced to learn how to code Visual Basic?
You might have to learn how to read it at least. One way to get going with Win32::OLE for MS Word is to use the macro record facility in Word to record some keystrokes (eg: edit-select all); then hit Alt-F11 to open up the macro editor; the convert VB to Perl by changing '.' to '->', putting curly braces around property names and putting $ signs in the right places :-)
To be pedantic, the macro language in Word is VBA which is different from 'full-blown' VB and different again from VBScript.
| [reply] |
Re: Does Win32::OLE suck?
by Mr. Muskrat (Canon) on Jan 24, 2003 at 23:42 UTC
|
Win32::OLE is supposed to be easy to use and understand? Only if M$ had made OLE easy to use and understand!
OTOH, Win32::OLE is not all that difficult to learn or use. Have you tried reading the fine documentation that comes with it?
| [reply] |
Re: Does Win32::OLE suck?
by ibanix (Hermit) on Jan 25, 2003 at 09:27 UTC
|
Win32::OLE is the only way to write perl code that interfaces with Active Directory (see: ADSI) at the moment.
You should keep this wise saying in mind:
There is no glory in the easy victory.
ibanix
$ echo '$0 & $0 &' > foo; chmod a+x foo; foo; | [reply] [d/l] |
Re: Does Win32::OLE suck?
by Zero_Flop (Pilgrim) on Jan 25, 2003 at 05:55 UTC
|
As mentioned WIN32::OLE only sucks as much as OLE sucks!
I actually use it all the time. What you have to understand is that
you have access to all the OLE that would be availabe in VB. If you
can not "select all" in win32::ole you will not be able to do it in
VB.
to select all you the OLE is "Selection.WholeStory" or perlish Selection->WholeStory
If you need some tips let me know | [reply] |
Re: Does Win32::OLE suck?
by Nitrox (Chaplain) on Jan 25, 2003 at 16:43 UTC
|
When it comes to threading, Win32::OLE still has some major issues. There's a webpage on the AS site that lists Win32::OLE as being thread-safe (read it HERE), which should be taken with a grain of salt.
As it turns out, Win32::OLE is only thread safe when "used in a process that hosts multiple Perl interpreters, each compiling their own scripts".
So when it comes to an embedded Perl project I've been working on which utilizes 5.8 threads, I've found that a COM object created in one thread can not be shared (whether by 'cloning' or by explicitly calling share()) with other threads.
I've submitted this bug to the author so hopefully we'll see a new release soon. Unfortunately he has listed it as a simple "Enhancement" request, which I tend to disagree with.
-Nitrox | [reply] |
Re: Does Win32::OLE suck?
by LameNerd (Hermit) on Jan 25, 2003 at 00:28 UTC
|
thanks for your replies. But the documentation does not seem to cover
doing a select all operation with MS Word. If I am wrong please
point me in the right direction.
Thanks | [reply] |
|
Win32::OLE only offers you the method to control another application, but it does not document what you can do with the other application. The Win32::OLE manpage has (I think I remember) a list of common links
on where to obtain documentation for the most used programs (MS Office). A search with Google will turn up a lot of Visual Basic code that can be ported almost verbatim to Perl.
' VB Code, written without either VB or MS Word available to check
set objWord = CreateObject("Word.Application")
objWord.DocumentNew()
objWord.Document.Text = "Hello World"
objWord.Document.SelectAll()
# Perl code
use strict;
my $word = Win32::OLE->new('Word.Application');
$word->DocumentNew();
$word->{Document}->{Text} = "Hello World";
$word->{Document}->SelectAll;
perl -MHTTP::Daemon -MHTTP::Response -MLWP::Simple -e ' ; # The
$d = new HTTP::Daemon and fork and getprint $d->url and exit;#spider
($c = $d->accept())->get_request(); $c->send_response( new #in the
HTTP::Response(200,$_,$_,qq(Just another Perl hacker\n))); ' # web
| [reply] [d/l] [select] |