创建DLL分为两种方法,先介绍第一种

一、创建DLL

(1)

// dll.h
#pragma once
//dll.h
#ifndef DLL_H_
#define DLL_H_ void printhello();
void callPython();
extern "C" _declspec(dllexport) void start();
#endif
//dll.cpp
#pragma once
#include <iostream>
#include <Python.h> using namespace std; void printhello() {
cout << "hello c++ dll !" << endl;
} void callPython() {
Py_Initialize();
if (!Py_IsInitialized()) PyErr_Print();
PyRun_SimpleString("import sys");
PyRun_SimpleString("sys.path.append('D:\\CodeDemo')");
PyObject* pModule = NULL;
PyObject* pFunc = NULL;
PyObject* pDict = NULL;
PyObject* pKey = NULL;
PyObject* pSubDict = NULL;
if (!(pModule = PyImport_ImportModule("hellopython"))) PyErr_Print();
if (!(pFunc = PyObject_GetAttrString(pModule, "hellopython"))) PyErr_Print();
PyObject_CallObject(pFunc, NULL);
} extern "C" _declspec(dllexport)void start()
{
printhello();
callPython();
}



Configuration Properties-> General -> Configuration Type 改为dll。



Configuration Properties-> Linker-> General -> output file 按图修改。

然后Build->build soultion, 就可以在debug或者release目录下看到生成的DLL 文件

(2) 待补充

二、使用DLL文件

参考这篇文章:https://docs.microsoft.com/zh-cn/cpp/build/walkthrough-creating-and-using-a-dynamic-link-library-cpp?view=msvc-170

分为四步:

(1)

指到要引用的头文件路径。

(2)

输入链接中使用的lib文件

(3)

这是上一步lib文件的路径,

(4)把dll文件放在调用project的exe目录下即可

最新文章

  1. [问题记录.dotnet]取网卡信息报错&quot;找不到&quot;-WMI - Not found
  2. 【读书笔记】iOS网络-使用推送通知
  3. Web前端开发基础 第四课(认识CSS样式)
  4. [Effective JavaScript 笔记]第68条:使用promise模式清洁异步逻辑
  5. 【原创】jmeter3.0在beanshell中输入中文乱码以及字体大小的更改
  6. IDEA 从SVN检出项目相关配置
  7. ubuntu下ssh登陆阿里云服务器(ubuntu系统)中文乱码问题
  8. 加载不同的nib文件
  9. MongoDB简述
  10. NET Remoting 示例
  11. tomcat web.xml配置
  12. sed文本处理--文本行扩展与分割
  13. 【多线程】--生产者消费者模式--synchronized版本
  14. Apache POI 一键上传(导入excel文件到数据库)
  15. 前端基础之JavaScript
  16. Windows使用Gitblit搭建Git服务器
  17. [Swift]LeetCode506. 相对名次 | Relative Ranks
  18. golang开源项目qor快速搭建网站qor-example运行实践
  19. ARM 技术文档
  20. libctemplate——源码分析

热门文章

  1. 自定义select组件
  2. Entity Framework生成的SQL语句
  3. Jmeter(三十九) - 从入门到精通进阶篇 - Jmeter配置文件的刨根问底 - 上篇(详解教程)
  4. redis常用命令之Hash
  5. vue 打开页面触发事件
  6. Expected space(s) after &quot;default&quot; keyword-spacing
  7. mobx hook中的使用
  8. Windows MFC HTTP 函数流程
  9. 版图 shrink
  10. 使用Wireshark完成实验1