Hi,
Does anyone know how to share a pointer with another process? I have to pass a pointer to an CODBC user class to another process.
Thanks for any help,
Printable View
Hi,
Does anyone know how to share a pointer with another process? I have to pass a pointer to an CODBC user class to another process.
Thanks for any help,
If you have that variable in a DLL then both programs *should* be able to access it.
Good idea, but how would I accomplish that? The process1 saves a pointer to a dll, then process2 somehow gets it out? I am lost here :(
No. The DLL has to create the pointer. The class has to live in the DLL.
However, there is no guarantee the pointer will map correctly to the second process. Process-private space (user space) is different for each process. That pointer in Process A will point to a valid object, the same address in process2 may already be used for something else, or may not even be part of the process heap.
You can use ReadProcessMemory to access another process's user space - this is how debuggers work.
On second thought -
Can you have the class create the result in process1, then store it in an atom?
Process2 can always read the result from there. Don't use this to pass pointers - I already showed why it isn't safe. Process2 can feed data back to Process1 to generate the result.
In general, any kind of interprocess communication via an independent intermediary is better than trying to use pointers -
mailslots, sockets, WM_COPYDATA, atoms, or even an ActiveX .EXE (aaaagh!) with global properties.
Thanks for your replies.
It has to be a database pointer. You see, the server app creates the connection in a user-defined class. Then it passses the connection object to various multithreaded dlls (they run like services). But I also have to make some sort of management application - it has to use the database too. I can pass the pointer to dll's, but I can't to another EXE. I guess i will just have to store the whole admin interface in a DLL then.