一、首选这边选用的是通过编译器VS来建立C++的dll文件,这个具体的过程可以参考我之前写的博客:https://blog.csdn.net/Littlehero_121/article/details/96159048
二、开始进行编写dll,我选用的两个函数,进行求和和求差
在myDll.h文件中:
#pragma once
#ifdef VSDLL_EXPORTS
#define VSDLL_API _declspec(dllexport)
#else
#define VSDLL_API _declspec(dllimport)
#endif
#ifdef __cplusplus
extern "C"
{
VSDLL_API int Sum(int a, int b);
VSDLL_API int Sub(int a, int b);
}
#endif //#ifndef MYDll_H_
在myDll.cpp文件中:
#include <iostream>
#include "stdafx.h"
#include "myDll.h"
using namespace std;
int Sum(int a, int b)
{
return a + b;
}
int Sub(int a, int b)
{
return a - b;
}
完成编译,会生成一个32位的dll文件,因为我安装的python是64位的,所以我这边还需要再改成64位的dll文件。
三、更改成64位的dll
1、首先找到配置管理器,如图:
2、在活动解决方案平台中找到:新建
3、找到64位的,选中
注意下面的这个不要更改,千万别改了
四、就是直接生成解决方案,将dll和lib拷到你放在python中的同级目录,然后开始编写python文件进行调用,最后的结果是:
源码连接:https://download.csdn.net/download/littlehero_121/11878507