This question isn't really specific, but more general.
So let's say I have program A and program B which both use the same dynamic library for example apple.dll. And both programs would use the same instance of the dynamic library so changes made with one program in the .dll would also be seen by the other program. So when for example I add two apples in program A, then if I get apples in program B it should return 2.
See illustration below
So my question is how to achieve this behavior (if it is even possible) and if one solution is cross platform.