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

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 5934
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 thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

3
by: Andy Read | last post by:
Dear all, I thought I understood passing parameters ByVal and ByRef but I clearly don't! If I define a simple class of: Public Class Person Public Name as String Public Age as Integer End...
58
by: jr | last post by:
Sorry for this very dumb question, but I've clearly got a long way to go! Can someone please help me pass an array into a function. Here's a starting point. void TheMainFunc() { // Body of...
8
by: kalinga1234 | last post by:
there is a problem regarding passing array of characters to another function(without using structures,pointer etc,).can anybody help me to solve the problem.
6
by: keepyourstupidspam | last post by:
Hi, I want to pass a function pointer that is a class member. This is the fn I want to pass the function pointer into: int Scheduler::Add(const unsigned long timeout, void* pFunction, void*...
17
by: Charles Sullivan | last post by:
The library function 'qsort' is declared thus: void qsort(void *base, size_t nmemb, size_t size, int(*compar)(const void *, const void *)); If in my code I write: int cmp_fcn(...); int...
17
by: Christopher Benson-Manica | last post by:
Does the following program exhibit undefined behavior? Specifically, does passing a struct by value cause undefined behavior if that struct has as a member a pointer that has been passed to...
12
by: Mike | last post by:
Consider the following code: """ struct person { char *name; int age; }; typedef struct person* StructType;
6
by: Roman Mashak | last post by:
Hello, I belive the reason of problem is simple, but can't figure out. This is piece of code: struct timeval { long tv_sec; /* seconds */ long tv_usec; /* microseconds */ };
8
by: Ivan Liu | last post by:
Hi, I'd like to ask if passing an object as an pointer into a function evokes the copy constructor. Ivan
7
by: TS | last post by:
I was under the assumption that if you pass an object as a param to a method and inside that method this object is changed, the object will stay changed when returned from the method because the...
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
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
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
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: 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: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
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.