Take the 2-minute tour ×
Programmers Stack Exchange is a question and answer site for professional programmers interested in conceptual questions about software development. It's 100% free, no registration required.

I need to learn COM for my current project. I am a noob and I haven't been able to find good starting points for COM. I have been looking into MSDN and googling... I did find some interesting articles on codeproject.com, but I am not satisfied. Why do we use COM ? Why does it exist ? In what places does it exist ? ..... and so on .. So, will you please tell me where can I find answers to these questions ?

share|improve this question
2  
Why do we use COM? Mostly we try not to. In what places does it exist? Painful legacy codebases, generally. –  Carson63000 May 9 '11 at 9:40
    
@carson actully i am developing a monitoring software where i need to fetch values of "COM" objects. Hence the new found Quest .. –  Ritwik G May 9 '11 at 9:54
1  
If I remember correct, of the best 3 web articles on COM, 2 was on MSDN (some old magazine article) and 1 was on CodeProject... obviously there are hundreds of other somewhat useful ones, so it's like finding needle in haystack. (and thanks Google for returning only sites in the ".com" TLD when I search for "COM"...) –  rwong May 10 '11 at 3:18
    
@Carson63000 So true it hurts... going to go cry in a corner now. –  Evicatos Nov 7 '13 at 22:55
add comment

closed as off-topic by gnat, ChrisF Nov 7 '13 at 22:49

This question appears to be off-topic. The users who voted to close gave this specific reason:

  • "Questions asking us to recommend a tool, library or favorite off-site resource are off-topic for Programmers as they tend to attract opinionated answers and spam. Instead, describe the problem and what has been done so far to solve it." – gnat, ChrisF
If this question can be reworded to fit the rules in the help center, please edit the question.

5 Answers

up vote 11 down vote accepted
  • Firstly, COM is just like object-oriented programming. COM interface is an abstract interface.
  • COM has an advantage over each language's own built-in OOP in that you can have COM classes implemented in different languages and/or compiled by different versions of compilers, and they will still be able to inter-operate. This is called "application binary interface" (ABI)
  • COM uses reference counting. It might be annoying at first, but as soon as you learn about smart pointers, your life will be much easier and you will find that the concept of reference counting is very easy to understand.
  • COM uses a weird way of class casting, namely "Query Interface".

Learning the IUnknown is the first step.

A good COM interface that is suitable for beginner's study is the IStream interface. You may practice COM by implementing the IStream interface using many kinds of ways of storing data.


Added 2012/09/28:

After the COM mechanism was invented, people at Microsoft discovered that these mechanisms open the door to unusual programming tricks which are not orthodox OOP. At the lowest level, IUnknown.QueryInterface is just a method; it can do anything. These tricks make COM intimidating to learners, because they can invalidate the basic reasoning that can be borrowed from OOP.

The Microsoft documentation at MSDN spends a lot of time saying "COM is not ..." or "Make no assumption" explaining how these unusual tricks can break your code.

COM designers use Liskov Substitution Principle (the "L" in SOLID) to make sure their multiple interfaces and use of tricks do not invalidate basic OOP reasoning or program operation.

If your project does not use these tricks, it is okay to see COM just from the OOP point of view. If your project uses these tricks, you will need to see COM as self-modifying code.

(Joke: We had to spend so much time with L that we typically ignore the four other principles.)

share|improve this answer
add comment

The main reason for COM is to provide an object oriented communications interface between an application and other applications and dll's that may live in different memory spaces, and between objects that may have different internal object representations.

Something to remember when learning COM is that at the time C++ was king and applications called dll's using C. There was no common ABI (as @rwong says) and COM was the microsoft solution.

It's probably worth having a look at Active Template Library (ATL) for visual studio which makes it a bit easier to use COM as well.

A couple of books I found useful back in the day

http://www.amazon.com/Essential-COM-Don-Box/dp/0201634465/ref=sr_1_1?ie=UTF8&qid=1304946825&sr=8-1

http://www.amazon.com/Understanding-ActiveX-OLE-Developers-Technology/dp/1572312165/ref=pd_sim_b_4

hth

share|improve this answer
1  
+1 for recommending Essential COM. –  user16764 May 9 '11 at 16:27
add comment

I originally learned about COM from the book Learning DCOM (DCOM is just an extension of COM, the book is mostly about COM). It's over ten years old and should be cheap if you get it used (since COM isn't exactly hot anymore, not even in the Microsoft world, even though it's still used for interop).

The main reason for COM to exist is to facilitate component-based development, which basically means that instead of linking libraries when you compile your code, you reference an interface (the description of how to communicate with an external component) and use some implementation of that when you deploy. It underlies most of Microsoft's own technology.

The system has support for some features that were cool before everything went managed (such as reference counting and self-description (through IDispatch)).

share|improve this answer
add comment

COM is a standard created in the 90's to allow different pieces of software to talk to each other. Most important is the binary standard that allows one piece of software create or bind to an object and then call into that interface. This allows you to do things like create a DLL in C++ which can be called by an ASP page (COM Objects), or create a control in Delphi which you can put onto a VB dialog box (ActiveX controls), or Excel worksheet. When you paste a picture into Word it uses COM too, embedding a separate application into word. Less popular is DCOM which is to call remote objects, there are usually simpler ways to do this.

So Com/ActiveX/DCOM was very popular 10 years ago with VB, VBA, C++/ATL, Delphi. Dotnet is much simpler though and C# has replaced most use of COM and VB etc

Still there are many COM interfaces in there which exist which you might want to call from a dotnet application or Java or C++. (You dont say)

If you need to call COM interfaces VB is the simplest way to do this. In Dotnet 4.0 C# has the dynamic keyword which makes it much easier to call IDispatch interfaces, which is probably a great solution you should look at.

If you need to know a lot of detail, you really need to use C++ and ATL, call the C APIs like CoCreateInstance. Avoid this if you can though as its old tech and isn't much use, stick with recommendations above.

I'm not sure what monitoring software you're looking at but its likely to be available via System.Management classes in dotnet.

share|improve this answer
add comment

The followings could be useful COM overviewM:

The first video talks about the general idea of creating Binary Components to reuse codes written in different languages (language-independent) and are in different machines (processes) (location independent/transparent). This technology is used in some Software Companies to integrate with other software (companies) instead of buying their software and embed them into their own or writing the codes from scratch in their systems.

This technology has three different versions (implementtaions):

OLE/COM/DCOM/ActiveX for C++ developers (ATL is used to make programmer's job easier)

JavaBeans/RMI/EJB for Java developers

CORBA/IIOP

Just think of it as a technology that comes handy when you have your software written in Java and you want to add a functionality to it that is already exist in a package but it is written in C++ and even perhaps is located in different machine not in your local machine. How do you call "new" , how do you make objects and call methods from them?

The following books that I have seen people who do COM coding have either of them in their bookshelves:

  • Developer's Workshop to COM and ATL 3.0

  • Inside Com

  • Essential COM

share|improve this answer
add comment

Not the answer you're looking for? Browse other questions tagged or ask your own question.