Link to home
Start Free TrialLog in
Avatar of dmf9000
dmf9000

asked on

callbacks in c++

Hello, someone can to get me samples of callbacks in c++.How I define an interface callback?
How I use the interface .
Thanks.

Avatar of jhance
jhance

Your question is difficult to address.  It's clearly OFF TOPIC since "callbacks" are NOT a part of the C++ language.  Further, while many operating systems support things called callbacks, the way they do that is varied.

I suggest you clarify your question and explain what it is you're trying to de in DETAIL.  Another suggestion would be to ask the EE moderators to move this question to a more appropriate topic area.  The best choice would be the PROGRAMMING topic area for your specific operating system.
If by interface you're talking COM interfaces. then read on.

----------------------------
Reproduced from http://www-tcsn.experts-exchange.com/questions/20751731/DCOM-Connection-Points.html
----------------------------

*All* that is needed is an interface pointer exchanged and held by each side of the *conversation*.

-- you do know IDL don't you --

[
     object,
     uuid(...),
     helpstring("IMyClient Interface")
]
interface IMyClient : IUnknown
{
    [helpstring("method ClientMethod")]
    HRESULT ClientMethod(...);

...
};

[
     object,
     uuid(...),
     helpstring("IMyServer Interface")
]
interface IMyServer : IUnknown
{
    [helpstring("method AdviseClient")]
    HRESULT AdviseClient([in] IMyClient*);

...
};


All that is required is for the client to instantiate the server:

IMyServer* pMyServer = 0;
CoCreateInstance(..., &pMyServer);  // assuming the AppId registry value is set-up to instruct DCOM usage
pMyServer->AdviseClient(static_cast<IMyClient*>(this));

At which point the IMyServer implementation can invoke the client method ClientMethod:

m_pMyClient->ClientMethod(...);       // assuming m_pMyClient is typed as IMyClient*

as and when it feels necessary to do so.

Simple as that. No MFC. No IConnectionPoint etc.

[This example assumes that standard marshalling is employed. Also that IMyClient is implemented on the client class represented by 'this' - otherwise the normal QI mechanism should be employed instead.]
ASKER CERTIFIED SOLUTION
Avatar of Dexstar
Dexstar

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
dmf9000:

> Hello, someone can to get me samples of callbacks in c++.How I define an interface callback?
> How I use the interface .

Actually, I found a good site that describes an example similiar to the one I gave you.
     http://www.gmonline.demon.co.uk/cscene/topics/misc/cs7-04.xml.html

Dex*