[Last Call] Learn about multicloud storage options and how to improve your company's cloud strategy. Register Now

x
?
Solved

.NET DELEGATE issue

Posted on 2010-09-17
5
Medium Priority
?
382 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 668 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 1332 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 1332 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

Veeam Task Manager for Hyper-V

Task Manager for Hyper-V provides critical information that allows you to monitor Hyper-V performance by displaying real-time views of CPU and memory at the individual VM-level, so you can quickly identify which VMs are using host resources.

Question has a verified solution.

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

It seems a simple enough task, yet I see repeated questions asking how to do it: how to pass data between two forms. In this article, I will show you the different mechanisms available for you to do just that. This article is directed towards the .N…
The object model of .Net can be overwhelming at times – so overwhelming that quite trivial tasks often take hours of research. In this case, the task at hand was to populate the datagrid from SQL Server database in Visual Studio 2008 Windows applica…
Video by: ITPro.TV
In this episode Don builds upon the troubleshooting techniques by demonstrating how to properly monitor a vSphere deployment to detect problems before they occur. He begins the show using tools found within the vSphere suite as ends the show demonst…
Visualize your data even better in Access queries. Given a date and a value, this lesson shows how to compare that value with the previous value, calculate the difference, and display a circle if the value is the same, an up triangle if it increased…

650 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