Cannot initialize OLE

Previous Topic Next Topic
 
classic Classic list List threaded Threaded
4 messages Options
Reply | Threaded
Open this post in threaded view
|

Cannot initialize OLE

Daniele Esposti
Hi all,

if I run my application (a wxPython frame with a wx.Activex Flash
component) with the python.exe in pythonnet folder its work like expected.
Instead, if I run my application with the standard Python interpreter,
with clr.pyd in DLLs folder and Python.Runtime.dll in the same
interpreter folder, I get a warnings says Cannot initialize OLE and the
ActiveX is locked.
I'm using Python 2.5.2 on a Windows XP SP3 machine, PythonNet
2.0-alpha2-clr2.0 compiled with VisualStudio Express 2008.

Have I missing something ? Only clr.pyd and Python.Runtime.dll are
needed or there are others resources to copy in Python interpreter folder ?

Thanks in advance
_________________________________________________
Python.NET mailing list - [hidden email]
http://mail.python.org/mailman/listinfo/pythondotnet
Reply | Threaded
Open this post in threaded view
|

Re: Cannot initialize OLE

Brian Lloyd-5
This probably has to do with the threading model being auto-magically
set for you when the CLR is cranked up, absent any prior initialization.

The managed version of python.exe is able to set the threading model
(to MTA I believe) because it is a managed executable. When you import
clr via the standard python.exe, you are probably getting the default
model (STA). I could have those backwards - its been a while ;)

If you are using the win32com extensions, you might be able to import
those, set the threading model for the process, then import clr. Not
sure if that will work, but its worth a shot. I don't think there is
any way to change the threading model once it's set.

-Brian


On 12/1/08 8:53 AM, "Daniele Esposti" <[hidden email]> wrote:

> Hi all,
>
> if I run my application (a wxPython frame with a wx.Activex Flash
> component) with the python.exe in pythonnet folder its work like expected.
> Instead, if I run my application with the standard Python interpreter,
> with clr.pyd in DLLs folder and Python.Runtime.dll in the same
> interpreter folder, I get a warnings says Cannot initialize OLE and the
> ActiveX is locked.
> I'm using Python 2.5.2 on a Windows XP SP3 machine, PythonNet
> 2.0-alpha2-clr2.0 compiled with VisualStudio Express 2008.
>
> Have I missing something ? Only clr.pyd and Python.Runtime.dll are
> needed or there are others resources to copy in Python interpreter folder ?
>
> Thanks in advance
> _________________________________________________
> Python.NET mailing list - [hidden email]
> http://mail.python.org/mailman/listinfo/pythondotnet

--------------------------------
Brian Lloyd         540.845.2975

[hidden email]

_________________________________________________
Python.NET mailing list - [hidden email]
http://mail.python.org/mailman/listinfo/pythondotnet
Reply | Threaded
Open this post in threaded view
|

Re: Cannot initialize OLE

Feihong Hsu
I believe Brian's assessment is correct. The easiest way to handle this is to use pywin32's pythoncom module to set the threading model. You can find a sample of how to do that here:

http://www.ironpython.info/index.php/Using_the_WebBrowser_Widget

In the sample, the WebBrowser widget (which uses ActiveX underneath) is embedded in a form. By invoking pythoncom.CoInitialize(), we set the threading model to STA which prevents the program from crashing when it initializes the form.

--- On Mon, 12/1/08, Brian Lloyd <[hidden email]> wrote:
From: Brian Lloyd <[hidden email]>
Subject: Re: [Python.NET] Cannot initialize OLE
To: "Daniele Esposti" <[hidden email]>, [hidden email]
Date: Monday, December 1, 2008, 1:45 PM

This probably has to do with the threading model being auto-magically
set for you when the CLR is cranked up, absent any prior initialization.

The managed version of python.exe is able to set the threading model
(to MTA I believe) because it is a managed executable. When you import
clr via the standard python.exe, you are probably getting the default
model (STA). I could have those backwards - its been a while ;)

If you are using the win32com extensions, you might be able to import
those, set the threading model for the process, then import clr. Not
sure if that will work, but its worth a shot. I don't think there is
any way to change the threading model once it's set.

-Brian


On 12/1/08 8:53 AM, "Daniele Esposti" <[hidden email]>
wrote:

> Hi all,
>
> if I run my application (a wxPython frame with a wx.Activex Flash
> component) with the python.exe in pythonnet folder its work like expected.
> Instead, if I run my application with the standard Python interpreter,
> with clr.pyd in DLLs folder and Python.Runtime.dll in the same
> interpreter folder, I get a warnings says Cannot initialize OLE and the
> ActiveX is locked.
> I'm using Python 2.5.2 on a Windows XP SP3 machine, PythonNet
> 2.0-alpha2-clr2.0 compiled with VisualStudio Express 2008.
>
> Have I missing something ? Only clr.pyd and Python.Runtime.dll are
> needed or there are others resources to copy in Python interpreter folder
?
>
> Thanks in advance
> _________________________________________________
> Python.NET mailing list - [hidden email]
> http://mail.python.org/mailman/listinfo/pythondotnet

--------------------------------
Brian Lloyd 540.845.2975

[hidden email]

_________________________________________________
Python.NET mailing list - [hidden email]
http://mail.python.org/mailman/listinfo/pythondotnet


_________________________________________________
Python.NET mailing list - [hidden email]
http://mail.python.org/mailman/listinfo/pythondotnet
Reply | Threaded
Open this post in threaded view
|

Re: Cannot initialize OLE

Daniele Esposti
Feihong Hsu ha scritto:

> I believe Brian's assessment is correct. The easiest way to handle this
> is to use pywin32's pythoncom module to set the threading model. You can
> find a sample of how to do that here:
>
> http://www.ironpython.info/index.php/Using_the_WebBrowser_Widget
>
> In the sample, the WebBrowser widget (which uses ActiveX underneath) is
> embedded in a form. By invoking pythoncom.CoInitialize(), we set the
> threading model to STA which prevents the program from crashing when it
> initializes the form.
>

Ok,

import pythoncom
pythoncom.CoInitialize()


and every it's working right.
Thank's to all
_________________________________________________
Python.NET mailing list - [hidden email]
http://mail.python.org/mailman/listinfo/pythondotnet