Home All Groups Group Topic Archive Search About
Author
11 Apr 2006 3:24 PM
Galen Somerville
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

Author
11 Apr 2006 5:58 PM
AlanT
It looks like you are trying to use C# syntax with VB.Net

try instead,


    Addhandler eventTable.pfDeviceAttach, addressof DeviceAttach


hth,
Alan.
Author
11 Apr 2006 7:52 PM
Galen Somerville
Show quote Hide quote
"AlanT" <alanto***@users.com> wrote in message
news:1144778316.285253.283370@e56g2000cwe.googlegroups.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
Author
12 Apr 2006 7:33 AM
Peter Huang" [MSFT]
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_system/keyboard/article.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.
Author
12 Apr 2006 7:24 PM
Galen Somerville
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


Show quoteHide quote
""Peter Huang" [MSFT]" <v-phu***@online.microsoft.com> wrote in message
news:LI3Q0NgXGHA.888@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_system/keyboard/article.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.
>
Author
13 Apr 2006 3:24 AM
Peter Huang" [MSFT]
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.