473,498 Members | 1,828 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

how do i create a thread with a class function?

The code below creates a thread on a global function (ReadChildOutput):

CreateThread(NULL, 0, ReadChildOutput, (LPVOID)this, 0, &ThreadId);

How would I create a thread on a non-global function, assuming the
ReadChildOutput function were in the current class. This code illustrates
what I mean, but does not compile.

CreateThread(NULL, 0, this->ReadChildOutput, NULL, 0, &ThreadId);

Thanks,
Chris
Nov 16 '05 #1
2 1884
Chris LaJoie wrote:
The code below creates a thread on a global function
(ReadChildOutput):

CreateThread(NULL, 0, ReadChildOutput, (LPVOID)this, 0, &ThreadId);

How would I create a thread on a non-global function, assuming the
ReadChildOutput function were in the current class. This code
illustrates what I mean, but does not compile.

CreateThread(NULL, 0, this->ReadChildOutput, NULL, 0, &ThreadId);

Thanks,
Chris


You have to use a "global" helper function. Pass the 'this' pointer as the
LPINFO parameter to CreateThread, and the address of the static function as
the start address. In the static function, cast the void* info into
CYourClass* and call the member function. From your example above, it looks
like you're already doing that.

-cd
Nov 16 '05 #2
Chris LaJoie wrote:
The code below creates a thread on a global function (ReadChildOutput):

CreateThread(NULL, 0, ReadChildOutput, (LPVOID)this, 0, &ThreadId);

How would I create a thread on a non-global function, assuming the
ReadChildOutput function were in the current class. This code illustrates
what I mean, but does not compile.

CreateThread(NULL, 0, this->ReadChildOutput, NULL, 0, &ThreadId);

Chris

Briefly, the problem is that all class instance functions have an
implicit "this" as a first (hidden) argument. Thus it simply won't
compile or be the right shape!

/steveA

--
my email Fg**********@vqk.pbz is encrypted with ROT13 (www.rot13.org)

Nov 16 '05 #3

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

1
2519
by: Daylor | last post by:
can i do it this way : from the defualt AppDomain : create thread. from the start function of the new thread , create new AppDomain,and then create my class through the AppDomain . this way...
5
3593
by: me | last post by:
I have a Class Library that contains a Form and several helper classes. A thread gets created that performs processing of data behind the scenes and the Form never gets displayed (it is for debug...
0
1493
by: me | last post by:
I have a Class Library that contains a Form and several helper classes. A thread gets created that performs processing of data behind the scenes and the Form never gets displayed (it is for debug...
2
3171
by: Bill Nguyen | last post by:
How can I create a shared function to display process progress that can be called from other routines within an application? Any example that I can follow? Thanks Bill
4
1539
by: Daylor | last post by:
hi. i have multi thread application in vb.net is there a way NET support, so i can mark the class , to be access only for 1 thread each time ? if there is , small sytax sample will help ...
3
3653
by: Lonewolf | last post by:
Hi all, I'm having difficulties passing data back to managed class from my native class when the data is generated from within a native thread in the native class itself. I will give the following...
4
1596
by: Lee Moore | last post by:
I am trying to develop a threaded function to create a dataset from an Oracle database. When querying an elaborate view, queries take a while. I would like to place and animated wait dialog up...
5
1619
by: fniles | last post by:
I am having problem with thread. I have a Session class with public string variable (called Message) that I set from my Main program. In the session class it checks for the value of Message...
23
7364
by: sandy | last post by:
I need (okay, I want) to make a dynamic array of my class 'Directory', within my class Directory (Can you already smell disaster?) Each Directory can have subdirectories so I thought to put these...
0
7005
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
7168
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
1
6891
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
7381
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
5465
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
0
4595
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and...
0
3096
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The...
0
1424
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated ...
1
659
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

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.