Results 1 to 6 of 6

Thread: Share Variable Across Process?

  1. #1

    Thread Starter
    Hyperactive Member made_of_asp's Avatar
    Join Date
    Jul 2001
    Location
    123 Fake Street
    Posts
    394

    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,
    VS.NET 2003

    Need to email me?

  2. #2
    Monday Morning Lunatic parksie's Avatar
    Join Date
    Mar 2000
    Location
    Mashin' on the motorway
    Posts
    8,169
    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

  3. #3

    Thread Starter
    Hyperactive Member made_of_asp's Avatar
    Join Date
    Jul 2001
    Location
    123 Fake Street
    Posts
    394
    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
    VS.NET 2003

    Need to email me?

  4. #4
    Frenzied Member
    Join Date
    Jul 2002
    Posts
    1,370
    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.

  5. #5
    Frenzied Member
    Join Date
    Jul 2002
    Posts
    1,370
    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.

  6. #6

    Thread Starter
    Hyperactive Member made_of_asp's Avatar
    Join Date
    Jul 2001
    Location
    123 Fake Street
    Posts
    394
    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.
    VS.NET 2003

    Need to email me?

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width