Do dll callback

Store a reference to your object in a global weak object pointer, and use a global function or a non-capturing lambda to route the callback back into the object :

TWeakObjectPtr<UWebClientHandler> GlobalPtr = nullptr;

void UWebClientHandler::Init()
{
    GlobalPtr = this;
}

void UWebClientHandler::RegCallBack()
{
    PtrCatchErrorFunc = &GlobalCatchError;
}

void GlobalCatchError(const char* msg)
{
    if (GlobalPtr.IsValid())
        GlobalPtr->CatchError(msg);
}

void UWebClientHandler::CatchError(const char* msg)
{
    //...
}

Obviously this only works properly if you have only one UWebClientHandler object.
If you have multiple simultaneously, you’ll have to somehow associate each callback with each instance. This might not be possible if the API doesn’t provide more specific callbacks (like for example with some extra parameters to discriminate).
If you plan to have a finite amount, you could resort to adding as many weak pointers and associated global callbacks as needed, and round-robin between them.

1 Like