c#类实现的接口属性无法从c ++ / cli访问

时间:2015-03-08 14:26:17

标签: c# c++-cli mixed-mode

我正在尝试在C ++ / CLI中实现一个本地接口,用于在c#中开发的类。我正在使用VS2013。

这是C#类的简化版本:

namespace ManagedTypes
{
    public static class CaptureFile
    {
        public static IPacketList GetPackets() { new PacketList(); }
    }
}

这是IPacketList接口的定义:

namespace ManagedTypes
{
    public interface IPacketList: IReadOnlyList<IPacket>
    {
    }
}

为了彻底,IReadOnlyList<T>(在mscorlib中)被声明为:

public interface IReadOnlyList<out T> : IReadOnlyCollection<T>, IEnumerable<T>, IEnumerable
{
    T this[int index] { get; }
}

IReadOnlyCollection<T>(也就是mscrolib)

public interface IReadOnlyCollection<out T> : IEnumerable<T>, IEnumerable
{
    int Count { get; }
}

所以,从C#开始,我可以做类似的事情:

var n = CaptureFile.GetPackets().Count;

但如果我尝试用C ++做类似的事情:

auto n = CaptureFile::GetPackets()->Count;

我收到以下编译错误:

1>------ Build started: Project: MixedMode, Configuration: Debug Win32 ------
1>C:\Program Files (x86)\MSBuild\12.0\bin\Microsoft.Common.CurrentVersion.targets(1697,5): warning MSB3274: The primary reference "C:\Hg\DP1000-DEV\src\Spikes\MixedModeSample\ManagedTypes\bin\Debug\ManagedTypes.dll" could not be resolved because it was built against the ".NETFramework,Version=v4.5" framework. This is a higher version than the currently targeted framework ".NETFramework,Version=v4.0".
1>  MixedModeApi.cpp
1>MixedModeApi.cpp(9): error C2039: 'Count' : is not a member of 'ManagedTypes::IPacketList'
1>          c:\hg\dp1000-dev\src\spikes\mixedmodesample\managedtypes\bin\debug\managedtypes.dll : see declaration of 'ManagedTypes::IPacketList'
1>MixedModeApi.cpp(10): error C3536: 'n': cannot be used before it is initialized
2>------ Build started: Project: NativeApp, Configuration: Debug Win32 ------
2>LINK : fatal error LNK1104: cannot open file 'C:\Hg\DP1000-DEV\src\Spikes\MixedModeSample\Debug\MixedMode.lib'
========== Build: 0 succeeded, 2 failed, 1 up-to-date, 0 skipped ==========

我在这里缺少什么?

0 个答案:

没有答案