2
我有一个C#应用程序。它引用了一个C++ - cli dll。在C的命名空间++ DLL中的公共结构声明:公共结构在托管c + + dll无法看到从c#
namespace Wrapper {
public struct maxs
{
public:
char Name[255];
int num;
};
etc
有一个在C++ DLL,它返回一个指针的指针结构的功能。
Wrapper::Maxs** Wrapper::Class1::CallMax();
C#的应用程序引用C++ DLL,并声明结构的实例(不安全代码)
Wrapper.Class1 oMax = new Wrapper.Class1()
Wrapper.Maxs** maxs;
maxs= oMax.CallMax();
int num = oMax.m_num;
然后我尝试访问MAXS领域像这样:
for(int i = 0; i < num; ++i)
{
name = maxs[i]->name;
}
但是,该'名称'字段在c#intellisense中不可见,并且不能编译。 有趣的是我去看看在C++中的元数据结构的定义和结构是空白..
using System;
using System.Runtime.CompilerServices;
namespaceWrapper
{
[CLSCompliant(false)]
[NativeCppClass]
[UnsafeValueType]
public struct Maxs
{
}
}
是正常吗? 所以问题是:为什么C#不能看到公共结构最大值的字段?为什么元数据信息显示空白结构? 谢谢。
因为它不是托管结构。您需要将其声明为“公共价值结构”。 – 2013-03-24 02:33:32
谢谢汉斯!完成了这项工作,我学到了新的东西。 – user2192008 2013-03-24 04:36:37
@HansPassant:你介意给出一个答案,所以作者可以接受它..?我知道这很不重要,但是这个线程将会以其他方式挂起。这是不合资格被关闭.. – quetzalcoatl 2013-03-28 00:16:42