Solved

.NET DELEGATE issue

Posted on 2010-09-17
5
372 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
[X]
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
  • 2
  • 2
5 Comments
 
LVL 86

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

Revamp Your Training Process

Drastically shorten your training time with WalkMe's advanced online training solution that Guides your trainees to action.

Question has a verified solution.

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

A basic question.. “What is the Garbage Collector?” The usual answer given back: “Garbage collector is a background thread run by the CLR for freeing up the memory space used by the objects which are no longer used by the program.” I wondered …
A long time ago (May 2011), I have written an article showing you how to create a DLL using Visual Studio 2005 to be hosted in SQL Server 2005. That was valid at that time and it is still valid if you are still using these versions. You can still re…
If you're a developer or IT admin, you’re probably tasked with managing multiple websites, servers, applications, and levels of security on a daily basis. While this can be extremely time consuming, it can also be frustrating when systems aren't wor…
In this video we outline the Physical Segments view of NetCrunch network monitor. By following this brief how-to video, you will be able to learn how NetCrunch visualizes your network, how granular is the information collected, as well as where to f…

717 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