[IronPython] IronPython interop problem

Dino Viehland dinov at exchange.microsoft.com
Tue Aug 29 22:10:27 CEST 2006


Sorry, pressed send too soon...

The good news is that very soon we'll have full documentation on the hosting APIs which might make it a little more obvious about where to look for these things :).

-----Original Message-----
From: Dino Viehland
Sent: Tuesday, August 29, 2006 1:09 PM
To: Discussion of IronPython
Subject: RE: [IronPython] IronPython interop problem

We hadn't really considered this and haven't had any requests to do this yet.  The problem here is of course that once a type is COM visible you're never allowed to add anything to that type as it'll break the COM clients.

What I would imagine we might do in the future would be to define an interface (e.g. IPythonEngine) and then expose that to COM rather than exposing the PythonEngine class to COM clients.  That would allow COM clients to interact w/ the engine and allow us to version the interface by adding an IPythonEngine2/IPythonEngineEx interface.

One of the best ways we have for interacting w/ delegates is with the CreateMethod and CreateLambda APIs.  These allow you to pass in a body of code and get a .NET delegate back out.  That .NET delegate for your purposes could be converted into an unmanaged function pointer and called directly from your native code (no COM needed! :) ).  You can combine these w/ ExecuteFile which will allow you to use the delegates to call into a module which contains some pre-baked script code if you don't want to pass all the code into this API.

-----Original Message-----
From: users-bounces at lists.ironpython.com [mailto:users-bounces at lists.ironpython.com] On Behalf Of Marc-André Belzile
Sent: Monday, August 28, 2006 1:25 PM
To: Discussion of IronPython
Subject: Re: [IronPython] IronPython interop problem

Dino,

Do you have plans in the future to make IP assemblies COM visible? This would allow us to support .NET assemblies in a uniform manner without having to do a special case for IP.

As for the approach you are proposing, it's not obvious how I can use PythonEngine for my scenario. Our plug-ins need to expose a set of functions known by the main app. These functions are called by the app with SDK objects arguments (i.e ActiveX), these objects are used by the callback to perform some actions. I don't see any methods in PythonEngine that would allow me to do such things.

Eg

PtyhonEngine engine = new PtyhonEngine
engine.ExecuteFile("MyModule.ps")

ArrayList args;
args.Add( obj1 );
args.Add( obj2 );

Boolean retVal;
engine.Execute( "Foo", args, retVal );

etc..

Foo would be defined as

def Foo( arg0, arg1 ):
        arg0.SomeMethod()
        arg1.SomeOtherMethod()
        return true

Are these kind of things possible to do with the current implementation of IP ?

Thanks.

-mab

-----Original Message-----
From: users-bounces at lists.ironpython.com
[mailto:users-bounces at lists.ironpython.com]On Behalf Of Dino Viehland
Sent: August 25, 2006 3:47 PM
To: Discussion of IronPython
Subject: Re: [IronPython] IronPython interop problem


The problem you're running into is that we won't expose the Python type by the names you compile it as - this is the weirdness you're seeing versus a C# compiled assembly.

There's a couple of ways to deal with this.  One is to host IronPython and use the PythonEngine interfaces to expose objects, create instances, etc...  This is the preferred mechanism - for your scenario you may need to make a small shim in C# that enables access to the IronPython engine because we don't mark the type as being ComVisible (and we explicitly turn off COM visibility for all types in the assembly unless they opt-in).  I'm actually not certain if our types that get created on the fly are COM visible, but even if they are IDispatch currently won't know about the way we plug-in here.

We also have a HIGHLY EXPERIMENTAL static type compiler - unfortunately there is plenty of valid Python code that can't be compiled by it yet so I'd suggest you go with the 1st route.

This is a very interesting scenario though and we'll probably want to look at what we can do in the future to make this better.  If you want to let us know more about what you're trying to accomplish in the end it might help us ensure this meets your needs in the future.



-----Original Message-----
From: users-bounces at lists.ironpython.com [mailto:users-bounces at lists.ironpython.com] On Behalf Of Marc-André Belzile
Sent: Friday, August 25, 2006 11:11 AM
To: users at lists.ironpython.com
Subject: [IronPython] IronPython interop problem

Hello,

I'm hosting the CLR (.NET 2.0) in an unmanaged C++ app in order to access objects from .NET assemblies with IDispatch. This is working fine for C# assemblies but failed for IP assemblies.

The call to _AppDomain.CreateInstance below returns this error: 80131522, which I couldn't find in the doc.

My unmanaged code:

        CComPtr<_AppDomain> spAppDomain;
        HRESULT hr = pDomain->QueryInterface( &spAppDomain.p );
        assert( !hr );

        CComPtr<_ObjectHandle> spHandle;
        CComBSTR assyname("IronPythonPlugin");
        CComBSTR classname("MyClass");

        hr = spAppDomain->CreateInstance( assyname,classname,&spHandle );

My test class in

        class MyClass:
                def Foo():
                        pass

I compiled the PI assbly with VS2005 using the IDE prototype. The IL code looks rather odd though compared to a C# assbly.

___[MOD] S:\Rayflex\Sdk\si3dobjectmodel\IronPythonPlugin\bin\Debug\IronPythonPlugin.dll
   |      M A N I F E S T
   |___[CLS] Class
   |   |     .class public auto ansi
   |   |      extends [IronPython]IronPython.Runtime.CustomDict
   |   |___[STF] ExtraKeysCache : public static string[]
   |   |___[STF] MyClass : public static object
   |   |___[STF] __doc__ : public static object
   |   |___[STF] __name__ : public static object
   |   |___[STF] myModule__py : public static class [IronPython]IronPython.Runtime.PythonModule
   |   |___[STM] .cctor : void()
   |   |___[MET] .ctor : void()
   |   |___[STM] Foo$f4 : object(class [IronPython]IronPython.Runtime.FunctionEnvironment4)
   |   |___[MET] GetExtraKeys : object[]()
   |   |___[MET] Initialize : void()
   |   |___[STM] Main : int32()
   |   |     MyClass$maker4 : class [mscorlib]System.Collections.Generic.IDictionary`2<object,object>(class [IronPython]IronPython.Runtime.FunctionEnvironment,class [IronPython]IronPython.Runtime.ICallerContext)
   |   |___[MET] TryGetExtraValue : bool(object,object&)
   |   |___[MET] TrySetExtraValue : bool(object,object)
   |

Is this a known limitation ? Or maybe there is another way of getting at IP classes from unmanaged code ?

thanks for your help!

Marc-André BELZILE - sdk software engineer, softimage|xsi _______________________________________________
users mailing list
users at lists.ironpython.com
http://lists.ironpython.com/listinfo.cgi/users-ironpython.com
_______________________________________________
users mailing list
users at lists.ironpython.com
http://lists.ironpython.com/listinfo.cgi/users-ironpython.com
_______________________________________________
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