Reputation: 107
I have a huge program (A) which uses about 30 (most of my own, some 3rd party) dll´s. It uses ActiveX, ATL and MFC to do different stuff. Now i want to use wxWidgets for some special tasks and will call the wxWidgets dialogs from within the program. I can do this with a special designed DLL which takes the wxW.. parts. But to run the special tasks with or without the A programm i would to like to put the wxW.. stuff in an exe (B) and these exe should address the same data from the A program. As far as i know each *.exe has its own process and so i can not share the same pointer address.
I can put in some shared data block in one of the DLLs.
#pragma data_seg("SHARED")
CClassA *g_ClassAPointer=NULL;
#pragma data_seg()
#pragma comment(linker, "/section:SHARED,RWS")
If the A is running and starts B, i can get the pointer g_ClassAPointer with the address within A. Is there a way to get the address or get an offset to reach this address within B ?
Thanks in advance,
Howie
BTW: We also want to use wxWidgets to fade all the MFC stuff more and more to cross platform code otherwise i would stick to MFC or use the wxW - DLL within a wrapper *.exe.
Upvotes: 1
Views: 629
Reputation: 180303
You're looking for shared memory, and the usual way to create that is via CreateFileMapping
. This can create shared memory backed by a named file, or backed by the paging file. (Memory allocated by GlobalAlloc
is also backed by the paging file, so that's no unusual thing).
In either case, the memory block from CreateFileMapping
is named, so another process can access the shared memory block by calling OpenFileMapping
with the same name.
Keep in mind that the shared memory block might reside at different offsets in memory. Also, if you put CClassA
in shared memory, there's no automatic mechanism to ensure that all pointers inside CClassA
point to the same shared memory block. E.g. putting a std::string
or MFC CString
in shared memory is unlikely to achieve what you intended.
Upvotes: 2