C ++ code call with structure from C #

I was provided with a third-party library that wraps unmanaged C ++ code in C # api, one of the functions has a parameter that is a structure from its own global namespace, how do we create an instance of this structure in C #?

This is C ++ Struct:

struct GroupInfo
{
    int                 cMembers;                                           // Current # of members in the group.
    char                saMembers[cMaxMembers][cMaxLoginID + 1];            // Members themselves.
};

When we try to declare an instance of it in C #, the compiler says that global :: GroupInfo is unavailable due to its level of protection.

C ++ signature

int QueryGroup(char* sGroupName,
    GroupInfo& gi);

C # signature

VMIManaged.QueryGroup(sbyte*, GroupInfo*)

I have a class called group info

class GroupInfo
{
    public int cMembers;
    public sbyte[,] saMembers;
}

and when I try to implement this with this code, I get an error message that cannot convert

GroupInfo gi = new GroupInfo();

unsafe
{
    sbyte* grpName;
    fixed (byte* p = groupNameBytes)
    { 
        grpName = (sbyte*)p;
    }
    return vmi.QueryGroup(grpName, gi); // cannot convert from class GroupInfo to GroupInfo*
}
+6
source share
1 answer

, - # GroupData. , , :

class GroupInfo
{
  public GroupInfo() {}
  public int cMembers;
  public sbyte saMembers[cMaxMembers][cMaxLoginID + 1];
};
+2

All Articles