|
-
Jan 28th, 2003, 09:57 PM
#1
Thread Starter
Hyperactive Member
Share Variable Across Process?
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,
-
Jan 29th, 2003, 06:32 AM
#2
Monday Morning Lunatic
If you have that variable in a DLL then both programs *should* be able to access it.
I refuse to tie my hands behind my back and hear somebody say "Bend Over, Boy, Because You Have It Coming To You".
-- Linus Torvalds
-
Jan 29th, 2003, 07:42 AM
#3
Thread Starter
Hyperactive Member
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
-
Jan 29th, 2003, 10:08 AM
#4
Frenzied Member
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.
-
Jan 29th, 2003, 10:14 AM
#5
Frenzied Member
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.
-
Jan 29th, 2003, 06:20 PM
#6
Thread Starter
Hyperactive Member
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.
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|