Click to See Complete Forum and Search --> : Sharing data between App. and dll


Constantin K
May 3rd, 1999, 06:47 AM
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.

May 4th, 1999, 10:43 AM
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

Chetan
May 4th, 1999, 02:14 PM
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