SHFreeNameMappings Function

Declare Sub SHFreeNameMappings Lib "shell32.dll" (ByVal hNameMappings As Long)

Platforms

Description & Usage

SHFreeNameMappings frees a file mapping object created by the SHFileOperation function. The file mapping object consists of an array of SHNAMEMAPPING structures identifying the renamed files.

Return Value

SHFreeNameMappings does not return a value.

Visual Basic-Specific Issues

NOTE: Although I know how to create and free a file mapping object, I still have not been able to figure out how to actually access its contents. If you know how to do this, please e-mail me.

Parameters

hNameMappings
A handle to the file mapping object to free.

Example

' This code is licensed according to the terms and conditions listed here.

' Declarations and such needed for the example:
' (Copy them to the (declarations) section of a module.)
Public Type SHFILEOPSTRUCT
	hwnd As Long
	wFunc As Long
	pFrom As String
	pTo As String
	fFlags As Integer
	fAnyOperationsAborted As Long
	hNameMappings As Long
	lpszProgressTitle As String
End Type
Public Declare Sub CopyMemory Lib "kernel32.dll" Alias "RtlMoveMemory" _
	(Destination As Any, Source As Any, ByVal Length As Long)
Public Declare Function SHFileOperation Lib "shell32.dll" Alias "SHFileOperationA" _
	(lpFileOp As Byte) As Long
Public Declare Sub SHFreeNameMappings Lib "shell32.dll" (ByVal hNameMappings As Long)
Public Const FO_COPY = &H2
Public Const FOF_ALLOWUNDO = &H40
Public Const FOF_FILESONLY = &H80
Public Const FOF_WANTMAPPINGHANDLE = &H20

' Copy the files "C:\Folder\*.*" to the folder "C:\NewFolder\".
Dim fos As SHFILEOPSTRUCT  ' structure to pass to the function
Dim s(1 To 24) As Byte     ' byte array to make structure properly sized
Dim retval As Long         ' return value

' Load the proper parameters into the structure.
With fos
	' The window invoking the file operation.
	.hwnd = Form1.hWnd
	' Copy the specified files.
	.wFunc = FO_COPY
	' The list of source files to copy.
	.pFrom = "C:\Folder\*.*" & vbNullChar & vbNullChar
	' The path to copy the files to.
	.pTo = "C:\NewFolder\" & vbNullChar & vbNullChar
	' Allow Undo, and do not copy subfolders.
	' Also ask for a file mapping object.
	.fFlags = FOF_ALLOWUNDO Or FOF_FILESONLY Or FOF_WANTMAPPINGHANDLE
	' The rest of the structure isn't needed for this example.
	.fAnyOperationsAborted = 0
	.hNameMappings = 0
	.lpszProgressTitle = vbNullChar
End With

' Transfer the contents of the structure object into the byte
' array in order to compensate for a byte alignment problem.
CopyMemory sa(1), fos, LenB(fos)
CopyMemory sa(19), structarray(21), 12

' Send those files to the Recycle Bin.
retval = SHFileOperation(sa(1))

' Transfer the byte array back into the structure.  This is necessary
' because the mapping handle has been added to the structure.
CopyMemory sa(21), sa(19), 12
CopyMemory fos, sa(1), Len(fos)

' If you knew how to access the file mapping object, it would be done here.

' Free the file mapping object to free up resources.
SHFreeNameMappings fos.hNameMappings

Category

Shell

Back to the Function list.
Back to the Reference section.


Last Modified: April 16, 2000
This page is copyright © 2000 Paul Kuliniewicz. Copyright Information Revised October 29, 2000
Go back to the Windows API Guide home page.
E-mail: vbapi@vbapi.com Send Encrypted E-Mail
This page is at http://www.vbapi.com/ref/s/shfreenamemappings.html