简体   繁体   English

从Python调用C ++函数

[英]Calling C++ functions from Python

class ICallback
{
       public: virtual void OnEvent(int a,char*  b) = 0;
};
class MyListener :public ICallback
{
    public: virtual void OnEvent(int a, , char*  b){code here}
};

int OnComplete(char* ID, ICallback* Listener);

Hello, I have such code in C++ and I need to call OnComplete method from Python. 您好,我在C ++中有这样的代码,我需要从Python调用OnComplete方法。

Please pay attention that I have to create MyListener in python, implement OnNavigationEvent in python and call OnComplete of C++. 请注意,我必须在python中创建MyListener,在python中实现OnNavigationEvent并调用C ++的OnComplete。

Is it possible? 可能吗?

Update: I can't touch "OnComplete" method code, it's third party library 更新:我无法触摸“ OnComplete”方法代码,它是第三方库

Update 2: Here is the perfect example, very compact and understandable for people like me, new for python: http://eli.thegreenplace.net/2008/08/31/ctypes-calling-cc-code-from-python/ I just can't answer on my own question because a reputation < 10 :) 更新2:这是一个完美的示例,对于像我这样的人来说非常紧凑并且可以理解,对于python来说是新的: http : //eli.thegreenplace.net/2008/08/31/ctypes-calling-cc-code-from-python/我只是无法回答自己的问题,因为声誉<10 :)

It's possible, but it's not trivial; 可能,但并非不重要。 the process is too involved to try and describe it here. 该过程过于复杂,无法在此处进行描述。 Fortunately the Python team provides a handy document that describes how to do it . 幸运的是,Python团队提供了一个方便的文档来描述如何执行此操作

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM