OK, I've managed to clarify my question (whew).
I'll show two blocks of code - one in VB6.0 and one in VB.NET. The VB6.0
code manages to execute the callback function, the VB.NET does not. The
question is "how do I get the .NET code to execute the callback function?"
(Note - the declared function works to expose IRQs for a digital
input/output card. Not relevant, but worth knowing if you were curious.)
VB6.0 code:
'Dask.bas - module with lots of declarations
'relevant declaration
Declare Function DIO_INT1_EventM essage Lib "Pci-Dask.dll" (ByVal CardNumber
As Integer, ByVal Int1Mode As Integer, ByVal windowHandle As Long, ByVal
message As Long, ByVal callbackAddr As Long) As Integer
'Form1 code
Private Sub Form_Load()
'superfluous code eliminated
DIO_INT1_EventM essage 0, 0, 0, 0, AddressOf BE_ReadPort
End Sub
'Module1.bas module that contains BE_ReadPort
Function BE_ReadPort() As Long
'this fires properly when I press an electrical switch to send digital
input to the card
MsgBox("Bang!")
End Function
* * * * *
VB.NET code:
'DIOCard.vb - wrapper class
Public Class DIOCard
Declare Function DIO_INT1_EventM essage Lib "Pci-Dask.dll" (ByVal
CardNumber As Integer, ByVal Int1Mode As Integer, ByVal windowHandle As
Long, ByVal message As Long, ByVal callbackAddr As Form1.BP) As Integer
End Class
'Form1.vb - form code
Public Class Form1
Public Delegate Function BP() as Long
Public Function ButtonPressed() as long
'this does not go off
MsgBox("Bang!")
End Function
Private Sub Form1_Load(ByVa l sender As Object, ByVal e As
System.EventArg s) Handles MyBase.Load
'superfluous code eliminated
Dim intResult as integer
intResult = DIO_INT1_EventM essage(0, 0, 0, 0, AddressOf
ButtonPressed)
End Sub
End Class
* * * * *
That's it. Why won't the delegate function fire in .NET? No errors are
reported, the callback simply doesn't fire.
Gardner 3 7903
Hi,
In vb6 integer = vb.net short. vb6 long = vb.net integer. Try
this.
'DIOCard.vb - wrapper class
Public Class DIOCard
Declare Function DIO_INT1_EventM essage Lib "Pci-Dask.dll" (ByVal
CardNumber As short, ByVal Int1Mode As short, ByVal windowHandle As
integer, ByVal message As integer, ByVal callbackAddr As Form1.BP) As short
End Class
'Form1.vb - form code
Public Class Form1
Public Delegate Function BP() as integer
private myBP as bp
Public Function ButtonPressed() as integer
'this does not go off
MsgBox("Bang!")
End Function
Private Sub Form1_Load(ByVa l sender As Object, ByVal e As
System.EventArg s) Handles MyBase.Load
'superfluous code eliminated
Dim intResult as integer
mybp=new bp
intResult = DIO_INT1_EventM essage(0, 0, 0, 0, mybp)
End Sub
End Class
Ken
------------------
"BoloBaby" <bo******@hotma il.com> wrote in message
news:he******** ************@co mcast.com... OK, I've managed to clarify my question (whew).
I'll show two blocks of code - one in VB6.0 and one in VB.NET. The VB6.0 code manages to execute the callback function, the VB.NET does not. The question is "how do I get the .NET code to execute the callback function?"
(Note - the declared function works to expose IRQs for a digital input/output card. Not relevant, but worth knowing if you were curious.)
VB6.0 code:
'Dask.bas - module with lots of declarations 'relevant declaration Declare Function DIO_INT1_EventM essage Lib "Pci-Dask.dll" (ByVal CardNumber As Integer, ByVal Int1Mode As Integer, ByVal windowHandle As Long, ByVal message As Long, ByVal callbackAddr As Long) As Integer
'Form1 code Private Sub Form_Load() 'superfluous code eliminated DIO_INT1_EventM essage 0, 0, 0, 0, AddressOf BE_ReadPort End Sub
'Module1.bas module that contains BE_ReadPort Function BE_ReadPort() As Long 'this fires properly when I press an electrical switch to send digital input to the card MsgBox("Bang!") End Function
* * * * *
VB.NET code:
'DIOCard.vb - wrapper class Public Class DIOCard Declare Function DIO_INT1_EventM essage Lib "Pci-Dask.dll" (ByVal CardNumber As Integer, ByVal Int1Mode As Integer, ByVal windowHandle As Long, ByVal message As Long, ByVal callbackAddr As Form1.BP) As Integer End Class
'Form1.vb - form code Public Class Form1 Public Delegate Function BP() as Long
Public Function ButtonPressed() as long 'this does not go off MsgBox("Bang!") End Function
Private Sub Form1_Load(ByVa l sender As Object, ByVal e As System.EventArg s) Handles MyBase.Load 'superfluous code eliminated Dim intResult as integer intResult = DIO_INT1_EventM essage(0, 0, 0, 0, AddressOf ButtonPressed) End Sub
End Class
* * * * *
That's it. Why won't the delegate function fire in .NET? No errors are reported, the callback simply doesn't fire.
Gardner
(Whoops, might as well make this public!)
Thank you Ken. I'm officially an idiot. I didn't even think to look at the
type changes from 6.0 to .NET.
The "private myBP as bp" line is not needed from your solution when the type
changes are made. I can keep the "AddressOf ButtonPressed" instead of
switching to "Address myBP."
Thank you again.
Hi,
I tried just using addressof instead of a variable and kept
getting object not set to reference of object errors when the api called the
callback a second time.
Ken
----------------
"BoloBaby" <bo******@hotma il.com> wrote in message
news:z5******** ************@co mcast.com... (Whoops, might as well make this public!)
Thank you Ken. I'm officially an idiot. I didn't even think to look at the type changes from 6.0 to .NET.
The "private myBP as bp" line is not needed from your solution when the type changes are made. I can keep the "AddressOf ButtonPressed" instead of switching to "Address myBP."
Thank you again.
This thread has been closed and replies have been disabled. Please start a new discussion. Similar topics |
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 this in C#
menuItem2.MenuItems.Add("123", MenuItem1_Click);
But it does not seem to work, since C# has no AddressOf how can I acomplish this?
|
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 here
'UPGRADE_WARNING: Add a delegate for AddressOf ViewFinderCallbackFunc Click
for more: 'ms-help://MS.VSCC/commoner/redir/redirect.htm?keyword="vbup1048"'
|
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 iMsg As
Integer, ByVal wParam As Integer, ByVal LParam As Integer) As Integer
'Code here
|
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 constructor does in VB.NET within my own class. In
the Thread constructor, you can specify the function to run instead of
creating a ThreadStart object by using the AddressOf keyword such as; Dim
oThread As New Threading.Thread(AddressOf foo.Run)
...
|
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
===================================
Public Declare Function SetCallbacks Lib "tfm.dll" ( _
ByVal hConn As Long, ByVal pfnGuiCallback As Long, ByVal
pGuiCallbackCtx As Long, ByVal pfnGuiStateCallback As Long, ByVal
pGuiStateCallbackCtx As Long) As Long
| |
by: Ant |
last post by:
Hello,
Very simple question but one I need clarified.
Which part of the statement below is considered the 'delegate'?
Is it the 'new System.EventHandler'
or the
btnAccept_Click?
or is it the piece of code which doesn't appear here, but abstracts the
btnAccept_Click method?
|
by: eBob.com |
last post by:
(Not that size matters, but ...) I have a program which is getting too big.
So I'd like to split it into several source files. I know that I can create
a ModuleX.vb source file which looks like this ...
Module ModuleX
Public Sub DoX()
MsgBox("message from DoX")
End Sub
End Module
|
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 delegate, so on
the button click event I can invoke a method at the calling page
level. Everything works great if the control is written in C#, but it
needs to be written in VB.NET.
In C#, in the control I can attach an event like so:
...
|
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()
....
|
by: marktang |
last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look !
Part I. Meaning of...
|
by: Hystou |
last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it.
First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
| |
by: Hystou |
last post by:
Overview:
Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
|
by: tracyyun |
last post by:
Dear forum friends,
With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
|
by: agi2029 |
last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own....
Now, this would greatly impact the work of software developers. The idea...
|
by: isladogs |
last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM).
In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules.
He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms.
Adolph will...
|
by: conductexam |
last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one.
At the time of converting from word file to html my equations which are in the word document file was convert into image.
Globals.ThisAddIn.Application.ActiveDocument.Select();...
|
by: adsilva |
last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
| |
by: muto222 |
last post by:
How can i add a mobile payment intergratation into php mysql website.
| | |