Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people, just like you, are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
Solved

.NET DELEGATE issue

Posted on 2010-09-17
5
367 Views
Last Modified: 2013-11-26
I have converted a VB6 project to .NET.  I have worked through every issue but one.

Add a delegate for AddressOf fWindowProc

I have read numerous articles and looked at examples.  However, when I try to use this code:

I created a delegate

Delegate Function fWindowProcDEL(ByVal hw As Integer, ByVal uMsg As Integer, ByVal wParam As Integer, ByVal lParam As Integer) As Integer

I added those code to my code:

Dim MyDelegate As fWindowProcDEL
MyDelegate = New fWindowProcDEL(AddressOf fWindowProc)

lpPrevWndProc = SetWindowLong(lHwnd, GWL_WNDPROC, MyDelegate)

I get the error:  Value of type 'Project1.modMain.fWindowProcDEL' cannot be converted to Integer
0
Comment
Question by:Kevin_Foley
  • 2
  • 2
5 Comments
 
LVL 85

Accepted Solution

by:
Mike Tomlinson earned 167 total points
ID: 33702509
What are you doing with SetWindowLong() in the original app?

...many things can be done without the need for APIs in.Net.

Without knowing more, you can change attributes of the form using CreateParams():
http://msdn.microsoft.com/en-us/library/system.windows.forms.control.createparams.aspx

For instance, you can grey out the 'X' in the upper right of the form with:
    Protected Overrides ReadOnly Property CreateParams() As System.Windows.Forms.CreateParams
        Get
            Const CS_NoClose As Integer = &H200
            Dim cp As CreateParams = MyBase.CreateParams
            cp.ClassStyle = cp.ClassStyle Or CS_NoClose
            Return cp
        End Get
    End Property

Open in new window

0
 
LVL 29

Assisted Solution

by:nffvrxqgrcfqvvc
nffvrxqgrcfqvvc earned 333 total points
ID: 33702824
It looks like your trying to subclass.... You can override the forms WndProc() instead of using the API that is of course if subclassing is your intention.

Protected Overrides Sub WndProc(ByRef m As System.Windows.Forms.Message)
        If m.Msg = &H1 Then
            Debug.Print("WM_CREATE")
        End If
        MyBase.WndProc(m)
    End Sub

Open in new window

0
 

Author Comment

by:Kevin_Foley
ID: 33703306
I need to do a major rewrite in the long run.  In the short term, I am trying to resurrect this 7 year old tool.  

I have two applications and I'm monitoring the messages in one from the other.  (sub class the form to trap for windows messages).  

The VB6 code was

lpPrevWndProc = SetWindowLong(lwnd, GWL_WNDPROC, Address of fwindowProc.)

.NET doesn't like the Address of and says I need a delegate.
0
 
LVL 29

Assisted Solution

by:nffvrxqgrcfqvvc
nffvrxqgrcfqvvc earned 333 total points
ID: 33703545
You can pass messeges by overriding WndProc() you won't need to use the API.. .NET makes it MUCH simpler :)
Just be aware of isolation on Vista and later you can't send messages to higher integrity process unless you change the message filter.

'// Use only on Windows Vista.
ChangeWindowMessageFilter
'// Use only on Windows 7 or later.
ChangeWindowMessageFilterEx
0
 

Author Closing Comment

by:Kevin_Foley
ID: 33753580
found the answer... had to add .target
0

Featured Post

Master Your Team's Linux and Cloud Stack

Come see why top tech companies like Mailchimp and Media Temple use Linux Academy to build their employee training programs.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Title # Comments Views Activity
Example works but why do I need to click twice on button 4 48
VB.NET 2008 Publish Error 2 34
VB.NET 2008 - Windows Protected Your PC 7 41
Why use this lambda? 12 36
This document covers how to connect to SQL Server and browse its contents.  It is meant for those new to Visual Studio and/or working with Microsoft SQL Server.  It is not a guide to building SQL Server database connections in your code.  This is mo…
For those of you who don't follow the news, or just happen to live under rocks, Microsoft Research released a beta SDK (http://www.microsoft.com/en-us/download/details.aspx?id=27876) for the Xbox 360 Kinect. If you don't know what a Kinect is (http:…
Although Jacob Bernoulli (1654-1705) has been credited as the creator of "Binomial Distribution Table", Gottfried Leibniz (1646-1716) did his dissertation on the subject in 1666; Leibniz you may recall is the co-inventor of "Calculus" and beat Isaac…

856 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question