call c 23 from python

Solutions on MaxInterview for call c 23 from python by the best coders in the world

showing results for - "call c 23 from python"
Cavan
31 Jan 2017
1private void run_cmd(string cmd, string args)
2{
3     ProcessStartInfo start = new ProcessStartInfo();
4     start.FileName = "my/full/path/to/python.exe";
5     start.Arguments = string.Format("{0} {1}", cmd, args);
6     start.UseShellExecute = false;
7     start.RedirectStandardOutput = true;
8     using(Process process = Process.Start(start))
9     {
10         using(StreamReader reader = process.StandardOutput)
11         {
12             string result = reader.ReadToEnd();
13             Console.Write(result);
14         }
15     }
16}
17
Melvyn
16 Nov 2020
1"""
2It is actually pretty easy. Just use NuGet to add the "UnmanagedExports" package 
3to your .Net project. 
4See https://sites.google.com/site/robertgiesecke/Home/uploads/unmanagedexports for details.
5"""
6using System;
7using System.Collections.Generic;
8using System.Linq;
9using System.Runtime.InteropServices;
10using System.Text;
11using System.Threading.Tasks;
12using RGiesecke.DllExport;
13
14class Test
15{
16    [DllExport("add", CallingConvention = CallingConvention.Cdecl)]
17    public static int TestExport(int left, int right)
18    {
19        return left + right;
20    }
21}
22
23
24"""
25You can then load the dll and call the exposed methods in Python (works for 2.7)
26"""
27import ctypes
28a = ctypes.cdll.LoadLibrary(source)
29a.add(3, 5)
30