using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Runtime.InteropServices; namespace ComToPython { [Guid("350779B9-8AB5-4951-83DA-4CBC4AD860F4")] public interface IMyClass { void Initialize(); void Dispose(); int Add(int x, int y); } [ClassInterface(ClassInterfaceType.None)] [Guid("16D9A0AD-66B3-4A8A-B6C4-67C9ED0F4BE4")] [ProgId("ComToPython.Application")] public class ComToPython: IMyClass { public void Initialize() { // nothing to do } public void Dispose() { // nothing to do } public int Add(int x, int y) { return x + y; } } }
#!/usr/bin/env python # -*- coding: utf-8 -*- a=1 b=2 print "方法一:" from win32com.client import Dispatch dll = Dispatch("ComToPython.Application") result = dll.Add(a, b) print "a + b = " + str(result) print "方法二:" import comtypes.client dll = comtypes.client.CreateObject('ComToPython.Application') result = dll.Add(a, b) print "a + b = " + str(result)
运行代码,执行结果如下:
以上就是Python调用C# COM Dll整个过程了
以上就是Python调用C# Com dll组件的过程详解的详细内容,更多请关注Gxl网其它相关文章!
查看更多关于Python调用C#Comdll组件的过程详解的详细内容...
声明:本文来自网络,不代表【好得很程序员自学网】立场,转载请注明出处:http://haodehen.cn/did81722