我已将解决方案.net框架从3.5升级到4.6.1,并且在运行工具时出现APPCRASH错误。 因此,我尝试调试代码,并且看起来当控件到达以下代码时,调试简单地退出而没有引发任何错误。 尝试了异常处理以捕获错误,但没有用。
Marshal.DestroyStructure(p, typeof(DS_SELECTION))
示例
See this example in .Net Fiddle
using System;
using System.Runtime.InteropServices;
public class Program
{
public static void Main()
{
IntPtr p = IntPtr.Zero;
IntPtr dsSL = IntPtr.Zero +1;
p = (IntPtr)(((int)dsSL) + Marshal.SizeOf(typeof(DS_SELECTION_LIST)));
if(IntPtr.Zero.Equals(p) == false)
{
//Console.WriteLine("Hello");
Marshal.DestroyStructure(p, typeof(DS_SELECTION));
}
}
internal struct DS_SELECTION
{
[MarshalAs(UnmanagedType.LPWStr)]
public string pwzName;
}
internal struct DS_SELECTION_LIST
{
public uint cFetchedAttributes;
}
}