0

我有一个非常愚蠢的问题:显然我对 .NET 平台以及 C# 和 C++/CLI 如何通信的知识非常低,也许是我只是不知道一些 MSVS 的生活窍门或需要知道的知识。

我想从 C# 调用 C++/CLI 代码(编写的算法是本机 C++,我想包装它)。C++/CLI 编译,我将 C++/CLI 项目的引用添加到我的 C# 控制台应用程序项目中。但它仍然没有看到它。我一直在挖掘这个愚蠢的问题半天了。请帮忙!

如果你知道一些很好的理论材料来弥补我理解中的这些空白,我会真诚地 - 非常感激。我读过 Hogenson 并在工作中使用 C++/CLI 作为粘合剂,但我一直无法理解链接器的工作原理。

那是解决方案结构 - 1

测试.hxx:

#pragma once
#pragma managed

namespace Test
{
    class Test
    {
        public:
            static int Run();
    };

}

测试.cxx:

#pragma unmanaged
#include <iostream>

#pragma managed
#using <System.dll>
#include "test.hxx"

namespace Test
{
    int Test::Run() { return 42; }
}

程序.cs:

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Test;

namespace ConsoleApplication1
{
  class Program
  {
    static void Main( string[] args )
    {
      Test.Run();
    }
  }
}

错误:

Error   1   The type or namespace name 'Run' does not exist in the namespace 'Test' (are you missing an assembly reference?)    c:\users\denis\documents\visual studio 2010\Projects\ConsoleApplication1\ConsoleApplication1\Program.cs 13  12  ConsoleApplication1

感谢您的任何帮助!

4

1 回答 1

0

我认为您必须定义:

公共参考类测试

在Test.hxx

于 2013-05-14T15:13:33.360 回答