From: Gigin on
Hi ,

I am writing a wrapper class in C#, which uses DLLs created in C++. I need
to initialize a structure as given below:

public unsafe struct _MX00_ID_USER_RECORD
{
public uint nGroupID;

public uint nFinger;
public uint nInstances;

public char szUserID[32];

}

The member variable szUserID is creating troubles. I am not able to
initialise it properly.

The "char" type cannot be replaced by "string" type, since I am using
pointer to the structure _MX00_ID_USER_RECORD as it does not allow pointer to
a managed type.

I tried initialising the members using a constructor as given below:

public _MX00_ID_USER_RECORD( char[] tmp)
{
nGroupID = 0;
nFinger = 0;
nInstances = 0;
char[] szUserID = new char[32];

}
But since "szUserID" is not declared "public", I am not able to access it
outside the wrapper class.


Please help me with how to declare the character array so that I can access
it outside the wrappaer class.

Thank You
From: Paul G. Tobey [eMVP] paultobey _at_ earthlink _dot_ on
Huh? According to the declaration you gave us, szUserID *IS* declared
public. Based on the declaration that you showed us, you should not have a
problem.

I suspect that you have a bigger problem, though. If the C++ structure is
declared something like this:

typedef
struct
{
unsigned int nGroupID;

unsigned int nFinger;
unsigned int nInstances;

char szUserID[32];
}

You can't substitute a dynamically-created managed array for szUserID. The
structure as declared in C++ has 32 bytes right there in the structure.
Using new in C# will give you, essentially, a pointer, not a fixed array.
You have to set some marshaling attributes to make that work.

So, tell us what the actual problem is, give us the C++ structure
declaration, and show us how you want to have the user of your wrapper class
use the structure and you'll get some suggestions.

Paul T.

"Gigin" wrote:

> Hi ,
>
> I am writing a wrapper class in C#, which uses DLLs created in C++. I need
> to initialize a structure as given below:
>
> public unsafe struct _MX00_ID_USER_RECORD
> {
> public uint nGroupID;
>
> public uint nFinger;
> public uint nInstances;
>
> public char szUserID[32];
>
> }
>
> The member variable szUserID is creating troubles. I am not able to
> initialise it properly.
>
> The "char" type cannot be replaced by "string" type, since I am using
> pointer to the structure _MX00_ID_USER_RECORD as it does not allow pointer to
> a managed type.
>
> I tried initialising the members using a constructor as given below:
>
> public _MX00_ID_USER_RECORD( char[] tmp)
> {
> nGroupID = 0;
> nFinger = 0;
> nInstances = 0;
> char[] szUserID = new char[32];
>
> }
> But since "szUserID" is not declared "public", I am not able to access it
> outside the wrapper class.
>
>
> Please help me with how to declare the character array so that I can access
> it outside the wrappaer class.
>
> Thank You