我可以使用这个.mm网桥从我的目标c成功调用c ++函数。
问题是给定c ++库中的方法没有返回,即Void。 例如void login(const char * email,const char * password);
此c ++库已实现回调函数,以了解此登录方法的结果。
示例:
class DemoApp : public XClass
{
int urandomfd;
public:
uint32_t dstime(void);
FileAccess* newfile();
void request_error(MegaClient*, error);
void login_result(MegaClient*, error);
void users_updated(MegaClient*, User**, int);
void nodes_updated(MegaClient*, Node**, int);
int prepare_download(MegaClient*, Node*);
void share_result(MegaClient*, int, error);
void account_details(MegaClient*, AccountDetails*, int, int, int, int, int, int);
void topen_result(MegaClient*, int, error);
void topen_result(MegaClient*, int, string*, const char*, int);
void transfer_update(MegaClient*, int, off_t, off_t, uint32_t);
void transfer_error(MegaClient*, int, int, int);
void transfer_failed(MegaClient*, int, error);
void transfer_failed(MegaClient*, int, string&, error);
void transfer_limit(MegaClient*, int);
void transfer_complete(MegaClient*, int, chunkmac_map*, const char*);
void transfer_complete(MegaClient*, int, const byte*, const byte*, SymmCipher*);
void changepw_result(MegaClient*, error);
void reload(MegaClient*, const char*);
void notify_retry(MegaClient*, int);
void debug_log(MegaClient*, const char*);
DemoApp();
};
所以现在关注的是我应该如何以及何时在我的目标C库中调用这些CALLBACK函数,这对我来说是在c ++库中内部调用它们。
这是我的wrapper.mm文件,包装c ++方法,需要在目标c中调用。
- (void)WrapLogin:(NSString *)email:(NSString *)pwd {
self.wrappedModelAccessMega->登录([email UTF8String],[pwd UTF8String]); //没有返回,因为来自c ++库的Login mfunction没有返回任何内容,即void
}
我正在研究它已经有一段时间了,并且已经很难将这个库集成到我的目标C库中,现在我因为这些回调函数而陷入困境。 请举例说明我应该如何使用c ++的回调函数,将其包装并调用我的目标c来获取/知道我的登录函数的结果/返回将为我做好工作。
答案 0 :(得分:2)
简单的答案是:
感谢Jaggu先生帮助我了解这一点。