简体   繁体   中英

How to set a callback from C++ console application to a C++ COM DLL

This is the problem I am trying to solve.

My C++ console application is interacting with a C++ COM DLL.

Upon certain conditions, the C++ COM DLL needs to send some data back to the console application. I was thinking to pass a callback (std::function) as a parameter of one of the DLL API, but I do not know if COM supports that.

How could I implement such callbacks?

Thank you for your help!

There is a sample program that is likely to be helpful for your problem.
This is an example of specialized interface called IPortableDevice/IPortableDeviceEventCallback.
Project root Portable Devices COM API Sample
CallBack registration/release part DeviceEvents.cpp

As a general purpose principle, the COM-DLL you use must implement the IConnectionPoint interface.
The application implements the IConnectionPointContainer interface and registers CallBack(=Event Handler) by calling IConnectionPoint::Advice with that object as a parameter.

Please search variously with IConnectionPoint/IConnectionPointContainer.

There is no other code example, but there is also this article.
What is IconnectionPoint and EventHandling

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM