Tag: ctypes

可以让Python从C#接收一个可变长度的字符串数组吗?

这可能是一个红色的鲱鱼,但我的非arrays版本看起来像这样: C# using RGiesecke.DllExport; using System.Runtime.InteropServices; namespace Blah { public static class Program { [DllExport(“printstring”, CallingConvention = CallingConvention.Cdecl)] [return: MarshalAs(UnmanagedType.AnsiBStr)] public static string PrintString() { return “Hello world”; } } } python import ctypes dll = ctypes.cdll.LoadLibrary(“test.dll”) dll.printstring.restype = ctypes.c_char_p dll.printstring() 我正在寻找一个可以获取可变大小的List的printstrings 。 如果那是不可能的,我会选择一个固定长度的string[] 。

在python中使用ctypes来访问C#dll的方法

我想在我的python程序的关键部分实现C#代码,以使其更快。 它说(在Python文档和本站点上 )您可以加载动态链接库(以及PyDocs),如下所示: cdll.LoadLibrary(“your-dll-goes-here.dll”) 这是我的代码中负责此function的部分: from ctypes import * z = [0.0,0.0] c = [LEFT+x*(RIGHT-LEFT)/self.size, UP+y*(DOWN-UP)/self.size] M = 2.0 iterator = cdll.LoadLibrary(“RECERCATOOLS.dll”) array_result = iterator.Program.ITERATE(z[0],z[1],c[0],c[1],self.iterations,M) z = complex(array_result[0],array_result[1]) c = complex(array_result[2],array_result[3]) last_iteration = int(round(array_result[4])) 我使用的RECERCATOOLS.dll就是这个(C#代码,而不是C或C ++): using System; using System.Collections.Generic; using System.Linq; using System.Text; using KarlsTools; public class Program { public static Array ITERATE(double z_r,double […]