0
votes

I'm trying to do this:

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;   
    }
}

but I get these two errors :

Error 1:

Fixed size buffer type must be one of the following: bool, byte, short, int, long, char, sbyte, ushort, uint, ulong, float or double C:\Users\Aseel\Documents\Visual Studio 2010\Projects\CBS\CBS\GlobalVar.cs 40 22 CBS

Error 2:

GlobalVar.sentences.xplus': cannot have instance field initializers in structs C:\Users\Aseel\Documents\Visual Studio 2010\Projects\CBS\CBS\GlobalVar.cs 41 24 CBS

The dll file contains the search algorithm in C language and have the two struct I posted above plus other struct, but I need those two to display my result. Is there a way to get into these struct without redefining them again in C#?

1
by earlier I meant the above code ..Aseel84
@csharpler: please don't post .NET 1.1 links.John Saunders

1 Answers

1
votes

In general, when transporting objects between COM and .NET, it is necessary that either the objects have a very simple memory footprint, or else that the data in the objects be copied from a data structure which is suitable for one framework into one which is suitable for the other.

I can't tell exactly what you're trying to do with your data structure, but perhaps the simplest thing to do would be to store everything in one or more arrays of Int32 and impart your own interpretation upon the data therein. For example, rather than using pointer-linked lists of sentence_node, have the data for all your sentence_node items in an array, and for each item in sentences store the array index of the first node, and have each node hold the array index of the next. If you do things that way, code written in both COM and .NET will be able to use the data directly without having to copy or convert it.