Jules
Jules

Reputation: 4339

Strange WndProc bug in .Net. VB.Net more specifically

ETA: I use visual studio 2008 express edition.

If I override WndProc and mess up somehow, I'll usually backtrack by commenting out code until it works again.

The strange thing with WndProc though is you can strip it down to:

Protected Overrides Sub WndProc(ByRef m As System.Windows.Forms.Message)
    MyBase.WndProc((m))
End Sub

and it still throws the error.

I have to remove the code and retype it in to reset the error.

Anyone else experienced this?

ETA:

Answered below by Chris Haas.

I hadn't realised, but this problem must only have occurred when I'd used code from reflector. Reflector mis-translates to vb.net and inserts extra brackets into the calls to WndProc base.

Upvotes: 2

Views: 1464

Answers (1)

Chris Haas
Chris Haas

Reputation: 55427

When you wrap an argument in parenthesis you are overriding the ByRef call and instead calling it ByVal. See Argument Not Being Modified by Procedure Call - Underlying Variable

Just change the code to:

Protected Overrides Sub WndProc(ByRef m As System.Windows.Forms.Message)
    MyBase.WndProc(m)
End Sub

Upvotes: 5

Related Questions