'd say a snippet of code is better than thousand of words
I'm afraid a snippet enough to understand my monster would take a few full forum pages and send dr. Frankenshtein running screaming in terror.

The matter is, usual way is to define some functionality, wrap it into a dll, an then make the program load and use it. Everybody knows how this works: you export a function from the dll, the host program calls it...

Well, I turned this upside down. It's the dll that uses the host program like a sack of functions. The host program exports its own functions to the dll via custom-made mechanism (don't ask to show it. It's a veawe of macros includes that would make your eyes hurt).

So, aside from the host program initially loading the dll, feeding it the callback hook address and then calling its OnIdle function repeatedly (and except the fact that the main loop belongs to the host app, because it owns the window and receives all messages), the active participant here is the dll. It calls a lot of host program's functions that have their own try..except blocks used to dispatch and comment errors.

But if something crashes seriously, the exception goes up to the host program that unloads the dll and asks for further instructions.

and safeguard all callback executions in them as well as a top-level catch block in every exported function which simply sets the return value of the function to some constant...
I'm afraid, if else fails I'll have to take that way. A lot, A hell of a lot of work. There are more than hundred functions that i would need to revise, including all their calls... I'd better not.

Btw., I finally found the variant that works 100%. It seems.
[pascal] procedure RaiseSystemException;
var
a: integer;
p: pinteger = nil;
begin
{$ifdef win32}
RaiseException(0, 0, 0, nil);
{$else}
if CurrentOwner = NOT_A_MODULE //true when the execution goes
// in the host program's main loop
//false when the callto the module dll is
// being performed
then raise EDying.Create('')
else a:=p^;
{$endif}
end; [/pascal]

The result of all this shamanistic dancing: