Go Premium for a chance to win a PS4. Enter to Win

x
?
Solved

OBJECT Sharing

Posted on 1998-03-10
8
Medium Priority
?
258 Views
Last Modified: 2011-09-20
How to make  c++ OBJECT shared .
I have a c++ dll from where data to be shared between
two different process.

i am using microsoft Vc++5.0

0
Comment
Question by:peri
  • 5
  • 2
8 Comments
 
LVL 22

Expert Comment

by:nietod
ID: 1183314
answer coming
0
 
LVL 22

Expert Comment

by:nietod
ID: 1183315
You didn't give me much information, so this may only be a start at an answer.  If you need more post a comment with some more info.

to make a class exported from a DLL, use __declspec(dllexport)  like

class __declspec(dllexport) ExportedClass
{
 // stuff
};
0
 
LVL 22

Expert Comment

by:nietod
ID: 1183316
This allows the class to be used by programs/dlls that use your dll.  You may want to use a macro to define __declspec(dllexport)  like

#define declspec(dllexport) DllExp

Is there more you need?
0
Concerto Cloud for Software Providers & ISVs

Can Concerto Cloud Services help you focus on evolving your application offerings, while delivering the best cloud experience to your customers? From DevOps to revenue models and customer support, the answer is yes!

Learn how Concerto can help you.

 

Author Comment

by:peri
ID: 1183317
Environment : 32-bit

I have done data sharing between different instances of a DLL using the following method.

I named the data segment as below
#pragma data_seg(".sdata")
int gnData = 0;      // Global integer to be shared - Line number 1
#pragma data_seg()

I gave the attributes of this "named data segment" in the .def file.
Partial contents of .def file
// other sections of the .def file are omitted for simplicity..
==== Start  of the def file ====
SEGMENTS
.sdata  READ WRITE SHARED
==== End of the def file ====


What I want to do is gnData should be a class object.
Example
Assume a class like this..
Class Myclass
{'
 private :
      int m_data;
public:
      Myclass();
      ~Myclass();
}
Then Line number 1 mentioned above should be
Myclass gnData;

It is clearly mentioned in the MSDN that for an object to be in shared data segment. It should be initialized. This means that I should use initializer list "{ }"  if it is a user defined type. This cannot be done for a class objects....

One more thing I observed was I was able to share the class objects if I did not have any constructors. This allows me to use the initializer  lists....
Anyway the main thing that is preventing me from doing this the initializtion  "Shared Objects Need to be initialized...And class objects cannot have initializer lists"

Questions :
1.      Is there a way to work around this ???
2.      Is it not possible for C++ object to go in the named shared data segment??

Thanks in advance,
peri
0
 
LVL 4

Accepted Solution

by:
jtwine100697 earned 180 total points
ID: 1183318
[Answer coming?  What does that mean?]

   It sounds like you want two instances of an application to share the same INSTANCE of a class.

   You can have both applications create seperate instances of the same class, and pass them both, say, the same numeric identifier, and the class instances might be able to communicate via pipes, or some other shared memory arch.  Under MFC, you could use CMemFile.

-=- James.
0
 
LVL 22

Expert Comment

by:nietod
ID: 1183319
Sorry Peri, I didn't understand what you were looking for before.  I'm afraid jtwine doesn't either.

jtwine, the data in a window's dll is usually maintained seperately for each process.  That is, each proccess has a seperate copy of the data.  However, you can create segments that contain data that is shared among all the proccesses using the Dll.  Peri wants to put an object in such a segment.  Unfortunatley, I have no experience in this area.
0
 
LVL 4

Expert Comment

by:jtwine100697
ID: 1183320
  I understand that...  I have used a DLL to share data across to seperate applications before.

   I do not believe that sharing the same instance of an object is the best means to obtain communication here, and that is what it sounds like Peri is trying to do.

   Looks like Peri wants a struct-like object (class) to have the same data for both applications.  So if one application changes a member, the change is reflected in the other application as well.

   This can be done with "smart structures".  The strucures could create a Named Pipe, and preform sync. communication behind-the-scenes.

-=- James.
0
 
LVL 22

Expert Comment

by:nietod
ID: 1183321
I see.  Without understanding where you were coming from, I thought you were totally of track.

I can agree that it may not be the best way, there are lots of pitfalls.  But without knowing more about what Peri is trying to do its is hard to say if there is a better way.
0

Featured Post

Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

C++ Properties One feature missing from standard C++ that you will find in many other Object Oriented Programming languages is something called a Property (http://www.experts-exchange.com/Programming/Languages/CPP/A_3912-Object-Properties-in-C.ht…
Basic understanding on "OO- Object Orientation" is needed for designing a logical solution to solve a problem. Basic OOAD is a prerequisite for a coder to ensure that they follow the basic design of OO. This would help developers to understand the b…
The viewer will learn additional member functions of the vector class. Specifically, the capacity and swap member functions will be introduced.
The viewer will be introduced to the technique of using vectors in C++. The video will cover how to define a vector, store values in the vector and retrieve data from the values stored in the vector.
Suggested Courses

971 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