0

I have a c++ dll which I want to convert to COM object. what are the steps I need to do?

thanks!

3
  • 1
    Before you do, think very carefully about whether you need COM. I once decided I would just convert a DLL to COM, and a few months later, when my codebase was 30% boilerplate, vowed to always avoid COM when I could. aaaand then proceeded to rewrite half of it (the parts I actually needed)... This is extremely involved, so give it a good hard thinking. If you do have to, use source control and start a new branch. Commented Nov 15, 2011 at 7:49
  • Even if you plan to use ATL (which is a good idea, at least for the VS wizards), you'll need to understand quite toroughly how COM works. Especially, you have to understand that COM classes and C++ classes are unrelated objects. Commented Nov 15, 2011 at 7:58
  • peachykeen, you are probably the smartest person in the world, beacuse you know better than the OP what does he really needs. Commented Nov 15, 2011 at 8:01

1 Answer 1

2

Create new ATL project. Add new interface and add the same methods to that interface which are currently exported by your DLL.

Sign up to request clarification or add additional context in comments.

4 Comments

and then modify the methods to match COM conventions, and then set up all the objects to implement the new COMified interfaces, then modify the interfaces again to match the new requirements of the COM objects, and so on. This is much more complex than the answer suggests.
peachykeen, COM is very well defined. What your are saying here has nothing to do with the question, because you have no idea what's the signature of any of the exported functions. You can also downvote, because I didn't mention IDL, threading models, etc... Very "peechy", isn't it?
For what its worth, rather than trying to convert your current class wholesale to an ATL class, consider leaving it as-is, and using the new ATL class as a wrapper class (or Facade in pattern terminology) that does the translation from the COM view of the world to your class' current view of the world. For example, if one of the methods in your class returns a string, rather than converting your class to using BSTR all over the place, just convert the string to BSTR in the outer wrapper layer. This way, your currently working code stays as-is, and you can isolate the COM issues in the wrapper.
@natko Of course COM is well-defined. It's also extensive and complicated, which was all I was pointing out. The downvote was not mine.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.