使用Visual Studio 6.0 (C/C++)开发Python扩展模块

6 篇文章 0 订阅
4 篇文章 0 订阅

        其实大致的步骤和我在前面写的《使用Visual Studio.Net 2005开发Python扩展模块》 这里重写VC6.0环境下的方法是为了方便自己也为了熟悉VC6.0环境的朋友
少走弯路。

1、新建工程,Win32 Dynamic-Link Library,工程名:Winy(个人喜好)。

2、添加代码。清除Windy.cpp,拷贝代码如下:

//  Windy.cpp : Defines the entry point for the DLL application.
//

#include 
" stdafx.h "

#include 
< Python.h >

static  PyObject  *
Windy_hello(PyObject 
* self, PyObject  * args)
{
    printf(
"Hello, world ");
    Py_INCREF(Py_None);
    
return Py_None;
}


static  PyMethodDef Windy_methods[]  =  
{
    
{"hello", Windy_hello, METH_VARARGS, "hello() doc string"},
    
{NULL, NULL}
}
;

/*PyMODINIT_FUNC*/
extern   " C "  _declspec(dllexport)
initWindy(
void )
{
    Py_InitModule(
"Windy", Windy_methods);
}


BOOL APIENTRY DllMain( HANDLE hModule, 
                       DWORD  ul_reason_for_call, 
                       LPVOID lpReserved
                     )
{
    
return TRUE;
}



3、添加Python安装目录中的include,libs路径。Tools > Options > Directories

4、更改工程编译设置(Alt + F7), 添加python25.lib导入库(也可不设置,前面已经加入了Python的libs了)。

5、编译。如果你没有Python的调试库如python25_d.lib,请编译Release版本。

6、测试。请参考《使用Visual Studio.Net 2005开发Python扩展模块》

7、发挥我们的创造力的时候到了 :)

 

ps1: 注意在

/*PyMODINIT_FUNC*/
extern   " C "  _declspec(dllexport) void
initWindy(
void )

中如果你使用PyMODINIT_FUNC而注释掉extern "C" _declspec(dllexport) void 请将最后生成的dll后缀改为pyd,
具体原因目前我还不是太清楚,等有时间看看源代码是什么原因(是不是我哪儿的设置有问题?)。

ps2: vckbase上的一篇C++ 扩展和嵌入 Python》

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值