ModalCallbackFunction::create - What is best practise?

Hello,
I use:

NativeMessageBox::showOkCancelBox( MessageBoxIconType iconType,
                                   const String& title,
                                   const String& message,
                                   Component* associatedComponent = nullptr,
                                   ModalComponentManager::Callback* callback = nullptr );

but recently I found out it always return false. Even though in documentation there is sentence:

If the callback parameter is not null, the method always returns false, and the user’s choice is delivered later by the callback.

So I started experimenting with:

ModalCallbackFunction::create( void(*)(int, ParamType)  functionToCall,
                               ParamType parameterValue );

And the problem is it requires lambda which need to be static method. But I have in my class a lot of variables which are not static and I need to use them in the lambda. And as ParamType need to be some primitive type so I can’t use the reference to my class.
So I found workout to use as ParamType the void*. And I cast my class instance to void* and use it as a parameterValue. And then inside of lambda method I use static_cast<myClass*> and then I can use not static variables from instance of my class. And it works fine, but I didn’t any extensive tests.

So the questions are:

  1. Is it appropriate solution in my case?
  2. If it’s wrong solution, then what is best solution? Do I really need to remodel whole my class to have all necessary variables as a static variables?

For any advice great thanks in advance.
Best Regards

A better approach might be to use

template <typename CallbackFn>
ModalComponentManager::Callback* ModalCallbackFunction::create (CallbackFn&& fn);

This allows you to pass an arbitrary callable object, e.g. a lambda which captures references to the necessary state. Be careful that none of the references dangle! You might find it useful to capture a WeakReference to this, rather than capturing this directly, so that you can detect whether the captured item has been destroyed before you try to use it.