what is the purpose of pStr? just pass a string into MyTest? if yes, use String for pStr. If it changes its value inside MyTest, use StringBuilder
[StructLayout(LayoutKind.Sequential)]
public class TESTSTRUCT
{
public int a;
[MarshalAs(UnmanagedType.LPStr)]
public string pStr; //or StringBuilder pStr;
}[DllImport("YourDLLName.dll")]
public static extern void MyTest(
[MarshalAs(UnmanagedType.LPStruct),Out]
TESTSTRUCT pt);or[DllImport("YourDLLName.dll")]
public static extern void MyTest(
[MarshalAs(UnmanagedType.LPStruct)]
TESTSTRUCT pt);
[StructLayout(LayoutKind.Sequential)]
public class TESTSTRUCT
{
public int a;
[MarshalAs(UnmanagedType.LPStr)]
public string pStr; //or StringBuilder pStr;
}[DllImport("YourDLLName.dll")]
public static extern void MyTest(
[MarshalAs(UnmanagedType.LPStruct),Out]
TESTSTRUCT pt);or[DllImport("YourDLLName.dll")]
public static extern void MyTest(
[MarshalAs(UnmanagedType.LPStruct)]
TESTSTRUCT pt);
解决方案 »
免费领取超大流量手机卡,每月29元包185G流量+100分钟通话, 中国电信官方发货