ListviewControlDesigner - UnsafeNativeMethods.CallWindowProc - AccessViolation

  • Thread starter Thread starter SFC_Nitro
  • Start date Start date
S

SFC_Nitro

Guest
Ive been using this control that I created for a while and havent had any issues until recently. My compiled applications run the listview without issue, but because the Column Sizing with the Mouse wasnt working... I needed to find out why. Now when testing the source in VB 2008, I get this exception. Some of the code is below the exception. The error being pointed as line 212 is in the WndProc Override at boolInvoke = me.listViewDesign......

Exception.... I cannot upload the image screenshot until my account is verified...

System.Reflection.TargetInvocationException ......

System.AccessViolationException....

at System.Windows.Forms.UnsafeNativeMethods.CallWindowProc(IntPtr windProc, IntPtr hWnd, Int32 msg, IntPtr wParam, IntPtr lParam)

at ... DefWndProc...

at ChildSubClass.... DefWndProc...

all the way to ... WndProc... vb:line 212



<System.Diagnostics.DebuggerStepThrough()> _
Public Overrides Sub Initialize(ByVal component As IComponent)
MessageBox.Show(component.GetType().ToString)
Use reflection to bypass the "internal" marker on ListViewDesigner
If we cant get the unversioned designer, look specifically for .NET 4.0 version of it.
Dim tListViewDesigner As Type = Type.[GetType]("System.Windows.Forms.Design.ListViewDesigner, System.Design")

If tListViewDesigner Is Nothing Then
Throw New ArgumentException("Could not load ListViewDesigner")
Else
_ListViewDesigner = CType(Activator.CreateInstance(tListViewDesigner, BindingFlags.Instance Or BindingFlags.[Public], _
Nothing, Nothing, Nothing), ControlDesigner)

Debug.Assert(_ListViewDesigner IsNot Nothing, "No ListView")
Me._DesignerFilter = _ListViewDesigner

Fetch the methods from the ListViewDesigner that we know we want to use
Me.listViewDesignGetHitTest = tListViewDesigner.GetMethod("GetHitTest", BindingFlags.Instance Or BindingFlags.NonPublic)
Me.listViewDesignWndProc = tListViewDesigner.GetMethod("WndProc", BindingFlags.Instance Or BindingFlags.NonPublic)

Tell the Designer to use properties of default designer as well as the properties of this class (do before base.Initialize)
TypeDescriptor.CreateAssociation(component, _ListViewDesigner)

Dim site As IServiceContainer = CType(component.Site, IServiceContainer)
If site IsNot Nothing AndAlso GetService(GetType(DesignerCommandSet)) Is Nothing Then
If site.GetService(GetType(DesignerCommandSet)) Is Nothing Then
site.AddService(GetType(DesignerCommandSet), New CDDesignerCommandSet(Me))
End If
Else
Debug.Fail("site Is Nothing AndAlso GetService(GetType(DesignerCommandSet)) IsNot Nothing")
End If

If TypeOf component Is TransparentListView Then
_ListViewDesigner.Initialize(component)
Else
If TypeOf component Is PanelListView Then
MessageBox.Show("Panel")
_ListViewDesigner.Initialize(CType(component, PanelListView).TransparentListView1)
End If
End If

End If

MyBase.Initialize(component)
RemoveDuplicateDockingActionList()
If TypeOf MyBase.Component Is ListView Then
_CurListView = DirectCast(MyBase.Component, TransparentListView)
Else
_CurListView = DirectCast(CType(MyBase.Component, PanelListView).TransparentListView1, TransparentListView)
End If


End Sub

#Region "WndProc"
<DebuggerStepThrough()> _
Protected Overrides Sub WndProc(ByRef m As Message)
Static LVM_HITTEST := 0x1012 ; (LVM_FIRST + 18)
Static MouseDown As Boolean = False
Dim boolInvoke As Boolean = False
System.Diagnostics.Debug.WriteLine(m.Msg);
Select Case m.Msg
Case Msgs.WM_NOTIFY, &H204E
The listview designer is interested in HDN_ENDTRACK notifications
If _ListViewDesigner IsNot Nothing AndAlso Me.listViewDesignWndProc IsNot Nothing Then

**** LINE 212 ERROR???
boolInvoke = Me.listViewDesignWndProc.Invoke(_ListViewDesigner, New Object() {m})
End If
Exit Select
If boolInvoke Then
Dim nmhdr As NativeMethods.NMHDR = DirectCast(System.Runtime.InteropServices.Marshal.PtrToStructure(m.LParam, GetType(NativeMethods.NMHDR)), NativeMethods.NMHDR)
If nmhdr.code = -327 Then
Try
Dim svc As IComponentChangeService
svc = DirectCast(Me.GetService(GetType(IComponentChangeService)), IComponentChangeService)
If svc IsNot Nothing Then
svc.OnComponentChanged(MyBase.Component, Nothing, Nothing, Nothing)
End If
Catch generatedExceptionName As InvalidOperationException
Return
End Try
Else
MyBase.WndProc(m)
End If

Exit Select
Else
MyBase.WndProc(m)
Exit Select
End If
Case Msgs.WM_VSCROLL
_CurListView.OnListViewScrolled(EventArgs.Empty)
MyBase.WndProc(m)
Case Msgs.WM_HSCROLL
_CurListView.OnListViewScrolled(EventArgs.Empty)
MyBase.WndProc(m)
Case SBM_SETSCROLLINFO
_CurListView.OnListViewScrolled(EventArgs.Empty)
MyBase.WndProc(m)

Case Msgs.WM_SETCURSOR &H20
WM_SETCURSOR
Return True to cancel column cursor visibility
do nothing to handle it.
m.Result = 1
MyBase.WndProc(m)
Exit Select
Case Msgs.WM_RBUTTONDBLCLK &H206
WM_RBUTTONDBLCLK
If Not _CurListView.HandleRButtonDoubleClick(m) Then
MyBase.WndProc(m)
End If
Exit Select

Case HDM_LAYOUT
If Not Me.HandleLayout(m) Then
MyBase.WndProc(m)
End If
Exit Select

Case Msgs.WM_DESTROY
If Not Me.HandleDestroy(m) Then
MyBase.WndProc(m)
End If
Exit Select
Case Else
MyBase.WndProc(m)
Exit Select
End Select
End Sub
#End Region

Continue reading...
 
Back
Top