【问题标题】:.NET interface type definition in Visual C++Visual C++ 中的 .NET 接口类型定义
【发布时间】:2012-06-22 15:17:14
【问题描述】:

我需要在 Visual C++ 中编写一个接口,将在 C# 项目中使用。我需要在 C# 中使用 out 参数,我将如何制作 C++ 签名?

类似C++的代码

public interface class Iface
{
public:
    System::Object^ Method([out] bool there);
};

和C#必须是

public class TestObj : Library.Iface
    {
        object Library.Iface.Method(out bool there)
        {
            there = true;
            return null;
        }
    }

我将如何编写我的 C++ 接口?

【问题讨论】:

标签: c# c++-cli clr


【解决方案1】:
using namespace System;
using namespace System::Runtime::InteropServices;
interface class Iface
{
    Object^ Method([Out] bool% there);
};

【讨论】:

  • @Hans:错了。它会影响 C# 编译器数据流分析。如果没有[Out],C# 编译器将要求在调用之前明确分配参数。使用[Out],C# 编译器将要求实现方法在返回之前明确分配参数。
  • 嗯,不,C# 实际上使用 out 作为实现方法。这个答案是正确的,+1。
猜你喜欢
  • 1970-01-01
  • 2020-03-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2020-03-16
  • 2014-10-06
相关资源
最近更新 更多