我有一个类似的项目,其中大部分逻辑都是作为 C++ 库实现的,它可以编译为静态库或动态库。我也有一个命令行 C++ 测试程序,所以我所有的回调,基本上相当于他们在选择取消的情况下已经走了多远,都被实现为简单的 C++ 回调:
extern "C"
{
/**
* Callback function from long operations.
*
* @param gameNum The number of the game being processed (1-based).
* @param percentComplete Processing progress. (0.0 to 100.0).
* @param contextInfo Context Info passed to the database method.
*
* @return false to terminate processing, else true.
*/
typedef bool(*DATABASE_CALLBACK_FUNC)(unsigned gameNum, float percentComplete, void *contextInfo);
}
这在 C++ 命令行工具中与基于 Objective-C++ 的 Cocoa 应用程序同样有效。
请注意,我使用extern C
它也可以从 C 中使用。