[Last Call] Learn how to a build a cloud-first strategyRegister Now

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 275
  • Last Modified:

MFC DLL with shared data ?

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
kharandir
Asked:
kharandir
1 Solution
 
arunprakashCommented:
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
 
kharandirAuthor Commented:
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
 
kharandirAuthor Commented:
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
VIDEO: THE CONCERTO CLOUD FOR HEALTHCARE

Modern healthcare requires a modern cloud. View this brief video to understand how the Concerto Cloud for Healthcare can help your organization.

 
kharandirAuthor Commented:
I can't do it with class.
0
 
yuryzCommented:
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
 
GGRUNDYCommented:
Does CMyClass have any MFC base classes or members?
Does CMyClass contain any pointer members?
0
 
kharandirAuthor Commented:
I can't do it with class.
0
 
kharandirAuthor Commented:
I have one class that doesn't have any MFC base class. But I have one that have a CString class.
0
 
MirkwoodCommented:
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
 
kharandirAuthor Commented:
I have one class that doesn't have any MFC base class. But I have one that have a CString class.
0
 
kharandirAuthor Commented:
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
 
MirkwoodCommented:
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
 
kharandirAuthor Commented:
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
 
kharandirAuthor Commented:
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
 
kharandirAuthor Commented:
Adjusted points to 350
0
 
mikezangCommented:
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

What does it mean to be "Always On"?

Is your cloud always on? With an Always On cloud you won't have to worry about downtime for maintenance or software application code updates, ensuring that your bottom line isn't affected.

Tackle projects and never again get stuck behind a technical roadblock.
Join Now