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;
char saMembers[cMaxMembers][cMaxLoginID + 1];
};
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);
}
source
share