1

我有一个注册到 ROT 的 COM 类,通过另一个应用程序我从 ROT 获取我的 com 类的实例并将其转换为它的类型,给出以下错误。

无法将类型为“System.__ComObject”的 COM 对象转换为接口类型“ROTViewer.IHandleVIParentInfo”。此操作失败,因为 IID 为“{C4B3F18E-FDF1-3F0C-A6DB-F03B302CAE9F}”的接口的 COM 组件上的 QueryInterface 调用因以下错误而失败:不支持此类接口(HRESULT 异常:0x80004002 (E_NOINTERFACE)) .

以下是我的 COM 类实现

public interface IHandleVIParentInfo
  {
      Dictionary<int, string> ContainerParentredVi {get; set;}
      int GetListCount();
  }

  [ComVisible(true)]
  [ClassInterface(ClassInterfaceType.None)]
  [ComSourceInterfaces(typeof(IHandleVIParentInfo))]
  [ProgIdAttribute(&quot;Qcs.VIParentedInfoHandler&quot;)]
  [GuidAttribute(HandleVIParentedInfo.Guid)]
  [DisplayName(&quot;Qcs VI Parented Info Handler&quot;)]
  public class HandleVIParentedInfo : IDisposable, IHandleVIParentInfo
  {
      public const string Guid = &quot;CB6BFC97-F8E3-4fce-B68B-4D01485811A1&quot;;
      public Dictionary&lt;int, string&gt; ContainerParentredVi
      {
          get
          {
              return _containerParentredVi;
          }
          set
          {
              _containerParentredVi = value;
          }
      }
      private Dictionary&lt;int, string&gt; _containerParentredVi = new Dictionary&lt;int, string&gt;();
      public HandleVIParentedInfo()
      {
          //private Dictionary&lt;int, string&gt; _containerParentredVi = new Dictionary&lt;int, string&gt;();
      }

      #region IDisposable Members

      void IDisposable.Dispose()
      {
          throw new NotImplementedException();
      }

      #endregion

      #region IHandleVIParentInfo Members

      int IHandleVIParentInfo.GetListCount()
      {
          return ContainerParentredVi.Count;
      }

      #endregion

以下是我将对象类型转换为我的 com 类类型的方法

public static void GetIDEInstances()
        {
            instances = new List<object>();
            Hashtable runningStationInstances = new Hashtable();
            Hashtable runningObjects = GetROTContent();


            object expectedObj;
            //runningObjects["!{5EB461D8-71CD-4E78-A360-4CE788A93063}"].GetHashCode();
            IDictionaryEnumerator rotEnumerator = runningObjects.GetEnumerator();
            while (rotEnumerator.MoveNext())
            {
                string candidateName = (string)rotEnumerator.Key;
                if (string.Compare(candidateName,"!{CB6BFC97-F8E3-4fce-B68B-4D01485811A1}",true)==0)
                {

                    viParenting = (IHandleVIParentInfo)rotEnumerator.Value;


                }
            }
}

在“viParenting = (IHandleVIParentInfo)rotEnumerator.Value;”行中出现错误

4

0 回答 0