【发布时间】:2013-03-25 12:35:45
【问题描述】:
我正在尝试这样做:
public static class GlobalVar
{
[DllImport("Export.dll")]
public static extern sentences Export();
public unsafe struct sentence_node
{
public sentence_node* next; // next node in the dictionary in the same level
public int sNum; // sentence number starting from 1
public int sLoc; // the location in the sentence (protien)
}
public unsafe struct sentences
{ // list of lists of sentences in which words exists.
public fixed sentence_node* sList[50];
public char[,] xplus = new char[50, 100];
public int wordCount;
}
}
但我收到这两个错误:
错误 1:
固定大小的缓冲区类型必须是以下之一:bool、 byte、short、int、long、char、sbyte、ushort、uint、ulong、float 或 双 C:\Users\Aseel\Documents\Visual Studio 2010\Projects\CBS\CBS\GlobalVar.cs 40 22 CBS
错误 2:
GlobalVar.sentences.xplus': 不能有实例字段初始化器 结构 C:\Users\Aseel\Documents\Visual Studio 2010\Projects\CBS\CBS\GlobalVar.cs 41 24 CBS
dll 文件包含 C 语言中的搜索算法,并具有我在上面发布的两个结构以及其他结构,但我需要这两个来显示我的结果。有没有办法进入这些结构而无需在 C# 中重新定义它们?
【问题讨论】:
-
之前我的意思是上面的代码..
-
您应该考虑使用
class。 (msdn.microsoft.com/en-us/library/y23b5415%28VS.71%29.aspx) -
@csharpler:请不要发布 .NET 1.1 链接。
标签: c# arrays struct pinvoke dllimport