- 目的の c プロジェクトで c++ ライブラリを使用しています。
- c++ ライブラリを統合し、.mm ファイルを実装して、c++ と目的の c を橋渡ししました。
この .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*) 電子メール :(NSString*) pwd{
self.wrappedModelAccessMega->Login([email UTF8String], [pwd UTF8String]); //C++ ライブラリからの Login mfunction が何も返さない、つまり void であるため、戻りません
}
私はしばらくの間それに取り組んでおり、このライブラリを私の目的の C ライブラリに統合するためにすでに懸命に取り組んでいますが、これらのコールバック関数が原因で行き詰まってしまいました。C ++のコールバック関数を使用する方法を示す小さな例を示してください。それをラップし、目的のcを呼び出して、ログイン関数の結果を取得/知る/返すと、私にとって素晴らしい仕事をしてくれます。