The code below will not work on Vista 64bit?

Y

yxq

Hello,
The code below can popup the property dialog of a file, it works well on XP,
Vista 32bit, but it will not work on Vista 64bit, how to correct it? i have
tried to change integer to intptr, but not work yet, thank you.

//////////////////////////////////////////////////////
<System.Runtime.InteropServices.StructLayout(System.Runtime.InteropServices.LayoutKind.Sequential)>
Public Class SHELLEXECUTEINFO
Public cbSize As Integer
Public fMask As Integer
Public hwnd As Integer
<System.Runtime.InteropServices.MarshalAs(System.Runtime.InteropServices.UnmanagedType.LPWStr),
Microsoft.VisualBasic.VBFixedString(255)> Public lpVerb As String = ""
<System.Runtime.InteropServices.MarshalAs(System.Runtime.InteropServices.UnmanagedType.LPWStr),
Microsoft.VisualBasic.VBFixedString(255)> Public lpFile As String = ""
<System.Runtime.InteropServices.MarshalAs(System.Runtime.InteropServices.UnmanagedType.LPWStr),
Microsoft.VisualBasic.VBFixedString(255)> Public lpParameters As String = ""
<System.Runtime.InteropServices.MarshalAs(System.Runtime.InteropServices.UnmanagedType.LPWStr),
Microsoft.VisualBasic.VBFixedString(255)> Public lpDirectory As String = ""
Public nShow As Integer
Public hInstApp As Integer
Public lpIDList As Integer
Public lpClass As String
Public hkeyClass As Integer
Public dwHotKey As Integer
Public hIcon As Integer
Public hProcess As Integer

Private Const SW_SHOW As Integer = 5
Private Const SEE_MASK_INVOKEIDLIST As Integer = &HC
Private Declare Auto Function ShellExecuteEX Lib "shell32.dll" Alias
"ShellExecuteEx" (ByVal SEI As SHELLEXECUTEINFO) As Integer

Public Shared Sub ShowPropertiesDialog(ByVal Path As String)
If System.IO.File.Exists(Path) Or System.IO.Directory.Exists(Path)
Then
Dim shInfo As New SHELLEXECUTEINFO
shInfo.cbSize =
System.Runtime.InteropServices.Marshal.SizeOf(GetType(SHELLEXECUTEINFO))
shInfo.lpFile = Path
shInfo.nShow = SW_SHOW
shInfo.fMask = SEE_MASK_INVOKEIDLIST
shInfo.lpVerb = "properties"
ShellExecuteEX(shInfo)
End If
End Sub
End Class
 
A

Armin Zingler

yxq said:
Hello,
The code below can popup the property dialog of a file, it works
well on XP,
Vista 32bit, but it will not work on Vista 64bit, how to correct it?
i have
tried to change integer to intptr, but not work yet, thank you.

That's what I almost suggested: Intptr. Where is your version using IntPtr?
Not all Integers must be Intptrs, only "handles". If I see it right, it's
- hwnd
- hInstApp
- hkeyClass
- hIcon
- hProcess

I haven't checked the rest...


Private Declare Auto Function ShellExecuteEX Lib "shell32.dll"
Alias
"ShellExecuteEx" (ByVal SEI As SHELLEXECUTEINFO) As Integer

Isn't it ByRef and As Boolean (not Integer)?

I have no experience in this but what did you set as the target platform for
the application in the project properties? 64-Bit?


Armin
 
H

Herfried K. Wagner [MVP]

yxq said:
The code below can popup the property dialog of a file, it works well on
XP, Vista 32bit, but it will not work on Vista 64bit, how to correct it? i
have tried to change integer to intptr, but not work yet, thank you.

//////////////////////////////////////////////////////
<System.Runtime.InteropServices.StructLayout(System.Runtime.InteropServices.LayoutKind.Sequential)>
Public Class SHELLEXECUTEINFO
Public cbSize As Integer
Public fMask As Integer
Public hwnd As Integer

