Passing function pointer from VB .NET to C dll

K

kevin

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?
 
K

Ken Tucker [MVP]

Hi,

Use a delegate.
http://msdn.microsoft.com/library/d.../cpguide/html/cpconusingcallbackfunctions.asp

Ken
-----------------
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?
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top