C#数组到python的非托管导出
我正在使用Robert Giesecke的DLLExport库来导出一个可以被python应用程序访问的c#dll。我已经知道了如何调用基本类型,例如整数、double和字符串,但是我还需要将字符串或整数数组从c#dll返回到python 我试着这样定义它:C#数组到python的非托管导出,c#,python,unmanaged,C#,Python,Unmanaged,我正在使用Robert Giesecke的DLLExport库来导出一个可以被python应用程序访问的c#dll。我已经知道了如何调用基本类型,例如整数、double和字符串,但是我还需要将字符串或整数数组从c#dll返回到python 我试着这样定义它: [DllExport("Test7", System.Runtime.InteropServices.CallingConvention.Cdecl)] public static int[] Test7() { Rand
[DllExport("Test7", System.Runtime.InteropServices.CallingConvention.Cdecl)]
public static int[] Test7()
{
Random rnd = new Random();
int[] info = new int[10];
for (int i = 0; i < 10; i++)
{
info[i] = Convert.ToInt32(Math.Round(Convert.ToDecimal(rnd.Next()), 0));
}
return info;
}
我试过了
array_holder = ctypes.ARRAY()
output = ctypes.CDLL(".\\pythontst1.dll").Test8(10,array_holder)
在这两种情况下,我都会得到一个操作错误:[WinError-532462766]Windows错误0xe0434352。我正在学习python,因此它可能是我可能缺少的语法或调用,但输出=ctypes.CDLL(“.\pythontst1.dll”).Test6('hello')代码工作并返回字符串(以及我为原语提供的其他测试函数) 这里有一个答案:
import os
import ctypes
import numpy as np
output = ctypes.CDLL(".\\pythontstl.dll").Test7(10)
array_holder = ctypes.ARRAY()
output = ctypes.CDLL(".\\pythontst1.dll").Test8(10,array_holder)