python 调用dll

python代码:

import ctypes as C

dll = C.cdll.LoadLibrary('Dll1.dll')

#1.传入实数调用demo
result1 = dll.add(2,3)
print(result1)

C++:

python 调用dll_第1张图片

 Dll1.cpp:

#include "pch.h"
#define DLLEXPORT extern "C" _declspec(dllexport)

DLLEXPORT int add(int a, int b)
{
	return a + b;
}

Dll1.h:

#define DLL1_API _declspec(dllexport)

class DLL1_API CDll1
{
public:
	CDll1(void);
	int add(int a, int b);
};

extern DLL1_API int nDll1;

DLL1_API int fnDll1(void);

调用结果:

python 调用dll_第2张图片

你可能感兴趣的:(C++,c++)