如何在visual c ++中使用tlb

时间:2015-10-08 12:33:36

标签: c# c++ .net com

我有一个名为IronMan的接口[c#],RonMan实现了IronMan

问题在于我无法创建RonMan的实例[VC ++]:

界面:

namespace Widex.RonMan.Interop
{
  [ComVisible(true)]
  [Guid("5A3F9483-E235-4C92-839A-5890E60FD165")]
  public interface IronMan
  {
    int GetSome(int some);
  }
}
ronman班:

using System.Runtime.InteropServices;
namespace Widex.RonMan
[ComVisible(true)]
[ClassInterface(ClassInterfaceType.None)]
[Guid("79FD9A2F-AE4B-4412-BE8G-00649E136FCK")]
public class RonMan : IRonMan
{
    public  int GetSome(int some)
    {
        return some;
    }
}

当我尝试使用它时:

    [TestMethod]
    void IronManTest()
    {
        auto romManAuto= IRonManPtr(_uuidof(RonMan));
        auto res = romManAuto-> GetSome(2);

        Assert::AreEqual(2,res);
    }

创建了以下异常:

System.Runtime.InteropServices.SEHException: External component has thrown an exception.

更新 COM初始化:

#pragma once
#pragma unmanaged 
#import "Company.Heroes.Interop.tlb" no_namespace named_guids rename("value", "valueEx") 
// Following code is managed code. 
#pragma managed

0 个答案:

没有答案