Solved

MFC DLL with shared data ?

Posted on 1999-01-14
16
259 Views
Last Modified: 2013-11-20
Hi,

I have created a MFC DLL. This DLL allocates system resources (audio pipes for a specific hardware) that will be used by one or more applications. I have some globals structures that describe the state of these resources.

How can I make that these structures are the same for all the applications ? (like a data space shared by one or more application)

Thanks in advance for your help
0
Comment
Question by:kharandir
16 Comments
 
LVL 1

Expert Comment

by:arunprakash
ID: 1327681
Hi here is what u need,



Create named data sections using the #pragma statement.
        OR
Use memory-mapped files.
However, if you need to share a C++ class instance, you should use a memory-mapped file, because each time a process attaches to the DLL, the constructor for the object is called. For example:

#pragma  data_seg(".myseg")
  _declspec(dllexport) CTest Counter1(0);
  _declspec(dllexport) short Counter2 = 0;
#pragma data_seg()


Assume that the variables Counter1 and Counter2 are incremented in a function in the DLL. The value of Counter2 increases as expected, but on each process attach, the constructor for Counter1 is called reinitializing it to zero. In order to share Counter1, you must use a memory-mapped file. For more information about memory-mapped files, see File Mapping in the Win32 SDK documentation.

I got this from help.
Im sure this will solve ur problem.
thanx,
bye
0
 

Author Comment

by:kharandir
ID: 1327682
Thanks for your answer.
I have succeed to share variables, arrays and structures. What I still need is to share a class (CMyClass m_MyClass).

Is it possible and how ?
0
 

Author Comment

by:kharandir
ID: 1327683
Thanks for your answer.
I have succeed to share variables, arrays and structures. What I still need is to share a class (CMyClass m_MyClass).

Is it possible and how ?
0
 

Author Comment

by:kharandir
ID: 1327684
I can't do it with class.
0
 
LVL 1

Expert Comment

by:yuryz
ID: 1327685
I heard there is way to create DLL's which is loading only ONCE for all processes. So, all objects in data segments would be single instance for all apps. Im not sure how well MFC would behave in that case :]
0
 
LVL 3

Expert Comment

by:GGRUNDY
ID: 1327686
Does CMyClass have any MFC base classes or members?
Does CMyClass contain any pointer members?
0
 

Author Comment

by:kharandir
ID: 1327687
I can't do it with class.
0
 

Author Comment

by:kharandir
ID: 1327688
I have one class that doesn't have any MFC base class. But I have one that have a CString class.
0
Free Trending Threat Insights Every Day

Enhance your security with threat intelligence from the web. Get trending threat insights on hackers, exploits, and suspicious IP addresses delivered to your inbox with our free Cyber Daily.

 
LVL 13

Expert Comment

by:Mirkwood
ID: 1327689
If a DLL is loaded by multiple processes you have multiple instances of this global data. The only thing that you can do is read it from a global piece of information.
Take a look at GlobalAddAtom and its friends.
0
 

Author Comment

by:kharandir
ID: 1327690
I have one class that doesn't have any MFC base class. But I have one that have a CString class.
0
 

Author Comment

by:kharandir
ID: 1327691
But there is not only a CString ... there is a CWinThread.
I have tried to copy the adress of the thread in a shared variable but it doesn't work either.
How to share a MFC Class ? Is t possible ?
0
 
LVL 13

Expert Comment

by:Mirkwood
ID: 1327692
Sure create an out of process server. Not within a dll.
Altough you may try IGlobalInterfaceTable altough that is meant for between apartments and not within processes.
0
 

Author Comment

by:kharandir
ID: 1327693
But there is not only a CString ... there is a CWinThread.
I have tried to copy the adress of the thread in a shared variable but it doesn't work either.
How to share a MFC Class ? Is t possible ?
0
 

Author Comment

by:kharandir
ID: 1327694
I need to share a CWinThread and a CDialog in the DLL.
I have tried using FileMapping but it doesn't really work.

Please, help me
0
 

Author Comment

by:kharandir
ID: 1327695
Adjusted points to 350
0
 
LVL 5

Accepted Solution

by:
mikezang earned 350 total points
ID: 1327696
I guess your DLL is Regular DLL, you need to use Extension DLL if you wanto share a class Refer MFC Advanced Concepts sample DLLHUSK
0

Featured Post

IT, Stop Being Called Into Every Meeting

Highfive is so simple that setting up every meeting room takes just minutes and every employee will be able to start or join a call from any room with ease. Never be called into a meeting just to get it started again. This is how video conferencing should work!

Join & Write a Comment

Suggested Solutions

Title # Comments Views Activity
Show shut-down message as Windows 8 shuts down. 9 74
Folder Comparison 12 52
move a line in eclipse 3 60
withoutTen challenge 14 88
This is to be the first in a series of articles demonstrating the development of a complete windows based application using the MFC classes.  I’ll try to keep each article focused on one (or a couple) of the tasks that one may meet.   Introductio…
If you use Adobe Reader X it is possible you can't open OLE PDF documents in the standard. The reason is the 'save box mode' in adobe reader X. Many people think the protected Mode of adobe reader x is only to stop the write access. But this fe…
This video will show you how to get GIT to work in Eclipse.   It will walk you through how to install the EGit plugin in eclipse and how to checkout an existing repository.
Internet Business Fax to Email Made Easy - With eFax Corporate (http://www.enterprise.efax.com), you'll receive a dedicated online fax number, which is used the same way as a typical analog fax number. You'll receive secure faxes in your email, fr…

706 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

17 Experts available now in Live!

Get 1:1 Help Now