Mon but est d'accéder à la fonction de fichier C# dll à partir de la bibliothèque ctypes de scripts python. Mon code C# est:Accès à la fonction de fichier C# dll à partir du code python
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using RGiesecke.DllExport;
using System.Runtime.InteropServices;
namespace ConsoleApp1
{
[ComVisible(true)]
public class Program
{
[DllExport("MyFunctionName", CallingConvention = CallingConvention.Cdecl)]
[return: MarshalAs(UnmanagedType.LPWStr)]
public static string MyFunctionName([MarshalAs(UnmanagedType.LPWStr)] string iString)
{
return "hello world i'm " + iString;
}
[DllExport("Add",CallingConvention = CallingConvention.Cdecl)]
public static int Add(int a, int b)
{
return a + b;
}
[DllExport(CallingConvention = CallingConvention.Cdecl)]
static public int Subtract(int a, int b)
{
return a - b;
}
[DllExport(CallingConvention = CallingConvention.Cdecl)]
static public int Multiply(int a, int b)
{
return a * b;
}
[DllExport(CallingConvention = CallingConvention.Cdecl)]
static public int Divide(int a, int b)
{
return a/b;
}
static void Main(string[] args)
{
//Console.Write(Add(2,3));
}
}
}
et code python est:
import ctypes
a=ctypes.cdll.LoadLibrary('File Location')
a.MyFunctionName("a")
mais je reçois une erreur AttributeError: la fonction 'MyFunctionName' not found
Comment je peux résoudre l'erreur que je ne peux pas accéder aux fonctions incluses dans le fichier dll?
Bien que j'aie défini les plates-formes de solution sur x64 précédemment, j'obtiens toujours l'erreur. –