pass pointer to a thread function ?

M

mandatory

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 !
 
V

Victor Bazarov

mandatory said:
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 ?

Not if the class function is a non-static member. See the FAQ, section 33.

V
 
M

mandatory

"Victor Bazarov"
Not if the class function is a non-static member. See the FAQ, section
33.

V


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.
 
V

Victor Bazarov

mandatory said:
"Victor Bazarov"
Not if the class function is a non-static member. See the FAQ, section
33.

V


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.

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
 

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

Members online

No members online now.

Forum statistics

Threads
474,202
Messages
2,571,057
Members
47,660
Latest member
vidotip479

Latest Threads

Top