473,382 Members | 1,743 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,382 software developers and data experts.

Using the SHFILEOPSTRUCT structure

Can anyone fix the code below?

I need to set pTo to NULL and pFrom to a fullfilepath followed by two NULLs
Below Filename is a string
With FileOperation

..wFunc = FO_DELETE

..pFrom = FileName??

..pTo = ??

..fFlags = FOF_ALLOWUNDO Or FOF_SIMPLEPROGRESS

End With

My guess for the structure:

Public Structure SHFILEOPSTRUCT

Public hwnd As IntPtr

Public wFunc As Integer

<VB.VBFixedString(MAX_PATH), MarshalAs(UnmanagedType.ByValTStr,
SizeConst:=MAX_PATH)> _

Public pFrom As String

<VB.VBFixedString(MAX_PATH), MarshalAs(UnmanagedType.ByValTStr,
SizeConst:=MAX_PATH)> _

Public pTo As String

Public fFlags As Short

Public fAnyOperationsAborted As Boolean

Public hNameMappings As IntPtr

Public lpszProgressTitle As String

End Structure


Nov 20 '05 #1
14 4102
Hi,

Here is the structure, dll declare, and sample code. It will allow
you to select a file to delete with an open file dialog and send it to the
recycle bin.

Structure SHFILEOPSTRUCT

Dim hwnd As Integer

Dim wFunc As Integer

Dim pFrom As String

Dim pTo As String

Dim fFlags As Short

Dim fAnyOperationsAborted As Integer

Dim hNameMappings As Integer

Dim lpszProgressTitle As String ' only used if FOF_SIMPLEPROGRESS

End Structure

<DllImport("shell32.dll", entrypoint:="SHFileOperationA", _

setlasterror:=True, CharSet:=CharSet.Auto, exactspelling:=True, _

CallingConvention:=CallingConvention.StdCall)> _

Public Shared Function SHFileOperation(ByRef lpFileOp As SHFILEOPSTRUCT) As
Integer

End Function

Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles Button1.Click

If OpenFileDialog1.ShowDialog() = DialogResult.OK Then

Dim sh As New SHFILEOPSTRUCT

With sh

..wFunc = FO_DELETE

..pFrom = OpenFileDialog1.FileName

..fFlags = FOF_ALLOWUNDO Or FOF_SIMPLEPROGRESS

End With

If SHFileOperation(sh) <> 0 Then

MessageBox.Show("Error deleting file")

End If

End If

End Sub

Ken

-----------------------------

" Just Me" <ne********@a-znet.com> wrote in message
news:O4**************@TK2MSFTNGP11.phx.gbl...
Can anyone fix the code below?

I need to set pTo to NULL and pFrom to a fullfilepath followed by two NULLs
Below Filename is a string
With FileOperation

..wFunc = FO_DELETE

..pFrom = FileName??

..pTo = ??

..fFlags = FOF_ALLOWUNDO Or FOF_SIMPLEPROGRESS

End With

My guess for the structure:

Public Structure SHFILEOPSTRUCT

Public hwnd As IntPtr

Public wFunc As Integer

<VB.VBFixedString(MAX_PATH), MarshalAs(UnmanagedType.ByValTStr,
SizeConst:=MAX_PATH)> _

Public pFrom As String

<VB.VBFixedString(MAX_PATH), MarshalAs(UnmanagedType.ByValTStr,
SizeConst:=MAX_PATH)> _

Public pTo As String

Public fFlags As Short

Public fAnyOperationsAborted As Boolean

Public hNameMappings As IntPtr

Public lpszProgressTitle As String

End Structure

Nov 20 '05 #2
Ken,

* "Ken Tucker [MVP]" <vb***@bellsouth.net> scripsit:
Here is the structure, dll declare, and sample code. It will allow
you to select a file to delete with an open file dialog and send it to the
recycle bin.

Structure SHFILEOPSTRUCT


Notice that this structure has byte-aligned members, so I would specify
'Pack:=1' in the attributes.

--
Herfried K. Wagner [MVP]
<URL:http://dotnet.mvps.org/>
<URL:http://dotnet.mvps.org/dotnet/faqs/>
Nov 20 '05 #3
I'm going to try this of course, but I'm surprised that no consideration
seems to be given to the fact that pFrom is supposed to be a string that is
terminated with an extra zero?
As I remember, it is a list of filenames separated by semicolons. Maybe this
takes the chance that the byte after the file name does not happen to be a
semicolon??

