I want to create a CGDisplayStream with the CGDisplayStreamCreateWithDispatchQueue c function, which expects an CGDisplayStreamFrameAvailableHandler as parameter.
CGDisplayStreamFrameAvailableHandler is an objective-c block.
I tried to use a c++ lambda but this doesnt work:
No viable conversion from '(lambda at ###RECTRACTED###)' to 'CGDisplayStreamFrameAvailableHandler' (aka 'void (^)(CGDisplayStreamFrameStatus, uint64_t, IOSurfaceRef _Nullable, CGDisplayStreamUpdateRef _Nullable)')
I found: Objective-C Blocks in C but this doesnt really help, since they didnt explain what is needed to create an objective-c block in plain c or c++.
How can i create a valid object which i can pass to CGDisplayStreamCreateWithDispatchQueue?
This worked for me:
CGDisplayStreamFrameAvailableHandler handler = ^void(CGDisplayStreamFrameStatus status, uint64_t timestamp, IOSurfaceRef frameSurface, CGDisplayStreamUpdateRef updateRef) { std::cout << "Update" << std::endl; };Thanks to @molbdnilo for the help.