Skip to main content
gamedev.net
🔒 Locked

Shared DLL?

Started by BleedingBlue 4 replies 1.7k views
Original Post
BleedingBlue
BleedingBlue
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?
BeanDog
BeanDog
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 );
BleedingBlue
BleedingBlue
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.
LessBread
LessBread
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
rmsimpson
rmsimpson
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

Topic Locked

This topic has been locked by a moderator. New replies are not allowed.

Sign in to reply to this topic.