| Newsgroups |
perl.libwin32 |
| Message-ID |
<[email protected]> |
Thu Jan 14 21:22:30 2010: Request 53484 was acted upon.
Transaction: Correspondence added by [email protected]
Queue: Win32-OLE
Subject: RE: [rt.cpan.org #53484] win32-ole breaks win32-gui-hyperlink on win64
Broken in: 0.1709
Severity: Unimportant
Owner: Nobody
Requestors: [email protected]
Status: open
Ticket <URL: http://rt.cpan.org/Ticket/Display.html?id=53484 >
On Thu, 07 Jan 2010, Paul Boldra via RT wrote:
> This dies with the message "Failed opening http://google.com
> ShellExecute(5) The requested lookup key was not found in any active
> activation context". Without the Win32::OLE->GetObject call, the
> Hyperlink->Launch call works.
This is happening because the ShellExecute() function in Windows, which
is what Hyperlink->Launch() is ultimately calling, only works correctly
inside a single-threaded apartment (STA).
The COM threading model is determined by whoever first calls
CoInitialize() in a particular thread.
Win32::OLE will choose a multithreaded apartment (MTA) model by default
because it avoids certain lockup problems in non-GUI Perl programs that
don't process the message loop regularly.
So if the first COM call made in your process is a Win32::OLE call, you
end up with a threading model that is incompatible with ShellExecute().
If you call ShellExecute() first, then Win32::OLE will notice that it is
already running inside a STA and not try to change the model.
If you don't want to rely on the ordering in which you make these calls,
then you can tell Win32::OLE explicitly to use a STA with
use Win32::OLE;
Win32::OLE->Initialize(Win32::OLE::COINIT_OLEINITIALIZE());
Cheers,
-Jan