Solved

.NET DELEGATE issue

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

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

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

Today I had a very interesting conundrum that had to get solved quickly. Needless to say, it wasn't resolved quickly because when we needed it we were very rushed, but as soon as the conference call was over and I took a step back I saw the correct …
Real-time is more about the business, not the technology. In day-to-day life, to make real-time decisions like buying or investing, business needs the latest information(e.g. Gold Rate/Stock Rate). Unlike traditional days, you need not wait for a fe…
Internet Business Fax to Email Made Easy - With eFax Corporate (http://www.enterprise.efax.com), you'll receive a dedicated online fax number, which is used the same way as a typical analog fax number. You'll receive secure faxes in your email, fr…
Many functions in Excel can make decisions. The most simple of these is the IF function: it returns a value depending on whether a condition you describe is true or false. Once you get the hang of using the IF function, you will find it easier to us…

912 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

17 Experts available now in Live!

Get 1:1 Help Now