COM does what you want. It does require a bit of learning though, it's not a simple thing.

A decent starting point is in MSDN under Component Development > Component Object Model (General)

Check the MFC example in the technical articles, this should get you an idea what you can do.