Re: Sharing a struct/class/pointer in the data_seg() of a dll?

Tech-Archive recommends: Repair Windows Errors & Optimize Windows Performance



On Feb 6, 5:41 am, FFMG <spambuc...@xxxxxxxxxxxx> wrote:
On Feb 6, 6:27 am, "Scott McPhillips [MVP]" <org-dot-mvps-at-scottmcp>
wrote:



"FFMG" <spambuc...@xxxxxxxxxxxx> wrote in message

news:02d43f57-7874-4cf9-8955-cd64b9e8af33@xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx

Hi,

if I do

#pragma data_seg (".seg")
int some_number = 0;
#pragma data_seg()

Then the data sharing works as expected, (the data is shared between
the processes).

But if I do,

#pragma data_seg (".seg")
myclass* m_pSomething = NULL;
#pragma data_seg()

although the value of the pointer, (the 32bit value), itself is shared
the data is invalid.
I am guessing that it is because the memory past the pointer is not
accessible to the other process.

So, how can I share a class object/pointer in a DLL?
How would I be able to achieve the above?

This is as expected.  Different processes are in different address spaces,
so using the same pointer in multiple processes cannot work.  Think of it
this way: Each process has an independent virtual-to-physical address
mapping.  So the (virtual) pointer becomes meaningless outside of the
process where it is created.

Share data, not pointers.

--
Scott McPhillips [VC++ MVP]

It makes sense, and I kind of expected it was the problem.
But how would you share a class for example?

Could I maybe share a function that gets the class?

I am just thinking of the simplest way to share dynamically growing
data between 2 processes.

Many thanks

Simon

I always, always reach for COM first. MSDN has this on inter-process
communication on Windows: http://msdn.microsoft.com/en-us/library/aa365574(VS.85).aspx
.. I tried some of the other mechanisms (Pipes, Shared memory,
mailslots), and they are only good for simplests of cases or seriously
low-level programming.
.



Relevant Pages