通过使用C#一个DLL调用从C++ CLI(.NET)
问题描述:
我在C++ CLI(Game.h)一个头文件用来初始化一个属性(MAGIC_SEA)受管理的静态类(在C#)( settings.dll)。然而,当我建立这个代码(使用CLR支持)引发以下错误:通过使用<strong>C#</strong>一个DLL调用从C++ CLI(.NET)
Error 3 error C3083: 'game_id': the symbol to the left of a '::' must be a type c:\users\ed\projectS\Game.h
Error 4 error C2039: 'MAGIC_SEA' : is not a member of 'settings' c:\users\ed\ed\ProjectSl\Game.h
Game.h
...
using namespace settings;
...
const short MAGIC_SEA = settings::game_id::MAGIC_SEA;
...
settings.dll
using System;
using System.Collections.Generic;
using System.Text;
using System.Resources;
using System.Collections;
using System.ComponentModel;
using System.Management;
using System.Management.Instrumentation;
namespace settings {
...
public static class game_id {
public const short MAGIC_SEA = 1;
...
}
}
编译错误是相当平淡,“设置”是一个命名空间的名称,而不是一个类型名称。所以编译器还不知道“game_id”是什么意思。什么“静态类”可能意味着很难猜测,这与有效的C++/CLI代码没有任何关系。一个变量声明必须总是出现在一个ref类中,相当于一个const是'literal'。 –
汉斯,是的,“设置”是一个命名空间,但我似乎没有得到“编译器还不知道什么是game_id”的意思。 – ekremer
C++使用单通编译模型。声明必须始终出现在定义之前和用法,这与C#非常不同,掌握C++的相关知识对于编写正确的C++/CLI代码非常重要,并且发布可识别的代码对于获得SO答案很重要,请考虑从团队成员那里获得帮助。 –