如何在Pycharm Python中使用C#骑士编写的函数

时间:2019-06-13 08:05:26

标签: c# python pycharm rider

我是编程和实习生的新手,他们要求我将其python代码转换为c#(我以前从未使用c#编程,请原谅我犯的任何c#错误) )。

我正在尝试将Python中的某些函数更改为C#,然后在Pycharm中调用这些C#函数以提高Python的速度。我正在尝试调用函数本身,而不是通过.Net或IronPython。

我在网上找到了一个使用非托管导出的示例,并尝试使用该示例,但是我得到了

  

OSError:[WinError 193]%1不是有效的Win32应用程序

C#代码:

 using System.Runtime.InteropServices;
 using RGiesecke.DllExport;

 class Test
 {
     [DllExport("add", CallingConvention = CallingConvention.Cdecl)]
     public static int TestExport(int left, int right)
     {
         return left + right;
     }
 }

Python代码:

import ctypes
a = ctypes.cdll.LoadLibrary(r"C:\Users\Family PC\RiderProjects\ConsoleApplication1\ConsoleApplication1\Program.cs")
a.add(3, 5)

当我调用a.add(3,5)时,我期望得到8。我正在使用python 64位,pycharm 64和rider64。

有什么办法做到这一点,还是我徒劳地尝试?

0 个答案:

没有答案