=> 'Public hwnd As IntPtr'. Note that 'IntPtr' is a 32-bit type on 32-bit
systems and a 64-bit type on 64-bit systems.
<System.Runtime.InteropServices.MarshalAs(System.Runtime.InteropServices.UnmanagedType.LPWStr),
Microsoft.VisualBasic.VBFixedString(255)> Public lpVerb As String = ""

<System.Runtime.InteropServices.MarshalAs(System.Runtime.InteropServices.UnmanagedType.LPWStr),
Microsoft.VisualBasic.VBFixedString(255)> Public lpFile As String = ""

<System.Runtime.InteropServices.MarshalAs(System.Runtime.InteropServices.UnmanagedType.LPWStr),
Microsoft.VisualBasic.VBFixedString(255)> Public lpParameters As String =
""

<System.Runtime.InteropServices.MarshalAs(System.Runtime.InteropServices.UnmanagedType.LPWStr),
Microsoft.VisualBasic.VBFixedString(255)> Public lpDirectory As String =
""

You do not need fixed strings here. In addition, you can remove the
'MarshalAs' attribute in order to make the function call succeed on Windows
ANSI systems.
Public hInstApp As Integer

=> 'As IntPtr'.
Public lpIDList As Integer

=> 'As IntPtr'.
Public hkeyClass As Integer

=> 'As IntPtr'
Public hIcon As Integer

=> 'As IntPtr'.
Public hProcess As Integer

=> 'As IntPtr'
Private Declare Auto Function ShellExecuteEX Lib "shell32.dll" Alias
"ShellExecuteEx" (ByVal SEI As SHELLEXECUTEINFO) As Integer

=> 'ByRef lpExecInfo As SHELLEXECUTEINFO'.

The type of the return value should be 'Boolean', not 'Integer'.
 
Y

yxq

I have tested the code below, it works well both 32 and 64 bit, thank you
very much.

//////////////////////////////////////////////////////////////////////////////////////////////
<System.Runtime.InteropServices.StructLayout(System.Runtime.InteropServices.LayoutKind.Sequential)>
Public Class SHELLEXECUTEINFO
Private cbSize As Integer
Private fMask As Integer
Private hwnd As IntPtr
<System.Runtime.InteropServices.MarshalAs(System.Runtime.InteropServices.UnmanagedType.LPWStr),
Microsoft.VisualBasic.VBFixedString(255)> Private lpVerb As String = ""
<System.Runtime.InteropServices.MarshalAs(System.Runtime.InteropServices.UnmanagedType.LPWStr),
Microsoft.VisualBasic.VBFixedString(255)> Private lpFile As String = ""
<System.Runtime.InteropServices.MarshalAs(System.Runtime.InteropServices.UnmanagedType.LPWStr),
Microsoft.VisualBasic.VBFixedString(255)> Private lpParameters As String =
""
<System.Runtime.InteropServices.MarshalAs(System.Runtime.InteropServices.UnmanagedType.LPWStr),
Microsoft.VisualBasic.VBFixedString(255)> Private lpDirectory As String = ""
Private nShow As Integer
Private hInstApp As IntPtr
Private lpIDList As IntPtr
Private lpClass As String
Private hkeyClass As IntPtr
Private dwHotKey As Integer
Private hIcon As IntPtr
Private hProcess As IntPtr

Private Const SW_SHOW As Integer = 5
Private Const SEE_MASK_INVOKEIDLIST As Integer = &HC
Private Declare Auto Function ShellExecuteEX Lib "shell32.dll" Alias
"ShellExecuteEx" (ByVal lpExecInfo As SHELLEXECUTEINFO) As Boolean

Public Shared Sub ShowPropertiesDialog(ByVal Path As String)
If System.IO.File.Exists(Path) Or System.IO.Directory.Exists(Path)
Then
Dim shInfo As New SHELLEXECUTEINFO
shInfo.cbSize =
System.Runtime.InteropServices.Marshal.SizeOf(GetType(SHELLEXECUTEINFO))
shInfo.lpFile = Path
shInfo.nShow = SW_SHOW
shInfo.fMask = SEE_MASK_INVOKEIDLIST
shInfo.lpVerb = "properties"
ShellExecuteEX(shInfo)
End If
End Sub
End Class
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top