469,592 Members | 1,769 Online
Bytes | Developer Community
New Post

Home Posts Topics Members FAQ

Post your question to a community of 469,592 developers. It's quick & easy.

VB2005 Short address pointer

A call to a third party dll, which will call back, requires an hWnd and a 16
bit sub address. Yes this was designed for VB6.

Addressof and delegates and all that good crap doesn't help.

The hWnd where the subroutine is located is no problem. But how can I
provide the subroutines address as a Short ??

GalenS


May 2 '06 #1
2 1453
>A call to a third party dll, which will call back, requires an hWnd and a 16
bit sub address. Yes this was designed for VB6.
VB6 also targets Win32 so I don't see how it could work there.

The hWnd where the subroutine is located is no problem. But how can I
provide the subroutines address as a Short ??


If you're running .NET 2.0 you can try calling
Marshal.GetFunctionPointerForDelegate(), truncate the result to
16-bits and see if it works.
Mattias

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

"Mattias Sjögren" <ma********************@mvps.org> wrote in message
news:OP**************@TK2MSFTNGP02.phx.gbl...
A call to a third party dll, which will call back, requires an hWnd and a
16
bit sub address. Yes this was designed for VB6.


VB6 also targets Win32 so I don't see how it could work there.

The hWnd where the subroutine is located is no problem. But how can I
provide the subroutines address as a Short ??


If you're running .NET 2.0 you can try calling
Marshal.GetFunctionPointerForDelegate(), truncate the result to
16-bits and see if it works.
Mattias

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


My bad. In VB2005 it would be integer not short

VB6 code in bas module. The Call SetEventTable is immediately followed by
the 3rd party dll call WDU_Init

Dim eventTable As WDU_EVENT_TABLE

Call SetEventTable(eventTable, AddressOf DeviceAttach, AddressOf
DeviceDetach)
eventTable.pUserData = WD_VB_GetAddress(DevCtx, 1, 1)

dwError = WDU_Init(hdriver, matchTable, 1, eventTable, _
DEFAULT_LICENSE_STRING, WD_ACKNOWLEDGE, hWnd)

VB6 driver code bas module. It would appear that the AddressOf's could be
left out of the SetEventTable call and placed directly after the ='s below.

Public Sub SetEventTable(ByRef eventTable As WDU_EVENT_TABLE, ByVal attachCb
As Long, _
ByVal detachCb As Long)
eventTable.pfDeviceAttach = attachCb
eventTable.pfDeviceDetach = detachCb
End Sub

Public Type WDU_EVENT_TABLE
pfDeviceAttach As Long
pfDeviceDetach As Long
pfPowerChange As Long
pUserData As Long
End Type
VB6 declares for callback procedures

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

GalenS
May 2 '06 #3

This discussion thread is closed

Replies have been disabled for this discussion.

Similar topics

99 posts views Thread by Glen Herrmannsfeldt | last post: by
10 posts views Thread by Galen Somerville | last post: by
92 posts views Thread by =?Utf-8?B?bW9iaWxlbW9iaWxl?= | last post: by
15 posts views Thread by Aalaan | last post: by
2 posts views Thread by CptDondo | last post: by
3 posts views Thread by =?Utf-8?B?QmVu?= | last post: by
17 posts views Thread by spasmous | last post: by
reply views Thread by suresh191 | last post: by
4 posts views Thread by guiromero | last post: by
By using this site, you agree to our Privacy Policy and Terms of Use.