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")

相关文章:

  • 2021-12-03
  • 2022-12-23
  • 2022-01-12
  • 2022-12-23
  • 2021-06-28
  • 2021-12-30
  • 2022-12-23
猜你喜欢
  • 2022-02-25
  • 2021-07-21
  • 2021-07-10
  • 2021-11-16
  • 2022-12-23
  • 2021-08-16
相关资源
相似解决方案