I have a struct in my C# as follows:
[StructLayout(LayoutKind.Sequential, CharSet=CharSet.Ansi)] public struct UserProfileData { int userProfileRevision; [MarshalAs(UnmanagedType.LPStr)] public String firstName; [MarshalAs(UnmanagedType.LPStr)] public String lastName; [MarshalAs(UnmanagedType.LPStr)] public String memberids; [MarshalAs(UnmanagedType.LPStr)] public String emailAddress; } I pass a reference to this
typedef struct userProfile { int profileRevision; char *firstName; char *lastName; char *memberids; char *emailAddress; } userProfile_t; My C .dll has function like this
int getUserProfileData(userProfile_t *pUserProfile); to get the values for the strings in the struct above. I call this function from C# code and the int value 'profileRevision' is properly populated. The strings like 'firstname' are properly dynamically allocated and filled within the above C function but when the code returns to the C# environment all the strings in the struct are null. What's the best way to handle this?