Type a page name and press Enter. You'll jump to the page if it exists, or you can create it if it doesn't.
To create a page in a module other than Structures, prefix the name with the module name and a period.

C# Definition:

//[StructLayout(LayoutKind.Sequential, CharSet=CharSet.Unicode)]
//If you use the above you may encounter an invalid memory access exception (when using ANSI
//or see nothing (when using unicode) when you use FOF_SIMPLEPROGRESS flag.
[StructLayout(LayoutKind.Sequential, CharSet=CharSet.Unicode)]
struct SHFILEOPSTRUCT
{
public IntPtr hwnd;
public FileFuncFlags wFunc;
[MarshalAs(UnmanagedType.LPWStr)]
public string pFrom;
[MarshalAs(UnmanagedType.LPWStr)]
public string pTo;
public FILEOP_FLAGS fFlags;
[MarshalAs(UnmanagedType.Bool)]
public bool fAnyOperationsAborted;
public IntPtr hNameMappings;
[MarshalAs(UnmanagedType.LPWStr)]
public string lpszProgressTitle;
}

VB.NET Definition

<StructLayout(LayoutKind.Sequential, CharSet:=CharSet.Unicode)> _
Public Structure SHFILEOPSTRUCT
Public hwnd As IntPtr
<MarshalAs(UnmanagedType.U4)>Public wFunc As FileFuncFlags
<MarshalAs(UnmanagedType.LPWStr)>Public pFrom As String
<MarshalAs(UnmanagedType.LPWStr)>Public pTo As String
<MarshalAs(UnmanagedType.U2)>Public fFlags As FILEOP_FLAGS
<MarshalAs(UnmanagedType.Bool)>Public fAnyOperationsAborted As Boolean
Public hNameMappings As IntPtr
<MarshalAs(UnmanagedType.LPWStr)>Public lpszProgressTitle As String ' only used if FOF_SIMPLEPROGRESS
End Structure

VB Definition:

Public Type SHFILEOPSTRUCT
hWnd As Long
wFunc As FileFuncFlags
pFrom As String
pTo As String
fFlags As FILEOP_FLAGS
fAnyOperationsAborted As Long
hNameMappings As Long
lpszProgressTitle As String
End Type

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

Failure on 64 bit OS

Under x64, the SHFILEOPSTRUCT must be declared without the Pack = 1 parameter, or it will fail. This is a real pain if you want your code to be platform independent, as you have to declare two separate structures, one with Pack = 1, and one without. You then have to declare two different SHFileOperation calls, one for each of the structures. Then you have to decide which one to call depending on whether you are running on 32 or 64 bit.

Update on 64-bit Issue

Don't declare a value for the Pack size. If you omit it, the correct value is used when marshaling and a single SHFILEOPSTRUCT can be used for both 32-bit and 64-bit operation.

64 bit proof alternative

You may use the functionality of the Microsoft.VisualBasic.dll(.NET framework) instead. They handle the 64 bit call well.

An IntPtr is a pointer to a memory location (unmanaged) that adapts to the platform it is running on (64-bit, etc.) UNLIKE a standard int/Integer. You should always use this type for unmanaged calls that require it, even though an int will appear to work on your development machine.

1/13/2008 11:00:13 AM - tsahi-62.219.227.88

An IntPtr is a pointer to a memory location (unmanaged) that adapts to the platform it is running on (64-bit, etc.) UNLIKE a standard int/Integer. You should always use this type for unmanaged calls that require it, even though an int will appear to work on your development machine.

1/13/2008 11:00:13 AM - tsahi-62.219.227.88

The SHFileOperation API

7/12/2013 12:24:36 PM - -178.93.161.143

Please edit this page!

Do you have...

helpful tips?

corrections to the existing content?

alternate definitions?

additional languages you want to include?

Select "Edit This Page" on the right hand toolbar and edit it! Or add new pages containing any supporting types needed.