- 내 목표 C 프로젝트에서 C++ 라이브러리를 사용하고 있습니다.
- 나는 C++ 라이브러리를 통합하고 .mm 파일을 구현하여 C++과 objective c를 연결합니다.
이 .mm 브리지를 사용하여 내 목표 C에서 성공적으로 C++ 함수를 호출 할 수 있습니다.콜백 함수를 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 라이브러리에서 이러한 콜백 함수의를 호출해야 할 때 ++ 도서관.
이것은 내 wrapper.mm 파일로, C++ 메소드를 래핑하고 객관적으로 호출해야합니다. c.
- (무효) WrapLogin (는 NSString *) 이메일 (는 NSString *) PWD {
self.wrappedModelAccessMega-> 로그인 ([이메일 UTF8String에], [PWD UTF8String에]); 즉, 무효 ++ 라이브러리 아무것도 반환 C에서 로그인 mfunction 같은 는 // 없음 반환하지
}
내가 잠시에서 작업을 이미 지금이 붙어있어 내 목표 C 라이브러리에이 라이브러리를 통합하기 위해 열심히 밀어하고 이 콜백 함수로 인해 C++의 콜백 함수를 사용하여 랩핑하고 내 목표 C를 호출하여 결과/결과를 알 수있는 작은 예제를 작성하십시오. 로그인 기능이 돌아 오면 큰 도움이 될 것입니다.
+1 좋은 질문 – icodebuster