Connecting Tech Pros Worldwide Help | Site Map

pass pointer to a thread function ?

mandatory
Guest
 
Posts: n/a
#1: Jul 23 '05
hi,

i would like to pass a pointer to a thread function to a class.

The function in my code that i would like to get the address of, and pass it
to a class function is:

DWORD ServiceExecution(LPDWORD param)

And i would like to somehow send the address to a class function, similar to
this:

MyClass.ServiceExe (ServiceExecution):

Can this be done ? i have abit troubles getting it working - i remember that
i in the early years in normal C could do this fairly easy - but it has
really slipped my mind how the syntax is, and if its possible at all...

hope you can help !




Victor Bazarov
Guest
 
Posts: n/a
#2: Jul 23 '05

re: pass pointer to a thread function ?


"mandatory" <okllsam@nptklooohs.ru> wrote...[color=blue]
> i would like to pass a pointer to a thread function to a class.
>
> The function in my code that i would like to get the address of, and pass
> it to a class function is:
>
> DWORD ServiceExecution(LPDWORD param)
>
> And i would like to somehow send the address to a class function, similar
> to this:
>
> MyClass.ServiceExe (ServiceExecution):
>
> Can this be done ?[/color]

Not if the class function is a non-static member. See the FAQ, section 33.
[color=blue]
> [..][/color]

V


mandatory
Guest
 
Posts: n/a
#3: Jul 23 '05

re: pass pointer to a thread function ?


"Victor Bazarov"[color=blue]
>
> Not if the class function is a non-static member. See the FAQ, section
> 33.
>[color=green]
>> [..][/color]
>
> V[/color]


hi victor !

thanks, but im not completely sure, but i think you might have misunderstood
me.

My goal isnt to start a memberfunction as a thread, im fully aware that this
has to be a static function outside the class (and then there are some ways
of make it "feel" its inside the class).

My goal is merely to pass on a address of a (static/global) function to a
class-member-function - like GetProcAddress() but just not from a library.


Victor Bazarov
Guest
 
Posts: n/a
#4: Jul 23 '05

re: pass pointer to a thread function ?


"mandatory" <okllsam@nptklooohs.ru> wrote...[color=blue]
> "Victor Bazarov"[color=green]
>>
>> Not if the class function is a non-static member. See the FAQ, section
>> 33.
>>[color=darkred]
>>> [..][/color]
>>
>> V[/color]
>
>
> hi victor !
>
> thanks, but im not completely sure, but i think you might have
> misunderstood me.
>
> My goal isnt to start a memberfunction as a thread, im fully aware that
> this has to be a static function outside the class (and then there are
> some ways of make it "feel" its inside the class).
>
> My goal is merely to pass on a address of a (static/global) function to a
> class-member-function - like GetProcAddress() but just not from a library.[/color]

OK, I probably did misunderstand you. What problem do you have, then?

Your member function has to accept a pointer to a function as its argument
and when you pass it a function, it decays to a pointer to that function,
and everything is peachy.

If section 33 doesn't apply to your problem (which I admit is likely),
then you need to give FAQ 5.8 a try.

V


Closed Thread