Skip to main content
 Web开发网 » 编程语言 » Python语言

怎么制作python和c++ 接口(用C++制作)1

2021年11月27日6490百度已收录

首先,用C++生成一个DLL,源码

dllmain.c

/* Replace "dll.h" with the name of your header */

#include "dll.h"

#include <windows.h>

DLLIMPORT void HelloWorld()

MessageBox(0,"Hello World from DLL!\n","Hi",MB_ICONINFORMATION);

BOOL WINAPI DllMain(HINSTANCE hinstDLL,DWORD fdwReason,LPVOID lpvReserved)

switch(fdwReason)

case DLL_PROCESS_ATTACH:

break;

case DLL_PROCESS_DETACH:

break;

case DLL_THREAD_ATTACH:

break;

case DLL_THREAD_DETACH:

break;

/* Return TRUE on success, FALSE on failure */

return TRUE;

dll.h

#ifndef _DLL_H_

#define _DLL_H_

#if BUILDING_DLL

#define DLLIMPORT __declspec(dllexport)

#else

#define DLLIMPORT __declspec(dllimport)

#endif

DLLIMPORT void HelloWorld();

#endif

项目名:testdll

生成结果:testdll.dll

python程序

#test dll

from ctypes import *  

dll = CDLL("d:\\temp\\testdll.dll")  

dll.HelloWorld()  

测试结果

怎么制作python和c++ 接口(用C++制作)1  Python接口 第1张

评论列表暂无评论
发表评论
微信