473,407 Members | 2,315 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,407 software developers and data experts.

CreateThread in Windows

This must be an easy question.

I am trying to create a thread in windows. I am using C as my language.

I am trying to pass a function to the CreateThread function to create a thread. My function has a return type void and paratmeter is void as well. How do I approach this?

Is it something like this?

static void run() {
myThread = CreateThread(
NULL,
0,
MyFunction,
NULL,
0,
NULL);
}

How do I pass my function to CreateThread?

What is this DWORD WINAPI functionName () that I am reading about? Do I need this function?

Thanks in advance,
Sevak.
Oct 1 '08 #1
3 7169
Laharl
849 Expert 512MB
The function you pass to CreateThread must return a DWORD and be defined with the WINAPI keyword. For example,
Expand|Select|Wrap|Line Numbers
  1. DWORD WINAPI run(void* arg); //LPVOID would be more "Windows", not that I really care
Oct 1 '08 #2
sorry, but im confused. I have been lookin at code ALL day!

who ends up calling my funtion and how??
lets say my function is "void xTaskFast(void)"
Oct 1 '08 #3
Laharl
849 Expert 512MB
Then you call CreateThread as follows:

Expand|Select|Wrap|Line Numbers
  1. DWORD tid;
  2. HANDLE h = CreateThread(NULL, 0, xFastTask, 0, &tid); //check h to see if it succeeded or not
  3.  
Source: MSDN

The spawned thread, if the call is successful, will be created and will start execution at the beginning of the function passed in the third parameter. The thread that called CreateThread will continue from the next line (this should be error checking).
Oct 1 '08 #4

Sign in to post your reply or Sign up for a free account.

Similar topics

3
by: lamilla | last post by:
Salve a tutti, sto creando una applicazione che istanzia un thread al quale viene passato come argomento il puntatore ad una classe che contiene molte funzioni alcune delle quali devono essere...
1
by: phark52 | last post by:
My main app calls LoadLibrary() to load a DLL, which calls CreateThread(). This does NOT return NULL and I get a thread ID. However, ThreadProc never gets executed when this code is in the DLL. It...
5
by: Vinayak Raghuvamshi | last post by:
Threads created using the CreateThread API used to leak memory if you accesed any crt methods within the thread proc. we used to use _beginthread to work around this issue. Does anyone know if...
3
by: raj | last post by:
Hi, I just want to know the difference between thread created by CreateThread and AfxBeginThread function. I got one problem when using the CreateThread. The appliction malfunction while using the...
3
by: mccanaveras | last post by:
Hello, I need to implement a Thread in a Visual C++ 6.0 application. I've never done this, then I've been investigating, but I don't have any properly solution. One of them is use CWinThread...
0
by: liamacheung | last post by:
Hi, I am designing a GUI application using a VC++ 2005 Form template. I have created a thread function external to the class containing the form. I can successfully create the thread and run...
5
by: eagerlearner | last post by:
Hallo, when I use class and I put one of the member function as the CreateThread argument, I keep getting the compile error in Visual Studio 2005. #include <windows.h> class X { public:...
1
by: tobycraftse | last post by:
I heard I should use the C function - CreateThread() to create thread. I have a graphics program that draws some animations. How can I add another thread to do other stuff like file processing...
17
by: Daniel | last post by:
When I use the CreateThread API method, what do I need to do when I want to pass more than one parameter where LPVOID lpParameter is passed? Daniel
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?
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...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
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
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
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
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...

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.