RE: OLE problem with Outlook
Jan: Thanks for the clarification. Even using require instead of use and only using Win32::OLE inside of a single thread, I was not able to get past the OLE error. I have since restructured my program to do OLE access from within the main thread of the service and then let worker threads handle the messages brought back. The service now works exactly as I had hoped it would. Ken -Original Message- From: Jan Dubois [mailto:[EMAIL PROTECTED] Sent: Tuesday, November 29, 2005 2:15 PM To: 'Steven Manross'; LeFevre, Ken; [EMAIL PROTECTED] Subject: RE: OLE problem with Outlook 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
RE: OLE problem with Outlook
Steven: Good suggestion. Unfortunately, it didn't help. Here's the revised version of my OutlookReader object. Thanks for your input. Ken -Original Message- From: Steven Manross [mailto:[EMAIL PROTECTED] Sent: Monday, November 28, 2005 11:40 PM To: LeFevre, Ken; [EMAIL PROTECTED] Subject: RE: OLE problem with Outlook 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 From: [EMAIL PROTECTED] [mailto:[EMAIL PROTECTED] On Behalf Of LeFevre, Ken Sent: Thursday, November 24, 2005 7:32 AM To: [EMAIL PROTECTED] Subject: OLE problem with Outlook 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 OutlookReader.pm Description: OutlookReader.pm ___ Perl-Win32-Users mailing list Perl-Win32-Users@listserv.ActiveState.com To unsubscribe: http://listserv.ActiveState.com/mailman/mysubs
RE: OLE problem with Outlook
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
RE: OLE problem with Outlook
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 From: [EMAIL PROTECTED] [mailto:[EMAIL PROTECTED] On Behalf Of LeFevre, Ken Sent: Thursday, November 24, 2005 7:32 AM To: [EMAIL PROTECTED] Subject: OLE problem with Outlook 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