1 windows下python调用C/C++以及使用C扩展python
转载于 https://blog.csdn.net/maosijunzi/article/details/79354806
2 Python调用C++ 编写的dll动态库函数
转载于 https://blog.csdn.net/weixin_38285131/article/details/81288338
3 Python 调用c#的dll pythonnet
https://blog.csdn.net/LTG01/article/details/80700513
C# dll
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace PoemDLL
{
public class Poetry
{
public void PrintSuShiPoem()
{
string strSS = "休对故人思故国,且将新火试新茶。诗酒趁年华。";
Console.WriteLine(strSS);
}
public static void PrintNlxdPoem()
{
string strNlxd = " 人生若只如初见,"
+ "何事秋风悲画扇。"
+ "等闲变却故人心,"
+ "却道故人心易变。"
+ "骊山语罢清宵半,"
+ "泪雨霖铃终不怨。"
+ "何如薄幸锦衣郎,"
+ "比翼连枝当日愿。";
Console.WriteLine(strNlxd);
}
public static int UnityAdd(int a, int b)
{
int c = a + b;
return c;
}
public static void WritePoem(char[] strs_poem)
{
String str_poem = "不应有恨,何事长向别时圆?"
+ "人有悲欢离合,月有阴晴圆缺,此事古难全。"
+" 但愿人长久,千里共婵娟。";
char[] str = str_poem.ToCharArray();
int len = str_poem.Length;
Buffer.BlockCopy(str, 0, strs_poem, 0, len * 2);
}
public static string PythonPoem()
{
String str_poem = "不应有恨,何事长向别时圆?"
+ "人有悲欢离合,月有阴晴圆缺,此事古难全。"
+ " 但愿人长久,千里共婵娟。";
return str_poem;
}
public static void PythonPoem(string poet)
{
poet = "SuDongPo";
String str_poem = poet;
return ;
}
}
}
python 调用
import clr
import sys
sys.path.append("F:\VS2013Buffer\HelloVS\ActivatePoemDll")
clr.FindAssembly("PoemDLL .dll")
from PoemDLL import * # 导入命名空间
Poetry.PrintNlxdPoem()
instance = Poetry() #class1是dll里面的类
instance.PrintSuShiPoem() #显示一个窗口
poem = "kkkkkkkkkkkkllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllll"
Poetry.WritePoem(poem)
print(poem)
输出