Also, is there some reason a C# declare of the function was given. I'll need
to convert to VB and hope there is no special reason it was given in C#

Also, I believe fAnyOperationsAborted is BOOL. why map to Integer instead
of Boolean?
Thanks very much

"Ken Tucker [MVP]" <vb***@bellsouth.net> wrote in message
news:uw**************@TK2MSFTNGP11.phx.gbl...
Hi,

Here is the structure, dll declare, and sample code. It will allow you to select a file to delete with an open file dialog and send it to the
recycle bin.

Structure SHFILEOPSTRUCT

Dim hwnd As Integer

Dim wFunc As Integer

Dim pFrom As String

Dim pTo As String

Dim fFlags As Short

Dim fAnyOperationsAborted As Integer

Dim hNameMappings As Integer

Dim lpszProgressTitle As String ' only used if FOF_SIMPLEPROGRESS

End Structure

<DllImport("shell32.dll", entrypoint:="SHFileOperationA", _

setlasterror:=True, CharSet:=CharSet.Auto, exactspelling:=True, _

CallingConvention:=CallingConvention.StdCall)> _

Public Shared Function SHFileOperation(ByRef lpFileOp As SHFILEOPSTRUCT) As Integer

End Function

Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles Button1.Click

If OpenFileDialog1.ShowDialog() = DialogResult.OK Then

Dim sh As New SHFILEOPSTRUCT

With sh

.wFunc = FO_DELETE

.pFrom = OpenFileDialog1.FileName

.fFlags = FOF_ALLOWUNDO Or FOF_SIMPLEPROGRESS

End With

If SHFileOperation(sh) <> 0 Then

MessageBox.Show("Error deleting file")

End If

End If

End Sub

Ken

-----------------------------

" Just Me" <ne********@a-znet.com> wrote in message
news:O4**************@TK2MSFTNGP11.phx.gbl...
Can anyone fix the code below?

I need to set pTo to NULL and pFrom to a fullfilepath followed by two NULLs Below Filename is a string
With FileOperation

.wFunc = FO_DELETE

.pFrom = FileName??

.pTo = ??

.fFlags = FOF_ALLOWUNDO Or FOF_SIMPLEPROGRESS

End With

My guess for the structure:

Public Structure SHFILEOPSTRUCT

Public hwnd As IntPtr

Public wFunc As Integer

<VB.VBFixedString(MAX_PATH), MarshalAs(UnmanagedType.ByValTStr,
SizeConst:=MAX_PATH)> _

Public pFrom As String

<VB.VBFixedString(MAX_PATH), MarshalAs(UnmanagedType.ByValTStr,
SizeConst:=MAX_PATH)> _

Public pTo As String

Public fFlags As Short

Public fAnyOperationsAborted As Boolean

Public hNameMappings As IntPtr

Public lpszProgressTitle As String

End Structure


Nov 20 '05 #4
Is it needed because of the "short"?
Structure SHFILEOPSTRUCT

Dim hwnd As Integer

Dim wFunc As Integer

Dim pFrom As String

Dim pTo As String

Dim fFlags As Short

Dim fAnyOperationsAborted As Integer

Dim hNameMappings As Integer

Dim lpszProgressTitle As String ' only used if FOF_SIMPLEPROGRESS

End Structure
Thanks
"Herfried K. Wagner [MVP]" <hi***************@gmx.at> wrote in message
news:up**************@tk2msftngp13.phx.gbl...
Ken,

* "Ken Tucker [MVP]" <vb***@bellsouth.net> scripsit:
Here is the structure, dll declare, and sample code. It will allow
you to select a file to delete with an open file dialog and send it to the recycle bin.

Structure SHFILEOPSTRUCT


Notice that this structure has byte-aligned members, so I would specify
'Pack:=1' in the attributes.

--
Herfried K. Wagner [MVP]
<URL:http://dotnet.mvps.org/>
<URL:http://dotnet.mvps.org/dotnet/faqs/>

Nov 20 '05 #5
* " Just Me" <ne********@a-znet.com> scripsit:
Is it needed because of the "short"?


Yes. Use this instead:

