CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 3 of 3
  1. #1
    Join Date
    Apr 1999
    Posts
    6

    Sharing data between App. and dll

    Hello!
    I have two applications, let it be called AppServer and AppClient. They use the same dll.
    How should I write function in the dll so when AppClient execute it, the function can access data of the AppServer, for example tell AppServer to do something or just ask it for current status?
    It's possible to declare shared variables in dll so there is no problem to put in shared memory the handle (HWND) and instance of AppServer, but I cannot store there pointers to variables and functions of AppServer because the AppServer moves to another part of memory when AppClient execute the function and pointers became invalid.

    I suppose that there is a way get CWinApp* from hInstance or maybe I'm wrong or I should to pass global pointers or I even don't know.
    Thanks! Constantin Kuznetsov Jr.


  2. #2
    Guest

    Re: Sharing data between App. and dll

    Your AppServer and your AppClient are running in two different processes, each has its own address space. Therefore you cannot share data between the two using a pointer. You need to use global shared memory.

    Check the VC++ online help for the following functions: GlobalAlloc, GlobalLock, and GlobalFree. Besides using global shared memory, there are other solutions. For example,

    1. Stored shared data in a database table.
    2. Stored shared data in a file.
    3. Stored shared data in the windows registry.
    4. Stored shared data in your AppServer, but provide COM interfaces so that your AppClient can read and write the data.

    Note that if your AppServer and AppClient have to run on different machines, then global shared memory won't work for you. But all the above except 3) will still work in this case.

    Xiangyang Liu



  3. #3
    Join Date
    May 1999
    Location
    PA
    Posts
    38

    Re: Sharing data between App. and dll

    I hope, memory maped files may solve your problem because I guess memory maped file is the only simple way to share memory between two applications in Win32 environment

    Thanks


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

Featured