The struct should be:
[StructLayout(LayoutKind.Sequential, CharSet = CharSet.Ansi)]
public struct MYDATA
{
[MarshalAs(UnmanagedType.ByValTStr, SizeConst = 4096)]
public string calls;
[MarshalAs(UnmanagedType.ByValTStr, SizeConst = 4096)]
public string Desc;
[MarshalAs(UnmanagedType.ByValTStr, SizeConst = 1024)]
public string error;
}
I assume the 4069 value in the question is a typo.
The first function is:
[DllImport(dllname, CharSet = CharSet.Ansi)]
public static extern IntPtr startSessionint(string[] argv);
Then convert the function pointer to a delegate:
[UnmanagedFunctionPointer(CallingConvention.Cdecl)]
public delegate IntPtr getStatDelegate();
....
IntPtr ptr = startSessionint(argv);
if (ptr == IntPtr.Zero)
// handle error
getStatDelegate getStat = (getStatDelegate)Marshal.GetDelegateForFunctionPointer(ptr, typeof(getStatDelegate));
Now you can call the function:
IntPtr structPtr = getStat();
And then marshal to the struct:
MYDATA data = (MYDATA)Marshal.PtrToStructure(structPtr, typeof(MYDATA));
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…