\\\
<StructLayout(LayoutKind.Sequential, Pack:=1, CharSet:=CharSet.Auto)> _
Private Structure SHFILEOPSTRUCT
Public hWnd As IntPtr
Public wFunc As Integer
Public pFrom As String
Public pTo As String
Public fFlags As Short
Public fAnyOperationsAborted As Boolean
Public hNameMappings As IntPtr
Public lpszProgressTitle As String
End Structure
///

--
Herfried K. Wagner [MVP]
<URL:http://dotnet.mvps.org/>
<URL:http://dotnet.mvps.org/dotnet/faqs/>
Nov 20 '05 #6
Ken, I replied but inadvertingly put it in the wrong place. This is a copy.
I'm going to try this of course, but I'm surprised that no consideration
seems to be given to the fact that pFrom is supposed to be a string that is
terminated with an extra zero? As I remember, it is a list of filenames
separated by semicolons. Maybe this takes the chance that the byte after the
file name does not happen to be a semicolon??

Also, is there some reason a C# declare of the function was given. I'll need
to convert to VB and hope there is no special reason it was given in C#

Also, I believe fAnyOperationsAborted is BOOL. why map to Integer instead
of Boolean?
Thanks very much


"Ken Tucker [MVP]" <vb***@bellsouth.net> wrote in message
news:uw**************@TK2MSFTNGP11.phx.gbl...
Hi,

Here is the structure, dll declare, and sample code. It will allow you to select a file to delete with an open file dialog and send it to the
recycle bin.

Structure SHFILEOPSTRUCT

Dim hwnd As Integer

Dim wFunc As Integer

Dim pFrom As String

Dim pTo As String

Dim fFlags As Short

Dim fAnyOperationsAborted As Integer

Dim hNameMappings As Integer

Dim lpszProgressTitle As String ' only used if FOF_SIMPLEPROGRESS

End Structure

<DllImport("shell32.dll", entrypoint:="SHFileOperationA", _

setlasterror:=True, CharSet:=CharSet.Auto, exactspelling:=True, _

CallingConvention:=CallingConvention.StdCall)> _

Public Shared Function SHFileOperation(ByRef lpFileOp As SHFILEOPSTRUCT) As Integer

End Function

Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles Button1.Click

If OpenFileDialog1.ShowDialog() = DialogResult.OK Then

Dim sh As New SHFILEOPSTRUCT

With sh

.wFunc = FO_DELETE

.pFrom = OpenFileDialog1.FileName

.fFlags = FOF_ALLOWUNDO Or FOF_SIMPLEPROGRESS

End With

If SHFileOperation(sh) <> 0 Then

MessageBox.Show("Error deleting file")

End If

End If

End Sub

Ken

-----------------------------

" Just Me" <ne********@a-znet.com> wrote in message
news:O4**************@TK2MSFTNGP11.phx.gbl...
Can anyone fix the code below?

I need to set pTo to NULL and pFrom to a fullfilepath followed by two NULLs Below Filename is a string
With FileOperation

.wFunc = FO_DELETE

.pFrom = FileName??

.pTo = ??

.fFlags = FOF_ALLOWUNDO Or FOF_SIMPLEPROGRESS

End With

My guess for the structure:

Public Structure SHFILEOPSTRUCT

Public hwnd As IntPtr

Public wFunc As Integer

<VB.VBFixedString(MAX_PATH), MarshalAs(UnmanagedType.ByValTStr,
SizeConst:=MAX_PATH)> _

Public pFrom As String

<VB.VBFixedString(MAX_PATH), MarshalAs(UnmanagedType.ByValTStr,
SizeConst:=MAX_PATH)> _

Public pTo As String

Public fFlags As Short

Public fAnyOperationsAborted As Boolean

Public hNameMappings As IntPtr

Public lpszProgressTitle As String

End Structure


Nov 20 '05 #7
Ken, I replied twice but the note ends up under Herfried's note. Here's a
copy (revised).

I did try this of course, but I'm surprised that no consideration
seems to be given to the fact that pFrom is supposed to be a string that is
terminated with an extra zero? As I remember, it is a list of filenames
separated by semicolons. Maybe this takes the chance that the byte after the
file name does not happen to be a semicolon??
Thanks very much
Also, when I tried it I get "Cannot delete file: Cannot read from source
file or disk." error.

