473,320 Members | 1,958 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,320 software developers and data experts.

AddressOf from VB6 to .Net VB

Private Delegate Function WndCallback _
(ByVal hw As Integer, _
ByVal uMsg As Integer, _
ByVal wParam As Integer, _
ByVal lParam As Integer) As Integer

Private Declare Function SetWindowLong Lib "USER32.DLL" Alias
"SetWindowLongA" _
(ByVal hwnd As Integer, _
ByVal nIndex As Integer, _
ByVal dwNewLong As WndCallback) As WndCallback

Private PrevWndPRoc As WndCallback

Public Sub RegisterFormForOrientationDetection(ByRef f As
System.Windows.Forms.Form)
PrevWndPRoc = SetWindowLong(f.Handle.ToInt32(), _
GWL_WNDPROC, _
BBB-> AddressOf WndProcWithRotationDetection)
End Sub

Hi,

I have converted the VB6 code to .NET according to microsoft.
The compilation is okey, but i get an exception in runtime on line BBB
that says:

Invalid function pointer 0xffff0557 was passed into the runtime to be
converted to a delegate. Passing in invalid function pointers to be
converted to delegates can cause crashes, corruption or data loss.

What i did wrong ?

Thanks,
Pavel.

Mar 22 '06 #1
3 2231
Sorry, i forgit the function itself.

Public Function WndProcWithRotationDetection(ByVal hw As Integer, _
ByVal uMsg As Integer, _
ByVal wParam As Integer, _
ByVal lParam As Integer) As
Integer
' Do the job

End Functon

Mar 22 '06 #2
Hello Pavel,

If your WndProcWithRotationDetection function is not in a module, you must declare it Shared.
With Windows API functions that admit ANSI and Unicode versions, you should declare them Auto to avoid trouble when passing strings (it's only my opinion):
Declare Auto Function SetWindowLong Lib "USER32.DLL" (ByVal hwnd ...

Anyway, if you are processing Windows messages sent to your form, you don't need to do Platform Invoke: You can override the functions PreProcessMessage and WndProc.
If you only want to send messages, you can override DefWndProc.
You can also create a class that implements IMessageFilter and use Application.AddMessageFilter to activate it. This only let you see the messages and to stop them from reaching WndProc.

Regards.
<pa**********@gmail.com> escribió en el mensaje news:11*********************@g10g2000cwb.googlegro ups.com...
| Private Delegate Function WndCallback _
| (ByVal hw As Integer, _
| ByVal uMsg As Integer, _
| ByVal wParam As Integer, _
| ByVal lParam As Integer) As Integer
|
| Private Declare Function SetWindowLong Lib "USER32.DLL" Alias
| "SetWindowLongA" _
| (ByVal hwnd As Integer, _
| ByVal nIndex As Integer, _
| ByVal dwNewLong As WndCallback) As WndCallback
|
| Private PrevWndPRoc As WndCallback
|
| Public Sub RegisterFormForOrientationDetection(ByRef f As
| System.Windows.Forms.Form)
| PrevWndPRoc = SetWindowLong(f.Handle.ToInt32(), _
| GWL_WNDPROC, _
| BBB-> AddressOf WndProcWithRotationDetection)
| End Sub
|
| Hi,
|
| I have converted the VB6 code to .NET according to microsoft.
| The compilation is okey, but i get an exception in runtime on line BBB
| that says:
|
| Invalid function pointer 0xffff0557 was passed into the runtime to be
| converted to a delegate. Passing in invalid function pointers to be
| converted to delegates can cause crashes, corruption or data loss.
|
| What i did wrong ?
|
| Thanks,
| Pavel.

Mar 22 '06 #3

Check out the NativeWindow class for a better way to do window
subclassing in maanged code.
Mattias

--
Mattias Sjögren [C# MVP] mattias @ mvps.org
http://www.msjogren.net/dotnet/ | http://www.dotnetinterop.com
Please reply only to the newsgroup.
Mar 22 '06 #4

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

6
by: ECVerify.com | last post by:
I am trying to figure out how to do this in C Sharp In VB this works perfect MenuItem2.MenuItems.Add("123", AddressOf Me.MenuItem1_Click) The problem is there is no address of in C#, I tried...
2
by: Eric Newton | last post by:
first line fails with "Reference to a non-shared member requires an object reference." yet second line works... any reasons? ctxMenu.MenuItems.Add("Add new pattern...", AddressOf...
2
by: john | last post by:
Hello, I am trying to convert from vb6 to vb.net and I have an issue with the addressOf function. Below is the code any help would be greatly appreciated. Thanks in advance. code erroring...
4
by: ItsMe | last post by:
Hi Guyz, I'm unable to understand this (AddressOf) error??? In VB6 I have two functions: ---------------------------- Public Function ImageFirstImageCallback(ByVal hWnd As Integer, ByVal...
4
by: Anthony Coelho | last post by:
Hello Guru's! I am trying to pass a function pointer as a parameter to a method and can't seem to get it working. Basically I want to do the exact same thing that the System.Threading.Thread...
1
by: peter | last post by:
Probably you might help me regarding this.. I'm new to these Vb.net language. My question is Does AddressOf is accepted in Vb.net? in this VbCode: I have this API...
2
by: David A. Osborn | last post by:
I need to pass the address of a function to the contructor of a class when I create an instance of it so that in the new instance I can dynamically hookup a handler by doing the following: ...
4
by: kaczmar2 | last post by:
I have a custom web control that is called from an aspx page. The custom control dynamically renders out buttons via a public method (AddButton). One of the attributes of the method is a...
1
by: JOHNDOE | last post by:
All right, I've been trying to wrap my head around this by reviewing what is out on the web but still seem to be struggling with this.... Here is the calling code with the AddressOf Error: ...
2
by: =?Utf-8?B?UmljaA==?= | last post by:
Is there a difference between AddressOf and Delegate for assiging a function/Sub to an event? Add_Handler txt1.Click AddressOf WhatColorFont or Private Sub Delegate WhatColorFont() ....
0
by: DolphinDB | last post by:
The formulas of 101 quantitative trading alphas used by WorldQuant were presented in the paper 101 Formulaic Alphas. However, some formulas are complex, leading to challenges in calculation. Take...
0
by: DolphinDB | last post by:
Tired of spending countless mintues downsampling your data? Look no further! In this article, you’ll learn how to efficiently downsample 6.48 billion high-frequency records to 61 million...
0
by: ryjfgjl | last post by:
ExcelToDatabase: batch import excel into database automatically...
0
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
1
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
by: jfyes | last post by:
As a hardware engineer, after seeing that CEIWEI recently released a new tool for Modbus RTU Over TCP/UDP filtering and monitoring, I actively went to its official website to take a look. It turned...
0
by: ArrayDB | last post by:
The error message I've encountered is; ERROR:root:Error generating model response: exception: access violation writing 0x0000000000005140, which seems to be indicative of an access violation...
1
by: PapaRatzi | last post by:
Hello, I am teaching myself MS Access forms design and Visual Basic. I've created a table to capture a list of Top 30 singles and forms to capture new entries. The final step is a form (unbound)...
0
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.