简体   繁体   中英

When and why do we need to use COM?

I want to know when and why to use COM?

Please let me know in which situation I need to use com instead of normal DLL.

First, it's worth mentioning that COM is quite an old technology. It significantly predates .NET, which sometimes provide the same functionality. However, comparing to a plain DLL, it has a few advantages, for example:

  1. It doesn't have a functional interface, but an OO one. You create objects rather than call exported functions.
  2. It supports system security settings, so you can manage access to a COM class via Windows security settings.
  3. It crosses process boundaries - the COM server can either be in the user's process, or in a separate one.
  4. It crosses machine boundaries, AKA DCOM.
  5. It crosses language boundaries. COM's protocol is binary, so every language that supports it, can use COM components regardless of the language those components have been created in.
  6. There are many languages that support COM, and in which you can easily create and use COM objects.

This is just the tip of the iceberg. Although dated, COM is widely used in Windows. Whether it's the right technology for you to use these days is a different matter - this really depends on your specific needs. But if you're a Windows programmer, it's definitively worth getting familiar with anyway. Even it you don't produce any COM product, you're very likely to consume one.

You use COM in various contexts, such as:

  1. interacting with the msxml3/4/6 XML API (consuming COM objects);

  2. embedding an Internet Explorer WebBrowser control (consuming COM objects);

  3. implementing Explorer Shell extensions such as context menus (writing and consuming COM objects);

  4. implementing drag and drop functionality (writing and consuming);

  5. using the Vista-based file open/close dialogs (consuming);

  6. using the Windows-based ribbon API (consuming).

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