以下为实验步骤:
一、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);
}


4. 以Release方式Build。
5. 修改扩展名.dll为pyd.
二、Python:
1. copy刚才生成的hello.pyd到项目目录下,或者可以import的lib目录。
2. 新建main.py:
import hello

print hello.message("hhahhah")搞定。