468,310 Members | 1,418 Online
Bytes | Developer Community
New Post

Home Posts Topics Members FAQ

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

Passing function pointer from VB .NET to C dll

This is a repost with an update

Does any one know how to pass a function pointer as a function parameter
from VB .NET to a C dll?

Currently I'm passing it this way

Public Delegate Sub DSCUserInterruptFunction()

Public Declare Function dscUserInt Lib "dscud.dll" (ByVal board As Short,
ByRef dscuserint As dscUserInt, <MarshalAs(UnmanagedType.FunctionPtr)> ByRef
functions As DSCUserInterruptFunction) As Byte

Public Sub count()

dscUserInt(board, dscuserint, AddressOf count)

But this isn't working. My program just crashes and exits. Any ideas?
Thanks.
--
Kevin Liu
Nov 21 '05 #1
3 5509
Try the AddressOf()
it might work ;)

"kevin" <z2****@yahoo.com> wrote in message
news:eY**************@tk2msftngp13.phx.gbl...
This is a repost with an update

Does any one know how to pass a function pointer as a function parameter
from VB .NET to a C dll?

Currently I'm passing it this way

Public Delegate Sub DSCUserInterruptFunction()

Public Declare Function dscUserInt Lib "dscud.dll" (ByVal board As Short,
ByRef dscuserint As dscUserInt, <MarshalAs(UnmanagedType.FunctionPtr)>
ByRef
functions As DSCUserInterruptFunction) As Byte

Public Sub count()

dscUserInt(board, dscuserint, AddressOf count)

But this isn't working. My program just crashes and exits. Any ideas?
Thanks.
--
Kevin Liu

Nov 21 '05 #2
Thanks, I'm one step closer!

--
Kevin Liu
"Bishoy Ghaly" <de************@yahoo.co.uk> wrote in message
news:%2******************@TK2MSFTNGP10.phx.gbl...
Try the AddressOf()
it might work ;)

"kevin" <z2****@yahoo.com> wrote in message
news:eY**************@tk2msftngp13.phx.gbl...
This is a repost with an update

Does any one know how to pass a function pointer as a function parameter
from VB .NET to a C dll?

Currently I'm passing it this way

Public Delegate Sub DSCUserInterruptFunction()

Public Declare Function dscUserInt Lib "dscud.dll" (ByVal board As Short, ByRef dscuserint As dscUserInt, <MarshalAs(UnmanagedType.FunctionPtr)>
ByRef
functions As DSCUserInterruptFunction) As Byte

Public Sub count()

dscUserInt(board, dscuserint, AddressOf count)

But this isn't working. My program just crashes and exits. Any ideas?
Thanks.
--
Kevin Liu


Nov 21 '05 #3
Another related question

How do I keep the garbage collector from collecting the AddressOf count or
my funct variable below?

dim func as DSCUserIntFunction

func = AddressOf count

Thanks
--
Kevin Liu
"kevin" <z2****@yahoo.com> wrote in message
news:eY**************@tk2msftngp13.phx.gbl...
This is a repost with an update

Does any one know how to pass a function pointer as a function parameter
from VB .NET to a C dll?

Currently I'm passing it this way

Public Delegate Sub DSCUserInterruptFunction()

Public Declare Function dscUserInt Lib "dscud.dll" (ByVal board As Short,
ByRef dscuserint As dscUserInt, <MarshalAs(UnmanagedType.FunctionPtr)> ByRef functions As DSCUserInterruptFunction) As Byte

Public Sub count()

dscUserInt(board, dscuserint, AddressOf count)

But this isn't working. My program just crashes and exits. Any ideas?
Thanks.
--
Kevin Liu

Nov 21 '05 #4

This discussion thread is closed

Replies have been disabled for this discussion.

Similar topics

3 posts views Thread by Andy Read | last post: by
8 posts views Thread by kalinga1234 | last post: by
6 posts views Thread by keepyourstupidspam | last post: by
17 posts views Thread by Charles Sullivan | last post: by
17 posts views Thread by Christopher Benson-Manica | last post: by
12 posts views Thread by Mike | last post: by
6 posts views Thread by Roman Mashak | last post: by
8 posts views Thread by Ivan Liu | last post: by
reply views Thread by NPC403 | last post: by
reply views Thread by Teichintx | last post: by
By using this site, you agree to our Privacy Policy and Terms of Use.