DLL with shared data/class not sharing... 
Author Message
 DLL with shared data/class not sharing...

Hi
Im writing a number of apps which need a common class for accessing/storing
various items. The class will be in a shared data segment of a dll (mfc_extn
dll) thus:

////////////////////////////////////////////////////////////////////////////
/
// Here are the global variables...
////////////////////////////////////////////////////////////////////////////
/

#pragma data_seg(".data")
CData* ptrData = NULL;
CData theData;
#pragma data_seg()
#pragma comment(linker, "/SECTION:.data,RWS")

__export etc... CData* getCommonData()
{
 ptrData = &theData;    // just in case the data is relocated...
 return ptrData;

Quote:
}

Testing this from first app & data can be read/write ok. from 2nd app, ptr
is returning same value but accessing the class from within the 2nd app does
not giveme the data set in the first...

// ie 1st app...
ptr = getCommonData()
ptr -> setInfo("foo")

// 2nd app...
ptr = getCommonData()
ptr -> getInfo()  <> "foo"

I have done this sort of thing with COM in the past but for this application
there are a number of reasons why we do not wish to go that route..
Any Ideas?
Many Thanks in advance..
Mark



Tue, 02 Mar 2004 23:36:49 GMT  
 DLL with shared data/class not sharing...

Quote:
>#pragma data_seg(".data")
>CData* ptrData = NULL;
>CData theData;

Mark,

You need to initialise theData class - which I suspect isn't
appropriate for you. However, the problem with trying to share a
pointer is that there's no guarantee that the memory will be mapped to
the same address in each process. See Q100634 "HOWTO: Specify Shared
and Nonshared Data in a DLL" for more information.

Dave
--
MVP VC++ FAQ: http://www.mvps.org/vcfaq
My address is altered to discourage junk mail.
Please post responses to the newsgroup thread,
there's no need for follow-up email copies.



Wed, 03 Mar 2004 03:56:15 GMT  
 DLL with shared data/class not sharing...
Dave

Thanks for that but... I understand that the memory location wil probably
change hence the call to get the address of the dataclass before I do
anything with it..
i.e I always call..

getCommonData()
{
 ptrData = &theData;
 return ptrData;

Quote:
}

I have changed the construction of the class to also initalize it
CData theData("");

when running from 2 apps, the *ptr returned is always the same value but the
data returned from within the class is not..

Ie. 1st app sets data to "111" 2nd app getData = "".

If I then try to set the data from the 2nd App, I get all sorts of memory
access assertions...

Many Thanks
Mark


Quote:
> >#pragma data_seg(".data")
> >CData* ptrData = NULL;
> >CData theData;

> Mark,

> You need to initialise theData class - which I suspect isn't
> appropriate for you. However, the problem with trying to share a
> pointer is that there's no guarantee that the memory will be mapped to
> the same address in each process. See Q100634 "HOWTO: Specify Shared
> and Nonshared Data in a DLL" for more information.

> Dave
> --
> MVP VC++ FAQ: http://www.mvps.org/vcfaq
> My address is altered to discourage junk mail.
> Please post responses to the newsgroup thread,
> there's no need for follow-up email copies.



Fri, 05 Mar 2004 15:40:45 GMT  
 DLL with shared data/class not sharing...

Quote:
>Thanks for that but... I understand that the memory location wil probably
>change hence the call to get the address of the dataclass before I do
>anything with it..
>I have changed the construction of the class to also initalize it
>CData theData("");

>when running from 2 apps, the *ptr returned is always the same value but the
>data returned from within the class is not..

Mark,

Have you checked Knowledge Base article Q100634? I think that the
information mentioned in its Summary Note still applies in your
situation.

Dave
--
MVP VC++ FAQ: http://www.mvps.org/vcfaq
My address is altered to discourage junk mail.
Please post responses to the newsgroup thread,
there's no need for follow-up email copies.



Fri, 05 Mar 2004 16:11:32 GMT  
 DLL with shared data/class not sharing...
Dave

Ok, read, re-read, & re-read again..

So.. even so I am getting the address of the class each time I need it
before ANY action, the fact is that private data in the class may not be in
the shared segment and therefore not avaliable?

So.. in that case .. is there any other method avaliable for me to create a
class in a global memory pool? Or any other suggestions? (I was keeping away
from com as the apps will need to be ported to CE in  the near future & I
was trying to keep overheads to a minimum..) but I may have no option..

Many thanks dave
Regards
Mark


Quote:
> >Thanks for that but... I understand that the memory location wil probably
> >change hence the call to get the address of the dataclass before I do
> >anything with it..

> >I have changed the construction of the class to also initalize it
> >CData theData("");

> >when running from 2 apps, the *ptr returned is always the same value but
the
> >data returned from within the class is not..

> Mark,

> Have you checked Knowledge Base article Q100634? I think that the
> information mentioned in its Summary Note still applies in your
> situation.

> Dave
> --
> MVP VC++ FAQ: http://www.mvps.org/vcfaq
> My address is altered to discourage junk mail.
> Please post responses to the newsgroup thread,
> there's no need for follow-up email copies.



Fri, 05 Mar 2004 17:23:05 GMT  
 DLL with shared data/class not sharing...

Quote:
>So.. even so I am getting the address of the class each time I need it
>before ANY action, the fact is that private data in the class may not be in
>the shared segment and therefore not avaliable?

Yes - that's what I believe anyhow.

Quote:
>So.. in that case .. is there any other method avaliable for me to create a
>class in a global memory pool? Or any other suggestions?

Adopt a less complicated method - just share a structure with the data
that can easily be put in the shared area?

Dave
--
MVP VC++ FAQ: http://www.mvps.org/vcfaq
My address is altered to discourage junk mail.
Please post responses to the newsgroup thread,
there's no need for follow-up email copies.



Fri, 05 Mar 2004 19:12:39 GMT  
 DLL with shared data/class not sharing...
Ill try that - thacks again Dave


Quote:
> >So.. even so I am getting the address of the class each time I need it
> >before ANY action, the fact is that private data in the class may not be
in
> >the shared segment and therefore not avaliable?

> Yes - that's what I believe anyhow.

> >So.. in that case .. is there any other method avaliable for me to create
a
> >class in a global memory pool? Or any other suggestions?

> Adopt a less complicated method - just share a structure with the data
> that can easily be put in the shared area?

> Dave
> --
> MVP VC++ FAQ: http://www.mvps.org/vcfaq
> My address is altered to discourage junk mail.
> Please post responses to the newsgroup thread,
> there's no need for follow-up email copies.



Sat, 06 Mar 2004 14:37:33 GMT  
 
 [ 7 post ] 

 Relevant Pages 

1. file sharing under DOS (share not necessarily loaded)

2. Share CObArray Object using DLL Section share method

3. Shared data segment not working

4. Sharing data between classes

5. VB <-> Dll data sharing

6. Sharing data in .dll usings #pragma data_seg()

7. Sharing data in dll?

8. Sharing data with other instance of my DLL

9. Pointers to shared data in DLL???

10. Sharing data across dlls

11. sharing data in win32 dll

12. sharing data between application and DLL

 

 
Powered by phpBB® Forum Software