I have two programs that call a dll. I want to have them both make sure to call the same instance of the dll so it can be used to pass information back and forth.
How can I correctly pinvoke the same instance so that both programs are talking to the same dll and information can be passed back and forth using the dll as an intermediately with reverse pinvokes and callsbacks.
Is pinvoke not the way to do this? Is there a better way?
It is called “shared section in DLL” and it would let your somehow share data between all processes that load that DLL.
You will not be able to share callbacks as code is running in different processes. You need some sort of IPC (inter-process communication) mechanism to do that.
Overall I would recommend against doing it as it is unusual approach to sharing data between applications. You will unlikely to find help and samples how to do that and would need to read the book (Windows Internals, useful read anyway) to do it properly on your own.