The difference between traditional DLL and COM DLL

前端 未结 8 1299
半阙折子戏
半阙折子戏 2021-01-30 03:23

I am currently studying COM. I found that COM DLL is kind of built upon the traditional DLL infrastructure. When we build COM DLLs, we still rely on the traditional DLL export m

8条回答
  •  北恋
    北恋 (楼主)
    2021-01-30 03:48

    The best way to think of COM is to imagine it as a contract between you and the person using the object you create.

    COM handles

    1. how to version your object across releases
    2. how to discover your object, even if your object is in a DLL that gets renamed or came from a different source
    3. how to reference and destroy your object (with respect to heaps)
    4. how you expect threading to work, and the rules surrounding threading/locking for your object

    COM has become a standard because while you could make a traditional DLL that handles each of the above items you'd have to articulate the expected contract when you ship your DLL

    by using the rules of COM, this articulation is done for you

    you are also correct that COM exposes objects while more traditional DLLS just expose functions. you'll often see developers try to emulate the contracts found in COM in straight C, usually you'll see them clone aspects of COM in their DLL (for example you'll see methods that return structs of function pointers)... my experience is if you dont use COM for making a public DLL you're increasing the odds of miss some cases, especially when versioning is in the picture

提交回复
热议问题