8 ms·
Staring into the COM Abyss
- non-entity 6y agoNot a lot of software really feels like "magic" to me anymore, which is unfortunate, but system programming on Windows often still feels like some arcane art.
- classified 6y agoBecause it is. MS's developer tools have gotten quite nice but the OS itself is a sprawling mess.
- projektfu 6y agoThe examples in the docs were also usually the bare minimum to show that the function existed, and usually full of memory leaks and bad behavior. Guessing what errors might arise was always fun. And then, the OS started inserting proxies on your interfaces whenever it wanted without telling you it might happen. Fun times all around. Favorite “COM-ism”: IClassFactory, the basic interface to a class. Why not call it IClass? Or IFactory since a class is essentially a Factory pattern? IClassFactory makes it sound like a Factory for Classes, not objects.
- commandlinefan 6y ago> full of memory leaks With an interface like AddRef/Release, they all but guarantee memory leaks.
- pjmlp 6y agoIf using bare bones C, yes definitely. Developers that know what they are doing would use a C++ library with support for COM smart pointers, .NET or Delphi.
- recursive 6y agoUsing COM from .net absolutely does not prevent leaks. I still don't really understand COM to this day, but I vividly recall spending significant effort and ultimately failing to do Office interop without leaking.
- asveikau 6y agoMy experience using COM with .net is that the GC does not get the hint that there is significant memory that will be released when it drops the COM wrapper object, so a "big" COM object or even many ones will not make the runtime start a collection and it ends up as a leak even though kicking the GC would probably do the right thing. So I would end up wrapping the objects in IDisposable and calling Marshal.ReleaseComObject on Dispose. Then COM objects were usually wrapped in using() to remain idiomatic for manual cleanup in c#. That was some years ago.
- asveikau 6y agoIf you put it in a C++ smart pointer it winds up pretty similar to ARC. (Yes, I have heard the compiler person's explanation that an ARC-type solution can generate fewer reference count modifications than a c++ smart pointer.)
- parasight 6y agoI was a junior back then but COM felt like magic to me. I think MS made COM more arcane than necessary. It was not until I read the book Essential COM by Don Box that I understood COM.
- PaulHoule 6y ago"Essential COM" is one of the top computer books ever written and I'd recommend it to anyone who is interested in object systems even if they don't code for Windows. (e.g. I think better than "The Art of the MetaObject Protocol")
- teh_klev 6y agoI have my copy from before the days when they tarted it up to add to the Developmentor series. I kinda miss Don Box doing his thing, quite an entertaining showman (who remembers Box sitting in a bath on stage talking about SOAP?) and tremendous technical writer.
- Traubenfuchs 6y agoOne can use SharpShell for this to do it in C#. Development and deployment remain unwieldy though. https://github.com/dwmkerr/sharpshell/issues/197 https://github.com/dwmkerr/sharpshell/issues/197
- ygra 6y agoI thought shell extensions in managed code were pretty much a no-go. [0] Has that changed by now? [0] https://devblogs.microsoft.com/oldnewthing/20061218-01/?p=28693 https://devblogs.microsoft.com/oldnewthing/20061218-01/?p=28...
- pjmlp 6y agoSince .NET 4, https://docs.microsoft.com/en-us/archive/msdn-magazine/2009/december/clr-inside-out-in-process-side-by-side#add-in-problems https://docs.microsoft.com/en-us/archive/msdn-magazine/2009/... Also note that Windows development team doesn't have that much .NET love (owned by DevTools).
- hyperrail 6y agoThis is Microsoft's most recent advice about in-process Explorer shell extensions: https://docs.microsoft.com/previous-versions/windows/desktop/legacy/dd758089(v=vs.85) https://docs.microsoft.com/previous-versions/windows/desktop... The advice is still "don't use .NET managed code for your in-proc shell extension", but the given reasons are not necessarily specific to the .NET runtime: 1. The .NET framework CLR takes too long to load for an extension that could be loaded by any app that pops up shell UIs. 2. There are seams between .NET and COM even with interop. These seams open traps for you because the COM-era shell APIs (Windows 95 to Windows 7) were designed for people who write their shell extensions in C++ and so can deal with all the tricky details of COM.
- ComputerGuru 6y agoPoint 1 was temporarily obviated by .NET Native, but that has now been abandoned with no explicit replacement, leaving a hole only somewhat filled by a combination of Mono and CoreRT.
- pjc50 6y ago> We can cast it to an IWebBrowser (a remnant of when Internet Explorer and Windows Explorer were welded together) Aargh. For a while I maintained an app which embedded IE (technically "IHTMLDocument2") on Windows CE, which meant dealing with a lot of this madness. It spawned all kinds of background threads and didn't take kindly to being interrupted, and control over it was limited - ended up drawing a window over its control bar and passing clicks through ourselves. He mentions "the cultural defeat of Microsoft", which is absolutely right; developers no longer choose the Windows platform, they are only ever forced to by circumstance, and have developed tools like Electron which allow them to ignore the platform entirely. For whatever reason, the "developer community" of Microsoft was very weak, at least post-dotcom era. You couldn't find many people talking about it openly to learn from. And only recently have they responded to that, especially with Roslyn and the buyout of Github. https://www.devever.net/~hl/windowsdefeat https://www.devever.net/~hl/windowsdefeat
- biggestdecision 6y agoI think a main reason Microsoft lost their development community is because they charged for access to Visual studio (which is the gateway to the entire ecosystem). People didn't talk about it openly, because no one was building for the microsoft platform outside of work. Meanwhile a whole community of competing free alternatives appeared - students learnt Java and Python because C# was a paid product that was also not cross platform.
- addicted 6y agoVisual Studio was/is super expensive and also necessary for MS development. With .Net core you can get by with never touching VS. But that wasn’t always the case. I also don’t believe MS had a free livense of Visual Studio like they do now.
- pjmlp 6y agoThat free license was called Express, was available per language variant, so you needed on VS Express install per workload and exists since around 2005, until Community made its appearance. Also the Windows SDK was always available for free, just you needed to get a C compiler yourself.
- x87678r 6y ago20 years ago I knew COM inside out and it was great, it was really powerful way to integrate your own code with the big applications Excel, ASP, IE. Its a great way to do SOLID programming long before it became fashionable. It also did things like let you build components in a single threaded language and use from a multi thread process - stuff people still can't do today. I know MS technology was never popular in SV, but people never even looked at it, which to me is weird when developers spend a lot of time investigating other languages and frameworks. Anyway its mostly dead now I guess, except for these random archaeological digs.
- marcus_holmes 6y agoSame. I miss how awesome COM was too. DCOM was a couple of orders of magnitude more fiddly to get working. But amazing once it worked. Create an object on another server, call its methods, side effects happen on that server, results are returned to your process. When I was learning Go the similarity between COM interfaces and Go interfaces really helped me grok them quicker.
- pjmlp 6y agoIt still is, powering all major Windows APIs since Vista.
- marcus_holmes 6y agoyeah, but I don't write desktop apps any more, so it's not something I use any more.
- cesarb 6y agoDCOM was also amazing, in how much surface area it exposed to the network. Random COM objects which were never intended to be called remotely, and were poorly secured, could be exposed by accident. So in the infamous Windows XP SP2 (not a major release of the operating system, but a mere service pack), DCOM got locked down hard. If you have a legitimate use for DCOM (like an OPC-DA server), you have to toggle several obscure settings to make it work again (see https://www-bd.fnal.gov/controls/opc/Using_OPC_via_DCOM_with_XP_SP2_v1.10.pdf https://www-bd.fnal.gov/controls/opc/Using_OPC_via_DCOM_with... for a fourteen-page tutorial).
- taylodl 6y agoThis takes me back! I was a COM expert in the late 90's/early aughts. It was important technology to master for building desktop applications for Windows. Nowadays we don't typically build desktop applications and even when we do we typically employ cross-platform technologies. So COM has pretty much fallen by the wayside - which isn't a bad thing! We've moved on.
- mattgreenrocks 6y agoThe idea of an app being a graph of polyglot components lives on, however, in the guise of microservices. The good part is you know everything exists out of process and you don't have to worry about things like COM's threading apartment. The bad thing is, of course, everything is out of process. Everything old is new again.
- tragomaskhalos 6y agoA common pattern for COM projects, in my experience, was a VB front end talking to a C++ back end. This was usually a pretty brutal experience TBH, even with ATL, because there were many fiddly details that intruded, specifically: - reference counting - string incompatibilities, exacerbated by the tendency of every man and his dog at Microsoft with an internet audience writing their own COM string class for C++ and publishing it; IIRC BSTR, _bstr_t, CCOMBStr but there were surely others, none of which really succeeded in bridging the very large gap that exists between what COM things a string should look like (length encoded at the front, two bytes per char) and the C / C++ view.
- sclangdon 6y agoI'm currently working on a VB6 front-end (I say front end, but it 450,000 lines so probably a bit more to it!) with C++ back-end (and it's old C++ that uses MFC containers instead of std). We also have a lot of C# extras that are called from the VB6 and also consume the C++ stuff. Oh, and there is Python scripting in there somewhere too. Ungh.
- xg15 6y agoI remember stumbling over shell and namespace extensions (without knowing the names of those concepts) back when I was coding in VB in high school - and being impressed how deep programs were apparently able to integrate into "the OS". (Nevermind that it was just the shell). So it's really amazing to see giving step-by-step examples of how a namespace extension could be implemented. I remember in particular that MS Outlook implemented their desktop icon as a namespace extension instead of an ordinary shortcut. I never understand why it was done this way, as the icon didn't behave particularly different than a normal shortcut: The only practical differences were that it did not allow you to look up the exe path and that you could not remove it from the desktop short of uninstalling Outlook. I wonder if this was done purely for nerd cred in much the same manner as the author of the OP - or if some overzealous manager had an irrational fear of users deleting the "Outlook" icon and ordered their team to do anything in their power prevent that...
- derefr 6y ago> and being impressed how deep programs were apparently able to integrate into "the OS". (Nevermind that it was just the shell). I’ve always been annoyed that all the major OSes have all this GUI-shell-level virtual folders and namespaces stuff, but none of them bother to “push it down” such that it’s accessible by the command-line, or better, by syscalls. I feel it would have made a lot of sense to do this in Windows: just replace “shell” objects with NT kernel objects, and allow the writing of (userland) NT-kernel-object-namespace extensions. Like FUSE, but without the filesystem part.
- ComputerGuru 6y agoThe whole point is the decoupling of userland from the kernel. Windows doesn’t really have syscalls in the Linux sense, but has an even more stable interface in the various core dlls (kernel32, user32, shell32, etc) (and of course the Nt* “syscalls” for speaking with the kernel directly). COM was always the real api for interacting with the desktop environment/shell, even from cli applications. The problem is that COM is strictly object oriented (unlike the user32 api and co) but both C and C++ used the same bindings to interface with it, which were written at the lowest common denominator giving us C++ com wrappers were ugly as hell when they could have been so much nicer. Microsoft finally fixed that in the past couple of years with the new winrt api for C++ but the world would have been different if such COM bindings for C++ had existed twenty years ago.
- barrkel 6y ago> The real sad part is for things like this, because the documentation is so lacking/missing, is that you may run into issues where not even Stack Overflow can help you. This is how we used to write code, back in the day. If you had a particularly hard time and experimentation wasn't working well, you traced through the disassembly in the debugger.
- growlist 6y agoA good while back Esri rearchitected their whole software suite into a COM based technology known as ArcObjects, with the aim of providing developers a single environment in which to code across all Esri SDKs. I remember a couple of things about it: firstly it was reputedly the largest COM library in existence, and secondly it was so horrendous that hardly anyone used it. Don't even get me started on the Java wrappers for ArcObjects... Thank god things have moved on.