已注册的 COM 接口如何链接到 twapi 名字对象?

How registered COM interface is linked to twapi moniker?

我想使用 COM > twapi > tcl 路径在 tcl 中使用 c# 代码应用程序。 通过研究 "call c# code from tcl" wiki 页面,我明白了两件事。 我们需要用 com 接口注册 VS 选项来编译 c# 代码。然后使用 namespacename.classname 创建对象实例。但不清楚twapi(或tcom)将如何使用那个com(或link)。你能详细解释一下吗?提前致谢。


C#代码

using System;
 namespace MyClassLib
 {
    public class Class1
    {
    public Class1()   {}
    public int Double (int val)  { return val * 2 ;  }
    }

 }

为 COM Interop 注册并构建项目时,class 会在系统的注册表中注册为该 class 名称的提供者。 tcom 包知道如何使用该信息。当你这样做时:

set myCom [tcom::ref createobject "ClassLibrary1.Class1"]

它消失并要求内置于 Windows 中的 COM 服务创建该对象的实例并将其引用返回给您。该引用是存储在变量中的内容。然后你可以调用对象的方法;它的语法是 Tcl-ish 而不是 C#-ish,但是模型是一致的。

$myCom Double 6

是的,幕后发生了很多复杂的事情,主要集中在 IDispatch 及其相关接口上。