Shared DLL?

Started by
4 comments, last by rmsimpson 18 years, 4 months ago
Well what I want to do is link the same dll to two different applications, and have them share memory across this DLL, IE one app which is linked to a game will call a function and fill in a list of prices for objects in the game, I want another application to then be able to call a function and retrieve this list, how would I go about that?
Advertisement
From what I understand, you can't, or at least shan't :-)

Each executable that runs has its own memory addressing space. That is, two executables could simultaneously have pointers to 0x3003fa12, but they actually point to separate areas of physical (or virtual) memory. The operating system makes sure that you don't overstep your bounds into other peoples' memory. Poking around outside your space is likely to result in segmentation faults (read: catastrophic failure).

The answer is to have some kind of third party communicate between the two. A database (probably not for a game), a TCP/IP socket connection (very reliable and fast on the localhost), or something like that.

Correct me if I'm wrong.



~BenDilts( void );
Well your right about the memory I knew about that problem already. However I was hoping to keep this as simple as possible, and did not want to have to resort to some TCP sockets, or file access.
Here's a Microsoft example of how to share memory between processes: Creating Named Shared Memory.

There are other ways to pass data between applications. The topic is named Interprocess Communications. You can find the details at that link.
"I thought what I'd do was, I'd pretend I was one of those deaf-mutes." - the Laughing Man
A quick and dirty hack would be to send a WM_USER type of window message across applications to that your server dumps a file to a specific location (i.e. PostMessage(HWND_BROADCAST, ...) ). The server can send a WM_USER type of window message once this is done so you can pick up the file. You need to register your WM_xxxx message first with RegisterWindowMessage().
Here's a very simplistic method of sharing memory in a DLL:

#pragma data_seg(".shared")  int g_sharedInteger = 0;  CHAR g_sharedArray[64][64] = {0};#pragma data_seg()#pragma comment(linker, "/SECTION:.shared,RWS")


Shared memory blocks in code have to be initialized -- so when you declare the variables you must also assign them to something.

Robert

This topic is closed to new replies.

Advertisement