I've included the code below:


Imports System.Runtime.InteropServices

Public Class Form1

Inherits System.Windows.Forms.Form

Public Const FO_DELETE As Integer = &H3

Public Const FOF_ALLOWUNDO As Integer = &H40

Public Const FOF_SIMPLEPROGRESS As Integer = &H100

#Region " Windows Form Designer generated code "

Public Sub New()

MyBase.New()

'This call is required by the Windows Form Designer.

InitializeComponent()

'Add any initialization after the InitializeComponent() call

End Sub

'Form overrides dispose to clean up the component list.

Protected Overloads Overrides Sub Dispose(ByVal disposing As Boolean)

If disposing Then

If Not (components Is Nothing) Then

components.Dispose()

End If

End If

MyBase.Dispose(disposing)

End Sub

'Required by the Windows Form Designer

Private components As System.ComponentModel.IContainer

'NOTE: The following procedure is required by the Windows Form Designer

'It can be modified using the Windows Form Designer.

'Do not modify it using the code editor.

Friend WithEvents Button1 As System.Windows.Forms.Button

Friend WithEvents OpenFileDialog1 As System.Windows.Forms.OpenFileDialog

<System.Diagnostics.DebuggerStepThrough()> Private Sub InitializeComponent()

Me.Button1 = New System.Windows.Forms.Button

Me.OpenFileDialog1 = New System.Windows.Forms.OpenFileDialog

Me.SuspendLayout()

'

'Button1

'

Me.Button1.Location = New System.Drawing.Point(128, 160)

Me.Button1.Name = "Button1"

Me.Button1.Size = New System.Drawing.Size(104, 40)

Me.Button1.TabIndex = 0

Me.Button1.Text = "Button1"

'

'Form1

'

Me.AutoScaleBaseSize = New System.Drawing.Size(5, 13)

Me.ClientSize = New System.Drawing.Size(292, 266)

Me.Controls.Add(Me.Button1)

Me.Name = "Form1"

Me.Text = "Form1"

Me.ResumeLayout(False)

End Sub

#End Region

Structure SHFILEOPSTRUCT

Dim hwnd As Integer

Dim wFunc As Integer

Dim pFrom As String

Dim pTo As String

Dim fFlags As Short

Dim fAnyOperationsAborted As Integer

Dim hNameMappings As Integer

Dim lpszProgressTitle As String ' only used if FOF_SIMPLEPROGRESS

End Structure

<DllImport("shell32.dll", entrypoint:="SHFileOperationA", _

setlasterror:=True, CharSet:=CharSet.Auto, exactspelling:=True, _

CallingConvention:=CallingConvention.StdCall)> _

Public Shared Function SHFileOperation(ByRef lpFileOp As SHFILEOPSTRUCT) As
Integer

End Function

Private Sub Button1_Click1(ByVal sender As Object, ByVal e As
System.EventArgs) Handles Button1.Click

If OpenFileDialog1.ShowDialog() = DialogResult.OK Then

Dim sh As New SHFILEOPSTRUCT

With sh

..wFunc = FO_DELETE

..pFrom = OpenFileDialog1.FileName

..fFlags = FOF_ALLOWUNDO Or FOF_SIMPLEPROGRESS

End With

If SHFileOperation(sh) <> 0 Then

MessageBox.Show("Error deleting file")

End If

End If

End Sub

End Class

"Ken Tucker [MVP]" <vb***@bellsouth.net> wrote in message
news:uw**************@TK2MSFTNGP11.phx.gbl...
Hi,

Here is the structure, dll declare, and sample code. It will allow you to select a file to delete with an open file dialog and send it to the
recycle bin.

Structure SHFILEOPSTRUCT

Dim hwnd As Integer

Dim wFunc As Integer

Dim pFrom As String

Dim pTo As String

Dim fFlags As Short

Dim fAnyOperationsAborted As Integer

Dim hNameMappings As Integer

Dim lpszProgressTitle As String ' only used if FOF_SIMPLEPROGRESS

End Structure

<DllImport("shell32.dll", entrypoint:="SHFileOperationA", _

setlasterror:=True, CharSet:=CharSet.Auto, exactspelling:=True, _

CallingConvention:=CallingConvention.StdCall)> _

