总结:
1.创建dll工程;
2.增加包含头文件路径 :将python路径下的include加入到包含头文件路径:在工程属性页 C/C++/附加包含目新增<Python>\include目录
3.增加lib路径:链接器/附加库目录添加<Python>\libs目录
4.修改输出文件类型为pyd: 工程属性页/链接器/输出文件,修改输出文件名为hello.pyd
5.以release方式build
6.将生成的pyd文件拷贝到项目目录下或者可以import的lib目录下。
http://blog.csdn.net/jelolu/article/details/40041649 vs2008实现c语言扩展python
http://blog.csdn.net/lien0906/article/details/51122572 讲的是VS2013的python开发环境
http://jingyan.baidu.com/article/67508eb4371b9e9cca1ce412.html C++ (VS 2013)调用Python (3.4)
http://blog.csdn.net/u010786109/article/details/41825147 Python 扩展技术总结
http://m.blog.csdn.net/article/details?id=50771316
VS 2005中实现对Python 2.5.2的模块扩展实验
以下为实验步骤:
一、VS 2005:
1. 新建Win32 Application, Application type: DLL, Additional options: Empty project.
2. Projects and Solutions->VC++ Directores中,新增<Python>\include目录到Include files和library files.
3. 新增Source Files:
hello.c:
一、VS 2005:
1. 新建Win32 Application, Application type: DLL, Additional options: Empty project.
2. Projects and Solutions->VC++ Directores中,新增<Python>\include目录到Include files和library files.
3. 新增Source Files:
hello.c:
#include <Python.h>
#include <string.h>
static PyObject *message(PyObject *self, PyObject *args) {
char *fromPython, result[64];
if (!PyArg_Parse(args, "(s)", &fromPython))
return NULL;
else {
strcpy(result, "Hello, ");
strcat(result, fromPython);
return Py_BuildValue("s", result);
}
}
static struct PyMethodDef hello_methods[] = {
{"message", message, 1},
{NULL, NULL}
};
_declspec(dllexport) void inithello() {
(void)Py_InitModule("hello", hello_methods);
}
#include <string.h>
static PyObject *message(PyObject *self, PyObject *args) {
char *fromPython, result[64];
if (!PyArg_Parse(args, "(s)", &fromPython))
return NULL;
else {
strcpy(result, "Hello, ");
strcat(result, fromPython);
return Py_BuildValue("s", result);
}
}
static struct PyMethodDef hello_methods[] = {
{"message", message, 1},
{NULL, NULL}
};
_declspec(dllexport) void inithello() {
(void)Py_InitModule("hello", hello_methods);
}
4. 以Release方式Build。
5. 修改扩展名.dll为pyd.
二、Python:
1. copy刚才生成的hello.pyd到项目目录下,或者可以import的lib目录。
2. 新建main.py:
import hello
print hello.message("hhahhah")
print hello.message("hhahhah")
搞定。