当前位置: 移动技术网 > IT编程>开发语言>C/C++ > 使用C++创建Pyd文件扩展Python模块

使用C++创建Pyd文件扩展Python模块

2018年12月29日  | 移动技术网IT编程  | 我要评论

北京电视台天下财经,模特宋珊珊,七年之痒痒痒

使用c++创建pyd文件扩展python模块:1、需要说明的是pyd文件其实就是dll,为了python能正常调用,这个dll规定了导出函数的一些规则。下面代码简单演示使用c++创建一个函数,并使用python调用该模块。

(注意需要添加python的head路径和lib路径,具体操作,可见下面的视频链接)

#include 
#include 

//需要绑定的方法
static pyobject* printhello(pyobject *self, pyobject *args)
{
	std::cout << "hello, i am form c++" << std::endl;

	//测试一下使用c++/clr,让python调用
// 	system::windows::forms::form^ testdotnetwindows = gcnew system::windows::forms::form();
// 	testdotnetwindows->showdialog();

	py_incref(py_none);
	return py_none;
}

//描述方法
static pymethoddef methods[] = {
	{"printhellofn", printhello, meth_varargs, "文档字符串"},
	{null, null}
};

//初始化模块
pymodinit_func initprinthello(void)
{
	py_initmodule("printhello", methods);
}

如对本文有疑问,请在下面进行留言讨论,广大热心网友会与你互动!! 点击进行留言回复

相关文章:

验证码:
移动技术网