在VB.Net中传递函数指针 [英] Passing function pointer in VB.Net
问题描述
来自C / C ++背景,我如何将函数指针传递给
函数?我想编写一个处理某些线程产生的函数。
这就是我想要的东西:
函数(thesub as< ; functionptr?>)
dim t as new system.threading.thread(_
new system.threading.threadstart(Addressof thesub))
....
如何在VB.Net中获得类似内容?
< blockquote>使用委托。代表相当于.NET中的函数指针。
问候,
Ron
" ChrisB" <章**** @ discussions.microsoft.com>在消息中写道
news:87 ********************************** @ microsof t.com ...
来自C / C ++背景,我如何将函数指针传递给
函数?我想写一个处理某些线程产生的函数。
这就是我想要的东西:
函数(thesub as< functionptr?>)
new system.threading.threadstart(Addressof thesub))
我怎么能得到这样的东西进入VB.Net?
" Ron Bremmers" < R ******** @ home.nl>。 schrieb:使用委托。委托相当于.NET中的函数指针。
文档:
Visual Basic语言概念 - 事件和代表
< URL:http://msdn.microsoft.com/library/en-us/vbcn7/html/vaconEventsDelegatesInheritance.asp>
-
MS Herfried K. Wagner
MVP< URL:http://dotnet.mvps.org/>
VB< URL :http://dotnet.mvps.org/dotnet/faqs/>
我尝试使用代表,但我不知道如何。我试过这样的事情:
委托函数fpMyfunc()
(我也尝试过委托子fpMyfunc())
然后:
函数(thesub as fpMyfunc)
dim t as new system.threading.thread(_
new system.threading .threadstart(thesof thesub))
但这不起作用。 VB.Net抱怨thesub在
地址之后..说我不需要()在子名后面,好像它确实
不能识别thesub作为一个子程序。
" Ron Bremmers"写道:
使用委托。代表相当于.NET中的函数指针。
问候,
Ron
" ChrisB" <章**** @ discussions.microsoft.com>在消息中写道
新闻:87 ********************************** @ microsof t.com。 ..来自C / C ++背景,我如何将函数指针传递给
函数?我想写一个处理某些线程产生的函数。
这就是我想要的东西:
函数(thesub as< functionptr?>)
new system.threading.threadstart(Addressof thesub))
我怎么能得到这样的东西进入VB.Net?
Coming from a C/C++ background, how would I pass a function pointer to a
function? I want to write a function that handles certain thread spawning.
Here''s what I''m trying to invision:
function( thesub as <functionptr?> )
dim t as new system.threading.thread( _
new system.threading.threadstart( Addressof thesub ))
....
How can I get something like that going in VB.Net?
Use delegates. Delegates are the equivalent of function pointers in .NET.
Regards,
Ron
"ChrisB" <Ch****@discussions.microsoft.com> wrote in message
news:87**********************************@microsof t.com...Coming from a C/C++ background, how would I pass a function pointer to a
function? I want to write a function that handles certain thread spawning.
Here''s what I''m trying to invision:
function( thesub as <functionptr?> )
dim t as new system.threading.thread( _
new system.threading.threadstart( Addressof thesub ))
...
How can I get something like that going in VB.Net?
"Ron Bremmers" <r.********@home.nl> schrieb:Use delegates. Delegates are the equivalent of function pointers in .NET.
Documentation:
Visual Basic Language Concepts -- Events and Delegates
<URL:http://msdn.microsoft.com/library/en-us/vbcn7/html/vaconEventsDelegatesInheritance.asp>
--
M S Herfried K. Wagner
M V P <URL:http://dotnet.mvps.org/>
V B <URL:http://dotnet.mvps.org/dotnet/faqs/>
I tried using delegates but I don''t know how. I tried something like this:
delegate function fpMyfunc()
(I also tried delegate sub fpMyfunc())
Then:
function( thesub as fpMyfunc )
dim t as new system.threading.thread( _
new system.threading.threadstart( Addressof thesub ))
But this did not work. VB.Net complained about the "thesub" after the
Addressof.. saying that I do not need ()''s after the sub name, as if it did
not recognize "thesub" as being a subroutine.
"Ron Bremmers" wrote:
Use delegates. Delegates are the equivalent of function pointers in .NET.
Regards,
Ron
"ChrisB" <Ch****@discussions.microsoft.com> wrote in message
news:87**********************************@microsof t.com...Coming from a C/C++ background, how would I pass a function pointer to a
function? I want to write a function that handles certain thread spawning.
Here''s what I''m trying to invision:
function( thesub as <functionptr?> )
dim t as new system.threading.thread( _
new system.threading.threadstart( Addressof thesub ))
...
How can I get something like that going in VB.Net?
这篇关于在VB.Net中传递函数指针的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!