Solved

.NET DELEGATE issue

Posted on 2010-09-17
5
364 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

Highfive Gives IT Their Time Back

Highfive is so simple that setting up every meeting room takes just minutes and every employee will be able to start or join a call from any room with ease. Never be called into a meeting just to get it started again. This is how video conferencing should work!

Join & Write a Comment

Normally the drop down box control found in the .Net framework tools is able to select just one data and value at a time, which is displayed on the text area.   But what if you want to have multiple values to be selected in the drop down box? As …
This article describes relatively difficult and non-obvious issues that are likely to arise when creating COM class in Visual Studio and deploying it by professional MSI-authoring tools. It is assumed that the reader is already familiar with the cla…
Illustrator's Shape Builder tool will let you combine shapes visually and interactively. This video shows the Mac version, but the tool works the same way in Windows. To follow along with this video, you can draw your own shapes or download the file…
Get a first impression of how PRTG looks and learn how it works.   This video is a short introduction to PRTG, as an initial overview or as a quick start for new PRTG users.

706 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

Need Help in Real-Time?

Connect with top rated Experts

15 Experts available now in Live!

Get 1:1 Help Now