Public Shared Function SHFileOperation(ByRef lpFileOp As SHFILEOPSTRUCT) As Integer

End Function

Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles Button1.Click

If OpenFileDialog1.ShowDialog() = DialogResult.OK Then

Dim sh As New SHFILEOPSTRUCT

With sh

.wFunc = FO_DELETE

.pFrom = OpenFileDialog1.FileName

.fFlags = FOF_ALLOWUNDO Or FOF_SIMPLEPROGRESS

End With

If SHFileOperation(sh) <> 0 Then

MessageBox.Show("Error deleting file")

End If

End If

End Sub

Ken

Nov 20 '05 #8

I wonder if you know the answer to the following:

I'm surprised that no consideration
seems to be given to the fact that pFrom is supposed to be a string that is
terminated with an extra zero?

As I remember, it is a list of filenames separated by semicolons.

Maybe this takes the chance that the byte after the file name does not
happen to be a semicolon??
Nov 20 '05 #9
Hi,

The Structure should be public not private.

Ken
------------------
"Herfried K. Wagner [MVP]" <hi***************@gmx.at> wrote in message
news:Oe**************@TK2MSFTNGP10.phx.gbl...
* " Just Me" <ne********@a-znet.com> scripsit:
Is it needed because of the "short"?


Yes. Use this instead:

\\\
<StructLayout(LayoutKind.Sequential, Pack:=1, CharSet:=CharSet.Auto)> _
Private Structure SHFILEOPSTRUCT
Public hWnd As IntPtr
Public wFunc As Integer
Public pFrom As String
Public pTo As String
Public fFlags As Short
Public fAnyOperationsAborted As Boolean
Public hNameMappings As IntPtr
Public lpszProgressTitle As String
End Structure
///

--
Herfried K. Wagner [MVP]
<URL:http://dotnet.mvps.org/>
<URL:http://dotnet.mvps.org/dotnet/faqs/>
Nov 20 '05 #10
Hi,

You can use dll import with vb.net as well as c# so I posted a
vb.net version of the api. As for pFrom it should end with chr(0) not 0.
That is added automatically.

Ken
---------------
" Just Me" <ne********@a-znet.com> wrote in message
news:%2****************@TK2MSFTNGP12.phx.gbl...
I'm going to try this of course, but I'm surprised that no consideration
seems to be given to the fact that pFrom is supposed to be a string that is
terminated with an extra zero?
As I remember, it is a list of filenames separated by semicolons. Maybe this
takes the chance that the byte after the file name does not happen to be a
semicolon??

Also, is there some reason a C# declare of the function was given. I'll need
to convert to VB and hope there is no special reason it was given in C#

Also, I believe fAnyOperationsAborted is BOOL. why map to Integer instead
of Boolean?
Thanks very much

"Ken Tucker [MVP]" <vb***@bellsouth.net> wrote in message
news:uw**************@TK2MSFTNGP11.phx.gbl...
Hi,

Here is the structure, dll declare, and sample code. It will allow you to select a file to delete with an open file dialog and send it to the
recycle bin.

Structure SHFILEOPSTRUCT

Dim hwnd As Integer

Dim wFunc As Integer

Dim pFrom As String

Dim pTo As String

Dim fFlags As Short

Dim fAnyOperationsAborted As Integer

Dim hNameMappings As Integer

Dim lpszProgressTitle As String ' only used if FOF_SIMPLEPROGRESS

End Structure

<DllImport("shell32.dll", entrypoint:="SHFileOperationA", _

setlasterror:=True, CharSet:=CharSet.Auto, exactspelling:=True, _

CallingConvention:=CallingConvention.StdCall)> _

Public Shared Function SHFileOperation(ByRef lpFileOp As SHFILEOPSTRUCT) As Integer

End Function

Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles Button1.Click

If OpenFileDialog1.ShowDialog() = DialogResult.OK Then

Dim sh As New SHFILEOPSTRUCT

With sh

.wFunc = FO_DELETE

.pFrom = OpenFileDialog1.FileName

.fFlags = FOF_ALLOWUNDO Or FOF_SIMPLEPROGRESS

End With

If SHFileOperation(sh) <> 0 Then

MessageBox.Show("Error deleting file")

End If

End If

End Sub

Ken

-----------------------------

