Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/csharp/299.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C#数组到python的非托管导出_C#_Python_Unmanaged - Fatal编程技术网

C#数组到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

我正在使用Robert Giesecke的DLLExport库来导出一个可以被python应用程序访问的c#dll。我已经知道了如何调用基本类型,例如整数、double和字符串,但是我还需要将字符串或整数数组从c#dll返回到python

我试着这样定义它:

[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)