B
Basha
NullArgument Exception is happening on marshal.copy statement
execution. Plz help, following is the code
Private Structure SHELLEXECUTEEX
Public cbSize As UInt32
Public fMask As UInt32
Public hwnd As IntPtr
Public lpVerb As IntPtr
Public lpFile As IntPtr
Public lpParameters As IntPtr
Public lpDirectory As IntPtr
Public nShow As Integer
Public hInstApp As IntPtr
' Optional members
Public lpIDList As IntPtr
Public lpClass As IntPtr
Public hkeyClass As IntPtr
Public dwHotKey As UInt32
Public hIcon As IntPtr
Public hProcess As IntPtr
End Structure 'SHELLEXECUTEEX
Private Class APIClass
<DllImport("coredll")> _
Public Shared Function ShellExecuteEx(ByRef ex As
ShellExecuteEx) As Integer
End Function
'<DllImport("coredll")> _
Public Shared Function LocalAlloc(ByVal flags As Integer,
ByVal size As Integer) As IntPtr
End Function
<DllImport("coredll")> _
Public Shared Sub LocalFree(ByVal ptr As IntPtr)
End Sub
End Class
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles Button1.Click
Dim docname As String = clsAppSettings.AppDirectory & "\" &
clsAppSettings.LU_CabFileName
Dim fInfo As New FileInfo(docname)
Dim nSize As Integer = docname.Length * 2 + 2
Dim pData As IntPtr = APIClass.LocalAlloc(&H40, nSize)
Marshal.Copy(Encoding.Unicode.GetBytes(fInfo.Name), 0, pData,
nSize - 2)
Dim see As New SHELLEXECUTEEX
see.cbSize = System.Convert.ToUInt32(60)
see.dwHotKey = System.Convert.ToUInt32(0)
see.fMask = System.Convert.ToUInt32(0)
see.hIcon = IntPtr.Zero
see.hInstApp = IntPtr.Zero
see.hProcess = IntPtr.Zero
see.lpClass = IntPtr.Zero
see.lpDirectory = IntPtr.Zero
see.lpIDList = IntPtr.Zero
see.lpParameters = IntPtr.Zero
see.lpVerb = IntPtr.Zero
see.nShow = 0
see.lpFile = pData
APIClass.ShellExecuteEx(see)
APIClass.LocalFree(pData)
End Sub
execution. Plz help, following is the code
Private Structure SHELLEXECUTEEX
Public cbSize As UInt32
Public fMask As UInt32
Public hwnd As IntPtr
Public lpVerb As IntPtr
Public lpFile As IntPtr
Public lpParameters As IntPtr
Public lpDirectory As IntPtr
Public nShow As Integer
Public hInstApp As IntPtr
' Optional members
Public lpIDList As IntPtr
Public lpClass As IntPtr
Public hkeyClass As IntPtr
Public dwHotKey As UInt32
Public hIcon As IntPtr
Public hProcess As IntPtr
End Structure 'SHELLEXECUTEEX
Private Class APIClass
<DllImport("coredll")> _
Public Shared Function ShellExecuteEx(ByRef ex As
ShellExecuteEx) As Integer
End Function
'<DllImport("coredll")> _
Public Shared Function LocalAlloc(ByVal flags As Integer,
ByVal size As Integer) As IntPtr
End Function
<DllImport("coredll")> _
Public Shared Sub LocalFree(ByVal ptr As IntPtr)
End Sub
End Class
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles Button1.Click
Dim docname As String = clsAppSettings.AppDirectory & "\" &
clsAppSettings.LU_CabFileName
Dim fInfo As New FileInfo(docname)
Dim nSize As Integer = docname.Length * 2 + 2
Dim pData As IntPtr = APIClass.LocalAlloc(&H40, nSize)
Marshal.Copy(Encoding.Unicode.GetBytes(fInfo.Name), 0, pData,
nSize - 2)
Dim see As New SHELLEXECUTEEX
see.cbSize = System.Convert.ToUInt32(60)
see.dwHotKey = System.Convert.ToUInt32(0)
see.fMask = System.Convert.ToUInt32(0)
see.hIcon = IntPtr.Zero
see.hInstApp = IntPtr.Zero
see.hProcess = IntPtr.Zero
see.lpClass = IntPtr.Zero
see.lpDirectory = IntPtr.Zero
see.lpIDList = IntPtr.Zero
see.lpParameters = IntPtr.Zero
see.lpVerb = IntPtr.Zero
see.nShow = 0
see.lpFile = pData
APIClass.ShellExecuteEx(see)
APIClass.LocalFree(pData)
End Sub