SHI am trying to use the Shell32 operation FileOperation to send a file to the recycling Bin. I have defined the structure in my class as follows and am hoping my definition is correct. Please let me know if I have it correct:
[StructLayout(LayoutKind.Sequential)]
internal struct _SHFILEOPSTRUCT
{
public IntPtr hwnd;
public Int32 wFunc;
[MarshalAs(UnmanagedType.LPStr)]
public String pFrom;
[MarshalAs(UnmanagedType.LPStr)]
public String pTo;
public Int32 fFlags;
public Int32 fAnyOperationsAborted;
public IntPtr hNameMappings;
[MarshalAs(UnmanagedType.LPStr)]
public String lpszProgressTitle;
}
internal enum FileOpFunc
{
Delete = 3
}
internal enum FileOpFlags
{
Silent=0x04,
AllowUndo=0x40,
NoConfirmation=0x10
}
[DllImport("Shell32.dll")]
internal static extern Int32 SHFileOperation(ref _SHFILEOPSTRUCT fileOp);
Sometimes when I call it I get a failure response of 1026 (0x402). Sometimes it works. Does anyone know what this response value is?
Hi,
inline,
> SHI am trying to use the Shell32 operation FileOperation to send a file to the recycling Bin. I have defined the structure in my class as follows and
am hoping my definition is correct. Please let me know if I have it
correct:
> [StructLayout(LayoutKind.Sequential)]
> internal struct _SHFILEOPSTRUCT
[quoted text clipped - 26 lines]
> [DllImport("Shell32.dll")]
> internal static extern Int32 SHFileOperation(ref _SHFILEOPSTRUCT fileOp);
How do you call it? Some struct fields must be 'double null terminated', eg.
aFileOpStruct.pFrom = "test.txt\0test2.txt\0";
aFileOpStruct.pFrom = "test.txt\0";
C# will add the second null to the end when marshalling.
HTH,
greetings
> Sometimes when I call it I get a failure response of 1026 (0x402). Sometimes it works. Does anyone know what this response value is?