zoukankan      html  css  js  c++  java
  • 如何用boost.python编写python扩展

    Dll扩展部分(文件名与模块名一致,将生成的DLL扩展名改为.pyd):

    #include "stdafx.h"
    
    #include <boost/python.hpp>
    
    #define EXPORT_SYMBOL_TO_PYTHON(x) boost::python::def(#x, x)
    
    void MsgBox(PyObject* pObj)
    {
       MessageBoxA(NULL, ((PyStringObject*)pObj)->ob_sval, "message", MB_OK );
    }
    
    BOOST_PYTHON_MODULE(DllForPython)
    {
        EXPORT_SYMBOL_TO_PYTHON(MsgBox);
    }
     
    Python脚本调用部分(将DLL扩展目录加入到sys.path):
     
    # -*- coding: gbk -*-
    
    import sys
    sys.path.append('./Debug')
    import DllForPython
    DllForPython.MsgBox("Everything is OK")
  • 相关阅读:
    Java程序员从笨鸟到菜鸟全部博客目录
    Problem I
    Problem I
    Problem S
    Problem S
    Problem X
    Problem X
    Problem Q
    Problem Q
    Ellipse
  • 原文地址:https://www.cnblogs.com/LinuxHunter/p/1890700.html
Copyright © 2011-2022 走看看