[IronPython] help with activex error

David.Lawler at franke.com David.Lawler at franke.com
Thu Sep 20 14:58:36 CEST 2007


This is all due to the wonderful issue created by COM components that can 
be single-threaded or multi-threaded 'apartment'.  I do not really fully 
understand what this means (you can google about it and find lots of 
information) - but I have run into it before and know how to fix it.  The 
winforms.py that comes with the examples allows you to program windows 
forms interactively by creating a second thread for you.  You just need to 
put that thread into STA 'mode':

Make a copy of winforms.py and at the top add:  from System.Threading 
import ApartmentState.  Then near the bottom, before the line: t.Start() 
add a line like this: t.ApartmentState = ApartmentState.STA

Then your example will work!  Enjoy!

David


users-bounces at lists.ironpython.com wrote on 09/20/2007 06:14:00 AM:

> Hi,
> 
> I'm trying to add the remote desktop activex control to a windows 
> form and am getting the following error. How can I fix this?
> 
> thanks for your help,
> Krishna.
> 
> C:\IronPython-1.1>ipy -X:TabCompletion
> IronPython 1.1 (1.1) on .NET 2.0.50727.312
> Copyright (c) Microsoft Corporation. All rights reserved.
> >>> import winforms 
> >>> import System
> >>> import System.Windows.Forms as wf
> >>> f = wf.Form()
> >>> f.Show()
> >>> import clr
> >>> clr.AddReferenceToFile("AxMSTSCLib.dll ")
> >>> import AxMSTSCLib as mstsc
> >>> rdp = mstsc.AxMsRdpClient2()
> Traceback (most recent call last):
> SystemError: ActiveX control '9059f30f-4eb1-4bd2-9fdc-36f43a218f4a' 
> cannot be instantiated because the current thread is not in a 
> single-threaded apartment. 
> >>>
> _______________________________________________
> Users mailing list
> Users at lists.ironpython.com
> http://lists.ironpython.com/listinfo.cgi/users-ironpython.com




More information about the Ironpython-users mailing list