none
How do .Net RCW resolve COM components? RRS feed

  • Question

  • I am integrating an older product into my company's build system. They are using a lot of external COM/ActiveX components in their C# projects by simply adding the COM reference and then delivering the RCW that is auto-generated. Since we strong name / sign everything we deliver I am having to change this to manually generate the .Net RCW files created through our build system to use our standards. I realized that I am unsure of how RCW files locate their COM component. I know it uses the registry, but does it use class name or id? Since these are pointing to external com components that are not delivered with the product, it must assume they are installed / registered all ready on the machine. Now this is acceptable since they either standard or listed with requirements, but considering there could be different versions of the COM component and it could have different guids, I am guessing it can resolve them by name, is this correct? 

    Also, since strong naming usually includes version, is this simply used for the assembly binding to the RCW or will it affect the com component locating?
    Wednesday, December 23, 2009 4:30 PM

Answers

  • The way that Win32 COM components are called doesn't change just because managed code is calling them rather than unmanaged. There are basically two ways:

    1. Via HKCR\CLSID\{guid} for the class being used, mapping to the Win32 server for that COM class.
    2. Via HKCR\<progid> has an entry that contains the class guid, then using method 1.

    Installation of the actual COM server typically creates both, but there's no rule that a Progid is required.

    There cannot be different versions of registered COM components because there is only one registration entry for each class. That's why there are COM rules about new versions being compatible with older clients and why installation is always to the same location.  For a COM component that properly obeys these rules it should not matter which actual version is installed.

    So the assembly naming attributes are important only for the managed code side of client=>RCW.

    Phil Wilson
    • Proposed as answer by SamAgain Wednesday, December 30, 2009 5:48 AM
    • Marked as answer by ShawnGarrison Wednesday, December 30, 2009 3:09 PM
    Wednesday, December 23, 2009 11:23 PM