473,383 Members | 1,788 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,383 software developers and data experts.

Delegate problems

I have looked through the Help stuff till I'm blue in the face.

The only 'AddressOf' examples dealing with a delegate for a Function do not
show the original Function in question. The following is my attempt which
fails.

Delegate Function DeviceAttachDelegate(ByVal hDevice As Integer, ByRef
pDeviceInfo As WDU_DEVICE, _
ByRef pUserData As DEVICE_CONTEXT) As Integer

Public Function DeviceAttach(ByVal hDevice As Integer, ByRef pDeviceInfo
As WDU_DEVICE, _
ByRef pUserData As DEVICE_CONTEXT) As Boolean

The DeviceAttach ( and DeviceDetach) function is a callback from a 3rd party
dll so must be exact. To set up the callback address it must be presented to
an API call as an Integer address (Yep, worked in VB6)

Public Sub SetEventTable(ByRef eventTable As WDU_EVENT_TABLE)
eventTable.pfDeviceAttach = AddressOf DeviceAttach
eventTable.pfDeviceDetach = AddressOf DeviceDetach
End Sub

and the error shown is

'AddressOf' expression cannot be converted to 'Integer' because
'Integer' is not a delegate type.

It's obvious I'm doing something way wrong. Probably need some pinvoke type
stuff. I would appreciate some guidance here.

GalenS
Apr 11 '06 #1
5 890

It looks like you are trying to use C# syntax with VB.Net

try instead,
Addhandler eventTable.pfDeviceAttach, addressof DeviceAttach
hth,
Alan.

Apr 11 '06 #2

"AlanT" <al*******@users.com> wrote in message
news:11**********************@e56g2000cwe.googlegr oups.com...

It looks like you are trying to use C# syntax with VB.Net

try instead,
Addhandler eventTable.pfDeviceAttach, addressof DeviceAttach
hth,
Alan.


That doesn't work as eventTable is not really a series of events. It's a
series of addresses the dll will use when it does it's callback event.

GalenS
Apr 11 '06 #3
Hi,

Based on my understanding, you are going to P/Invoke into an unmanaged dll
and pass the managed code as a callback function.

If I misunderstood, please feel free let me know.

Here are two links for your reference.

How to set a hook in Visual Basic .NET
http://support.microsoft.com/?id=319524

Managing Low-Level Keyboard Hooks with the Windows API for VB .NET
http://www.codeguru.com/vb/gen/vb_sy...cle.php/c4831/

If you still have any concern, please feel free to post here.

Best regards,

Peter Huang

Microsoft Online Community Support
==================================================
When responding to posts, please "Reply to Group" via your newsreader so
that others may learn and benefit from your issue.
==================================================
This posting is provided "AS IS" with no warranties, and confers no rights.

Apr 12 '06 #4
After much thought, I am dropping my attempt to use unmanaged API calls
entirely. Instead I am going to make a VB6 Activex dll that does all the
work. Then NET only has to supply a few variables and the dll will do the
work.

My app uses a USB connection to our device. It is USB 2.0 because we need
the speed. The 3rd party USB drivers were recently upgraded to NET. The
problem is, the original version runs 54 times faster than the NET version.

GalenS
""Peter Huang" [MSFT]" <v-******@online.microsoft.com> wrote in message
news:LI*************@TK2MSFTNGXA01.phx.gbl...
Hi,

Based on my understanding, you are going to P/Invoke into an unmanaged dll
and pass the managed code as a callback function.

If I misunderstood, please feel free let me know.

Here are two links for your reference.

How to set a hook in Visual Basic .NET
http://support.microsoft.com/?id=319524

Managing Low-Level Keyboard Hooks with the Windows API for VB .NET
http://www.codeguru.com/vb/gen/vb_sy...cle.php/c4831/

If you still have any concern, please feel free to post here.

Best regards,

Peter Huang

Microsoft Online Community Support
==================================================
When responding to posts, please "Reply to Group" via your newsreader so
that others may learn and benefit from your issue.
==================================================
This posting is provided "AS IS" with no warranties, and confers no
rights.

Apr 12 '06 #5
Hi Galen,

Thanks for your feedback.
If you still have any concern, please feel free to post here.

Best regards,

Peter Huang

Microsoft Online Community Support
==================================================
When responding to posts, please "Reply to Group" via your newsreader so
that others may learn and benefit from your issue.
==================================================
This posting is provided "AS IS" with no warranties, and confers no rights.

Apr 13 '06 #6

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

Similar topics

4
by: KC Eric | last post by:
Hi all, I have a dll file, it has a class, say: class Temp, this class has a function which has a delegate as a parameter, say: public void Test(GameOverHandler _overHandler)
6
by: Valerie Hough | last post by:
I'm not entirely sure what the difference is between these two approaches. In order to avoid reentrant code, I was using Control.BeginInvoke in my UI to cause an asynchronous activity to be done...
5
by: Cosmin Prund | last post by:
Hello everyone. I'm new to c# and I'm trying to use some delegates in my code, so I can do time-tests on whatever I'm doing. In order to do this I tried writing a testing method that will make use...
1
by: Kerry Jenkins | last post by:
I am having problems passing an Event Delegate as an argument to a method that accepts a delegate argument. I get the following error message: 'Public Event ProgressChanged(sender As Object, e...
3
by: Stewart | last post by:
Hey Group, Hoping someone can help me out. I have some code which starts up some asynchronous code using a delegate. The code is below. Basically my main code (not shown) calls...
4
by: Steven Cummings | last post by:
Hello, I'm currently developing on a large project where several assemblies build into DLLs that support the final .NET EXE. The original plan was to implement the project in VB.NET, so the EXE...
1
by: Quimbly | last post by:
I'm having some problems comparing delegates. In all sample projects I create, I can't get the problem to occur, but there is definitely a problem with my production code. I can't give all the...
3
by: steve | last post by:
Hi all, I want to be able to hirearchally define event delegate (declarations) WITHIN interfaces. Unfortunatelly C# 1 doesn't appear to support it. How does the following look as a...
7
by: colin | last post by:
Hi, How can I use a delegate that I can set to call a non static function but of any instance of the class ? eg class TypeTeader<T> { delegate T readDelegate<T>();
6
by: damiensawyer | last post by:
Hi, Can someone please explain to me something about delegates? My understanding is as follows. A delegate is basically an object that can hold a reference to a "method" somewhere. That is,...
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 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 former...
0
by: ryjfgjl | last post by:
In our work, we often need to import Excel data into databases (such as MySQL, SQL Server, Oracle) for data analysis and processing. Usually, we use database tools like Navicat or the Excel import...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...

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.