" Just Me" <ne********@a-znet.com> wrote in message
news:O4**************@TK2MSFTNGP11.phx.gbl...
Can anyone fix the code below?

I need to set pTo to NULL and pFrom to a fullfilepath followed by two NULLs Below Filename is a string
With FileOperation

.wFunc = FO_DELETE

.pFrom = FileName??

.pTo = ??

.fFlags = FOF_ALLOWUNDO Or FOF_SIMPLEPROGRESS

End With

My guess for the structure:

Public Structure SHFILEOPSTRUCT

Public hwnd As IntPtr

Public wFunc As Integer

<VB.VBFixedString(MAX_PATH), MarshalAs(UnmanagedType.ByValTStr,
SizeConst:=MAX_PATH)> _

Public pFrom As String

<VB.VBFixedString(MAX_PATH), MarshalAs(UnmanagedType.ByValTStr,
SizeConst:=MAX_PATH)> _

Public pTo As String

Public fFlags As Short

Public fAnyOperationsAborted As Boolean

Public hNameMappings As IntPtr

Public lpszProgressTitle As String

End Structure



Nov 20 '05 #11
* "Ken Tucker [MVP]" <vb***@bellsouth.net> scripsit:
The Structure should be public not private.


Depends on where you use it, I think. Or did I miss something?

--
Herfried K. Wagner [MVP]
<URL:http://dotnet.mvps.org/>
<URL:http://dotnet.mvps.org/dotnet/faqs/>
Nov 20 '05 #12

"Ken Tucker [MVP]" <vb***@bellsouth.net> wrote in message
news:%2****************@tk2msftngp13.phx.gbl...
Hi,

You can use dll import with vb.net as well as c# so I posted a I figured that out as some as I ran your code and didn't get a build error.

vb.net version of the api. As for pFrom it should end with chr(0) not 0.
That is added automatically. But the doc says there should be two NULLs at the end, not one.
It's how to get the extra zero that I wonder about.

The code I posted at 11:37 (really yours) always gives me an error when I
try to delete a file.

Thanks for all the answers

Ken
---------------
" Just Me" <ne********@a-znet.com> wrote in message
news:%2****************@TK2MSFTNGP12.phx.gbl...
I'm going to try this of course, but I'm surprised that no consideration
seems to be given to the fact that pFrom is supposed to be a string that is terminated with an extra zero?
As I remember, it is a list of filenames separated by semicolons. Maybe this takes the chance that the byte after the file name does not happen to be a
semicolon??

Also, is there some reason a C# declare of the function was given. I'll need to convert to VB and hope there is no special reason it was given in C#

Also, I believe fAnyOperationsAborted is BOOL. why map to Integer instead
of Boolean?
Thanks very much

"Ken Tucker [MVP]" <vb***@bellsouth.net> wrote in message
news:uw**************@TK2MSFTNGP11.phx.gbl...
Hi,

Here is the structure, dll declare, and sample code. It will

allow
you to select a file to delete with an open file dialog and send it to the recycle bin.

Structure SHFILEOPSTRUCT

Dim hwnd As Integer

Dim wFunc As Integer

Dim pFrom As String

Dim pTo As String

Dim fFlags As Short

Dim fAnyOperationsAborted As Integer

Dim hNameMappings As Integer

Dim lpszProgressTitle As String ' only used if FOF_SIMPLEPROGRESS

End Structure

<DllImport("shell32.dll", entrypoint:="SHFileOperationA", _

setlasterror:=True, CharSet:=CharSet.Auto, exactspelling:=True, _

CallingConvention:=CallingConvention.StdCall)> _

Public Shared Function SHFileOperation(ByRef lpFileOp As SHFILEOPSTRUCT)

As
Integer

End Function

Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles Button1.Click

If OpenFileDialog1.ShowDialog() = DialogResult.OK Then

Dim sh As New SHFILEOPSTRUCT

With sh

.wFunc = FO_DELETE

.pFrom = OpenFileDialog1.FileName

.fFlags = FOF_ALLOWUNDO Or FOF_SIMPLEPROGRESS

End With

If SHFileOperation(sh) <> 0 Then

MessageBox.Show("Error deleting file")

End If

End If

End Sub

Ken

-----------------------------

" Just Me" <ne********@a-znet.com> wrote in message
news:O4**************@TK2MSFTNGP11.phx.gbl...
Can anyone fix the code below?

