Solved

Interface pointers?

Posted on 2000-02-15
3
226 Views
Last Modified: 2010-04-10
What I'm trying to accomplish:
1.  I have a listener app that waits for a request from a client.
2.  Client connects and request data whenever that listener app gets it.

Generally, I have written programs where the client app pull information from an COM/DCOM object.  I have not written anything where the client makes the initial connection and its up to the DCOM object to push info to the client as it receives it.  
Someone told me that the client would have to pass an interface pointer to the DCOM object so it would know how to get to the client.  Is this true?  If so, how do I proceed.  If there is a better way, let me know.  
0
Comment
Question by:ivanh
3 Comments
 
LVL 32

Expert Comment

by:jhance
ID: 2525086
Of course you have to pass something to the object so it know how to communicate with your client.  The normal way for a COM object to communicate back to a client is via a connection point.
0
 

Accepted Solution

by:
mstout earned 200 total points
ID: 2525199
I think your source is correct.

1) the client needs to connect to the server.  It does this by CoCreateInstanceEx using the hostname of the server machine.

2 simple) Server creates a new object

2 advanced) Server creates a new object if one doesnt exist, or if one exists, just return the current object.
(see DECLARE_CLASSFACTORY_SINGLETON in atl doc).

3) Create a callback interface (say IMyProjCallback) that the server calls when data has changed.

4) Create a method on the server object to register the callback and returning a cookie so that
the client can unadvise.  call it Advise(IMyProjCallback *,DWORD *Cookie)

5) Implement this method by a) create a cookie, store the cookie and the interface pointer in some data structure. (AddRefing where appropriate)

6) Create a method on the server object to unregister the callback. Call it Unadvise(DWOORD cookie)

7) Implement this method by looking up the cookie in the data structure and releasing the interface.

8) When the data changes in your server, Just go through your data structure and call the all the IMyProjCallback interfaces


9) Gee ... this sounds a lot like the IConnectionPoint interfaces: IConnectionPoint,IConnectionPointContainer. You could probably
leverage IConnectionPointImpl template in atl.

10) Problems to deal with a) circular refrences: Server holds on to client and client holds on to server. b) Client and/or server dying...
need to clean up your COOKIE,Interface map when client callback fails.
0
 
LVL 1

Author Comment

by:ivanh
ID: 2528865
jhance:  I realize that and that's assumed, but the real question was implementing a push model vs. a pull.

mstout:  Thanks, I passed it back to my source and he agreed 100% on your comments.  Thankyou.  This gives me a good outline.  This concept is new to me and he helped by explaining your comments.

0

Featured Post

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
how to convert c++ code to Android App 3 83
C++ standard library based binary archive format 6 91
Exception thrown at 0x00007FFD5BC81F28 7 38
max float value 3 26
Unlike C#, C++ doesn't have native support for sealing classes (so they cannot be sub-classed). At the cost of a virtual base class pointer it is possible to implement a pseudo sealing mechanism The trick is to virtually inherit from a base class…
This article shows you how to optimize memory allocations in C++ using placement new. Applicable especially to usecases dealing with creation of large number of objects. A brief on problem: Lets take example problem for simplicity: - I have a G…
The viewer will learn how to pass data into a function in C++. This is one step further in using functions. Instead of only printing text onto the console, the function will be able to perform calculations with argumentents given by the user.
The viewer will learn how to user default arguments when defining functions. This method of defining functions will be contrasted with the non-default-argument of defining functions.

863 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