Background:
In C # code, you need to convert a struct to a character array
The form of the structure is similar to the following:
struct usrinfo{ [MarshalAs (UnmanagedType.ByValArray, SizeConst = +)] public char[] name; public int ID;}
Call your own struct conversion function to convert it to a character array form
However, the following error is indicated: The data region passed to the system call is too small. (Exception from hresult:0x8007007a)
The first thing you need to do is to check that you assigned the name to a value that exceeds 16. And then look down!
Error message in: Marshal.structuretoptr (Structobj, Structptr, true); Method at
Troubleshooting
Find some materials on the Internet, and found that there are some similar situations. One situation is: there is no error in converting English, but it can be wrong to convert Chinese.
Test it, it really is. Because the program needs to use Chinese name, it does not appear in English when the error prompt.
Cause of Error:
When the structure is laid out, the Unicode code is not indicated, so there is an error when transferring the struct to the Structtoptr () method.
Workaround:
Use the StructLayout attribute to define the structure so that it is encoded in Unicode ( by setting the CharSet property)
The modified structure is defined as follows:
[StructLayout (LayoutKind.Sequential, CharSet=CharSet.Unicode)]struct usrinfo{ [MarshalAs ( UnmanagedType.ByValArray, SizeConst = +)] [public char[] name; public int ID;}
The data region passed to the system call is too small. (Exception from hresult:0x8007007a)