python调用c#in

2024-09-30 12:28:26 发布

您现在位置:Python中文网/ 问答频道 /正文

C#库中有一个接口,我正试图在Python中使用它

这就是我在c中的用法:

using MyDll.MyClass; 
public partial class Form1 : Form
{
 MyClass myclas= new MyClass();
 IMyClassInterface myInterface = null;

 private void button_Click(object sender, EventArgs e)
    {
        myInterface = (IMyClassInterface)myclas.GetService(computer, port, MyClass.ServiceName.RUNTIME_CONTROL); } }

问题是如何从c#dll使用c#接口在python中启动相同的服务? 同样,我还想用python实现。Python代码如下:

import sys
sys.path.append(r"C:\Program Files\foldername")
import clr
clr.AddReference(r"C:\Program Files\foldername\MyDll.MyClass")
from MyDll.MyClass import MyClass

def OnRun(self, userExcInst):
    myInterface = MyClass()
    myInterface = (IMyClassInterface)myclas.GetService(computer, port, MyClass.ServiceName.RUNTIME_CONTROL); #??? This is what I am trying to implement

因此,我想在python中使用c#dll启动服务


Tags: importportsysmyclassfilesprogramcontrolcomputer

热门问题