[StructLayout(LayoutKind.Sequential, CharSet=CharSet.Unicode)]
struct SHFILEOPSTRUCT
{
public IntPtr hwnd;
public FILEOP_FLAGS wFunc;
[MarshalAs(UnmanagedType.LPWStr)]
public string pFrom;
[MarshalAs(UnmanagedType.LPWStr)]
public string pTo;
public ushort fFlags;
//typedef int BOOL; (in platform SDK)
//BOOL fAnyOperationsAborted; (in platform SDK)
//public bool fAnyOperationsAborted;
public Int32 fAnyOperationsAborted;
public IntPtr hNameMappings;
[MarshalAs(UnmanagedType.LPWStr)]
public string lpszProgressTitle;
}
<StructLayout(LayoutKind.Sequential, CharSet:=CharSet.Unicode)> _
Public Structure SHFILEOPSTRUCT
Public hwnd As IntPtr
Public wFunc As FO_Func
<MarshalAs(UnmanagedType.LPWStr)> _
Public pFrom As String
<MarshalAs(UnmanagedType.LPWStr)> _
Public pTo As String
Public fFlags As FILEOP_FLAGS
Public fAnyOperationsAborted As Boolean
Public hNameMappings As IntPtr
<MarshalAs(UnmanagedType.LPWStr)> _
Public lpszProgressTitle As String ' only used if FOF_SIMPLEPROGRESS
End Structure
FILEOP_FLAGS
I tried to use this to send files to the recycle bin. It failed (Marshal.GetLastWin32Error was 6, invalid handle) and sometimes threw a NullReferenceException. To make it work I did the following;
public IntPtr pFrom;
public IntPtr pTo;
In my case I only needed pTo so I just added a null byte to the end and used Marshal.StringToHGlobalUni() to set the value