Need to show file properties dialog box

  • Thread starter Thread starter Faraz Azhar
  • Start date Start date
F

Faraz Azhar

Hello

I need to show the shell's file properties dialog box. I tried
converting old vb6 code into vb.net but it gives me error. Here's my
code:

Private Structure SHELLEXECUTEINFO
Dim cbSize As Long
Dim fMask As Long
Dim hwnd As Long
Dim lpVerb As String
Dim lpFile As String
Dim lpParameters As String
Dim lpDirectory As String
Dim nShow As Long
Dim hInstApp As Long
Dim lpIDList As Long
Dim lpClass As String
Dim hkeyClass As Long
Dim dwHotKey As Long
Dim hIcon As Long
Dim hProcess As Long
End Structure

Private Declare Function ShellExecuteEx Lib "shell32" Alias
"ShellExecuteExA" (ByVal SEI As SHELLEXECUTEINFO) As Long

Private Const SEE_MASK_INVOKEIDLIST = &HC
Private Const SEE_MASK_NOCLOSEPROCESS = &H40
Private Const SEE_MASK_FLAG_NO_UI = &H400

Public Sub ShowFileProperties(ByVal sFilename As String, ByVal
hWndOwner As Long)

Dim SEI As SHELLEXECUTEINFO

'Fill in the SHELLEXECUTEINFO structure
With SEI
.cbSize = Len(SEI)
.fMask = SEE_MASK_INVOKEIDLIST Or SEE_MASK_NOCLOSEPROCESS
Or SEE_MASK_FLAG_NO_UI
.lpVerb = "properties"
.lpFile = sFilename
End With

'call the API to display the property sheet
Call ShellExecuteEx(SEI)
End Sub


Now when I call the above sub like this from my main form:
ShowFileProperties(szFileName, Me.Handle)

It gives me the following error:
"Attempted to read or write protected memory. This is often an
indication that other memory is corrupt."


No idea whats happening here. Need help.
 
Got it ! Did lots & lots of searching then found it. Some guy had
written this code snippet in community forums. Here's the code incase
anyone else wants it:

Imports System.Runtime.InteropServices

Public Class Form1

<DllImport("shell32.dll", EntryPoint:="ShellExecuteEx")> Private
Shared Function ShellExecute(ByRef s As SHELLEXECUTEINFO) As Integer
End Function

<StructLayout(LayoutKind.Sequential)> Private Structure
SHELLEXECUTEINFO
Public cbSize As Integer
Public fMask As Integer
Public hwnd As IntPtr
Public lpVerb As String
Public lpFile As String
Public lpParameters As String
Public lpDirectory As String
Public nShow As Integer
Public hInstApp As IntPtr
Public lpIDList As IntPtr
Public lpClass As String
Public hkeyClass As IntPtr
Public dwHotKey As Integer
Public hIcon As IntPtr
Public hProcess As IntPtr
End Structure

Public Shared Sub DisplayFileProperties(ByVal xFileName As String,
ByVal hwnd As IntPtr)


Const SEE_MASK_INVOKEIDLIST As Integer = &HC
Const SW_SHOW As Integer = 5
Dim shInfo As New SHELLEXECUTEINFO()
With shInfo
.cbSize = Marshal.SizeOf(shInfo)
.lpFile = xFileName
.nShow = SW_SHOW
.fMask = SEE_MASK_INVOKEIDLIST
.lpVerb = "properties"
.hwnd = hwnd
End With
ShellExecute(shInfo)
End Sub

End Class
 
Back
Top