I am thinking to learn COM.But I heard that Microsoft launched .NET as an alternative to COM. So is it worth to learn COM? actually I started learning COM for UMDF device driver. Is there any alternate way to work on UMDF except COM?
-
Related http://stackoverflow.com/questions/2280639/is-net-all-com-underneath – Brian Rasmussen Aug 14 '10 at 13:19
-
6Yes, learn it. It's the underpinning of almost everything in Windows. Whether they admit it or not. Plus you'll be that cool COM dude in the office that gets all the chicks. :-) – JustBoo Aug 14 '10 at 16:20
4 Answers
COM is old, tedious and frustrating. I don't think anyone has ever enjoyed working with COM. So generally, I'd recommend against learning it unless you have a really compelling reason. If there is a COM library out there that you need to use, I'd instead learn how to use it through COM interop, which enables you to work with COM from .NET.

- 60,826
- 17
- 123
- 123
-
I am not an expert on UMDF (far from it), but it does look like being familiar with COM will help with tackling a UMDF project. – Matt Greer Aug 14 '10 at 13:37
-
Seriously, I worked with COM for +- 7 years and most of the time I enjoyed. Also, since Windows relies heavily on COM, if you are going to extend Windows chances are high that you'll need to use COM. – Vagaus Aug 14 '10 at 22:11
To be clear, .NET was very much intended to be a replacement for COM. And that worked out well, it's been very successful. But COM is everywhere in Windows, you can't shake a stick at a typical program and not run into COM somewhere. That starts with the very first bit of code in any .NET GUI program, [STAThread].
There is lots and lots of stuff in Windows that hasn't gotten the friendly .NET wrapper yet. That isn't always needed, the CLR has excellent support for COM interop. Quite visible from the Add Reference dialog, the COM tab is filled with goodies. But what you see in that list are components that were specifically engineered to be easy to use from any runtime environment. They implement a subset of COM called "OLE Automation".
Automation is a very restricted subset, it works so well because what you actually can do is limited. There are however gobs of code that don't fit that subset. The kind for which you can't find a type library. Without the type library you're screwed in .NET. The most visible component with that issue is the shell. Windows Explorer. Writing a shell extension in managed code is hard.
The issue is that COM interface declarations were originally designed to work well on a compiler that implements multiple inheritance. C++ specifically. A .NET interface declaration does not map well to a COM interface if that COM interface was derived from another COM interface. The CLR generates the wrong v-table. This is touched upon in this MSDN magazine article, albeit that the author's conclusion is quite wrong.
You can write COM interface declarations in a .NET language and implement them. It is just that you get no help at all from the SDK. And that you'll need to know COM pretty well to get them right.
UMDF fits this model too, its interfaces are derived from IUnknown. No type library. No managed wrapper that I know of. You could write your code in C# but you'll have to write all the interface declarations yourself. Realistically, only C++ applies here.
Yes, you'll need to learn COM.

- 922,412
- 146
- 1,693
- 2,536
-
Do You know any good book for COM? Any website for tutorials? – Rushikesh Talokar Aug 14 '10 at 16:21
-
The thread is here: http://stackoverflow.com/questions/399566/what-is-the-best-book-to-learn-com – Hans Passant Aug 14 '10 at 16:39
UMDF is a framework to develop user mode device drivers. I think a key requirement for a device driver is: load fast. I don't want to delay my startup times just because I have a funky device driver that has to load and JIT the .NET framework (preJITed but nonetheless).
Sure you can develop bloated com libraries too but by being competent you can avoid it. You can't avoid .NET runtime.
So even if UMDF allowed for .NET development I at this point of time wouldn't want device drivers written in .NET.
Don't get me wrong. I love .NET. I just don't think it mixes that well with device drivers even if we are talking about usermode drivers.
When looking at COM I think it helps to understand why it was developed: to provide interopability between components developed in different environments. This was back in the '80s. Now people has complained about COM over the years but it is actually very successful at that. There were some mistakes in the deployment model of COM (ie the registry dependency) and other interesting design choices that have made developers scratch their heads. However, the core of COM (ie IUnknown) is still sound IMO.

- 11,499
- 2
- 35
- 54
-
But I heard that .NET will replace COM within few years.So is it worth to start learning COM? – Rushikesh Talokar Aug 14 '10 at 15:38
-
I don't see that happening. It will break so many applications out there and the cost to fix it enormous (1 million man years? maybe even more.). I and alot of others would sue over that so add legal cost to that. I can't say if it's worth for you learning COM but I think COM will be with us until the Windows NT platform is scrapped. With a good tutorial core COM is rather easy though. Takes 1 day to grasp the fundamentals. – Just another metaprogrammer Aug 14 '10 at 16:04
-
Plz can u tell me from where I can get good resource for COM(either book or website). – Rushikesh Talokar Aug 14 '10 at 16:14
-
very old, it's not about UMDF but much about COM, it's a classic: http://www.powervb.com/ but – OlimilOops Aug 14 '10 at 16:33
-
Essential COM (http://tinyurl.com/32og3ll) explains the basics well, but does a poor job on the more advanced features. I would recommend chapter: 1 (but its not so that COM is a better C++, different scopes), 2, 3 (to page 100), 4 (so good). Apartments are important but it's a topic that takes a while to grasp and it's not core COM. Box talks alot about Monikers, I never understood it 98 and I've never used it. Effective COM (http://tinyurl.com/362cdz4) is the book to read once you've got the basics inplace (although MTS is replaced with COM+). – Just another metaprogrammer Aug 14 '10 at 17:13
-
Once you started writing COM you'' realize that there a bunch of support libraries out there to help you writing COM objects ie MFC or ATL. The question arises: should you learn them? I know more about inner working of ATL than I want to admit but if I started a C++ project these days with a COM facade what I would do is by using T4 autogenerate the IDL files, the COM facades, the registry keys from a common COM model description. And I would make sure the generated code is blindingly fast to compile and have little runtime overhead. That's just my opinion. – Just another metaprogrammer Aug 14 '10 at 17:22
COM was useful because it allowed you to build a language independent API that could be consumed from multiple languages. Now .net is used for roughly the sampe purpose, although it is less accessible. If you program .net, many COM API's "just work", although it is good to get some basic understanding of how COM works (such that COM uses refcounting for memory management, whereas .net uses garbage collection).