I need to set pTo to NULL and pFrom to a fullfilepath followed by two

NULLs
Below Filename is a string
With FileOperation

.wFunc = FO_DELETE

.pFrom = FileName??

.pTo = ??

.fFlags = FOF_ALLOWUNDO Or FOF_SIMPLEPROGRESS

End With

My guess for the structure:

Public Structure SHFILEOPSTRUCT

Public hwnd As IntPtr

Public wFunc As Integer

<VB.VBFixedString(MAX_PATH), MarshalAs(UnmanagedType.ByValTStr,
SizeConst:=MAX_PATH)> _

Public pFrom As String

<VB.VBFixedString(MAX_PATH), MarshalAs(UnmanagedType.ByValTStr,
SizeConst:=MAX_PATH)> _

Public pTo As String

Public fFlags As Short

Public fAnyOperationsAborted As Boolean

Public hNameMappings As IntPtr

Public lpszProgressTitle As String

End Structure



Nov 20 '05 #13
To both MVP's,

"I fixed it. I'd appreciate comments on when it's OK to just use String in
a Structure and when Marshal must be used.
This is what I did to the structure:

<StructLayout(LayoutKind.Sequential, Pack:=1, CharSet:=CharSet.Auto)> _

Public Structure SHFILEOPSTRUCT

Public hWnd As IntPtr

Public wFunc As Integer

<MarshalAs(UnmanagedType.LPStr)> Public pFrom As String

<MarshalAs(UnmanagedType.LPStr)> Public pTo As String

'Public pFrom As String

'Public pTo As String

Public fFlags As Short

Public fAnyOperationsAborted As Boolean

Public hNameMappings As IntPtr

Public lpszProgressTitle As String

End Structure

I also had to add Chr(0) as follows:

..pFrom = OpenFileDialog1.FileName & Chr(0)

but that I understand.

Thansk for the help.


Nov 20 '05 #14
* " Just Me" <ne********@a-znet.com> scripsit:
I also had to add Chr(0) as follows:

.pFrom = OpenFileDialog1.FileName & Chr(0)


.... or 'ControlChars.NullChar', 'vbNullChar'.

--
M S Herfried K. Wagner
M V P <URL:http://dotnet.mvps.org/>
V B <URL:http://dotnet.mvps.org/dotnet/faqs/>
Nov 20 '05 #15

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

0
by: avishay | last post by:
Hi All, I want to use SHFileOperation using Python and Win32 extentions, in order to move a file to the trash can. The function itself can be accessed by importing win32com.shell.shell. However, I...
11
by: Grasshopper | last post by:
Hi, I am automating Access reports to PDF using PDF Writer 6.0. I've created a DTS package to run the reports and schedule a job to run this DTS package. If I PC Anywhere into the server on...
1
by: Daveyk0 | last post by:
Hello there, I have a front end database that I have recently made very many changes to to allow off-line use. I keep copies of the databases on my hard drive and link to them rather than the...
2
by: vikas | last post by:
I have following structure in c++. typedef struct MMF_result_struct { int action; char text; int cols,rows; int month,day,year; } MMF_result; Now this structure is shared between C++ and C#...
2
by: Stefan | last post by:
Hi, I cannot get the code below to work (C#). I'm trying to send a file to the recycling bin, and I keep getting the following error: "Cannot delete file: Cannot read from the source file or...
4
by: gsb58 | last post by:
Hi! I've been following the example on SHFILEOPSTRUCT here in the group, but I keep getting the message: 'Cannot read from sourcefile'. Here's the code: SHFILEOPSTRUCT shf = new...
13
by: Kantha | last post by:
Hi all, I have declared an Union as follows typedef union { struct interrupt_bits { unsigned char c_int_hs_fs_status : 1, c_setup_intflag : 1,
1
by: sambarker123 | last post by:
Hi all I am tring to copy a file.The code is as below int _tmain(int argc, _TCHAR* argv) { string s3,s4; s3="C:\\test\\to"; s4="C:\\test\\from\\sam.txt";
7
by: MLH | last post by:
If I'm using the following in a procedure... DoCmd.GoToRecord acDataForm, "FormName", acNext, 4 .... how can I recognize the EOF condition? Using GoToRecord, I find myself lost when trying to...
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome former...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.