我有一个名为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);
}
}
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