Win32::OLE doesn't really mix with using multiple threads inside Perl.
I think you *might* get it to work if you only ever use it inside a
single thread, and then also make sure you don't "use" Win32::OLE
at all, but just "require" it in the thread that uses it.  The
Initialize() call would have to be in the same thread.

This has been a very long standing issue with Win32::OLE.  Unfortunately
the interpreter cloning method doesn't work very well for supporting
Win32::OLE.  I once started working on it, but it turned out to be a
lot more complicated than I thought, and I ran out of time...  It
still is on the todo list, for whatever it is worth.

Cheers,
-Jan

PS: You may notice various places in the Win32::OLE code that seems
to be about thread safety.  This code is to support multiple Perl
interpreters embedded in a single process, even running in different
threads.  But it does not deal with the cloning of objects done by
the Perl internal thread mechanism and doesn't do all the required
bookkeeping to do so.

On Mon, 28 Nov 2005, Steven Manross wrote:
> Shouldn't your
>
> Win32::OLE->Initialize(Win32::OLE::COINIT_OLEINITIALIZE);
>
> Be after the use Win32::OLE qw (.....);
>
> As well, threading probably doesn't work all that well considering
> the single-threaded apartment model required for Outlook connections
> in Perl. But maybe someone can correct me if I've led you astray on
> this detail.
>
> Steven
>
On Thu, 24 Nov 2005, LeFevre, Ken wrote:
> I'm writing a program that monitors an Outlook mailbox and processes
> incoming e-mail in a given folder with a specified mailbox. When I
> run the module that does that actual access in the debugger, it
> works great. When I run the same module as a thread, I get the
> following error:
>
> retrying default method at /PerlApp/Win32/OLE/Lite.pm line 156.
> Win32::OLE(0.1403) error 0x800401f0: "CoInitialize has not been
> called" in METHOD/PROPERTYGET "" at /PerlApp/Cardinal/OutlookReader.pm
> line 209
>
> I'm running the program on Windows 2K Professional SP4 using perl
> 5.8.4.810 and Win32::OLE 0.1403 (the actual module is dated 11/5/2001
> 5:48 PM).
>
> Its really odd that I can access the Outlook profile enough to see all
> of the mailboxes attached to it and all the folders in each mailbox. I
> can even get the ID of each folder. The error occurs when I call
> GetFolderFromID.
>
> My calling sequence is:
>
> *     a service (compiled using perlsvc) that instantiates a
>       dispatcher thread and several worker threads
> *     a separate module (separate .pm) that represents the dispatcher
>       thread. This module instantiates an OutlookReader, retrieves the
>       contents of e-mails and places an entry on a Thread::Queue that
>       is instantiated in the service and passed in to the dispatcher
>       thread. It is also passed to each worker thread so they can
>       retrieve work from it.
>
> *     a separate module called OutlookReader. This object (which I've
>       attached) calls
>       Win32::OLE->Initialize(Win32::OLE::COINIT_OLEINITIALIZE) in its
>       BEGIN function. This is the module that throws the error.
>
> In my testing, I have a test driver that instantiates the object that
> represents the dispatcher thread, so the structural hierarchy is
> identical. The only difference is that no threads are involved.
>
> Any help, suggestions or ideas would be greatly appreciated.
>
> Ken



_______________________________________________
Perl-Win32-Users mailing list
Perl-Win32-Users@listserv.ActiveState.com
To unsubscribe: http://listserv.ActiveState.com/mailman/mysubs

Reply via email to