开发者

How to import COM into Ironpython?

In Cpython, I can use win32com.

But, i开发者_运维问答n ironpython, I didn't know how to import it.

Because, in .net, one always use Visual Studio to interop the COM and to use it.


You should be able to create an IDispatch object using:

from System import Type, Activator
Activator.CreateInstance(Type.GetTypeFromProgID(com_type_name))

This is equivalent to win32com.client.Dispatch(com_type_name).

If there's a type lib you should be able to do:

import clr
import System
typelib = clr.LoadTypeLibrary(System.Guid("00020905-0000-0000-C000-000000000046"))
word = typelib.Word.Application()

I don't know what that's equivalent to. I'm not much of an expert on this but I took those from IronPython's cominterop_util which is used in the tests. There's more stuff in the IronPython\Tests\interop\com directory which might be useful.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