creating threads in VC++ is simple and fast.
first of all, you need a HANDLE, you will use this HANDLE to "handle" the thread,
just like the way you "handle" a file, a socket, a device, etc.
If you don't care about the thread_id, you can use NULL instead.
At last, the thread function must be this prototype:
return value DWORD, one parameter, type: LPVOID
if the function is in a class, the function need to be a static one, however, there is a workaround, talk about it later.
an example thread function
this way, you have created a thread, and the thread is executing the function_name function with the argument you provided
in the function "function_argument". the thread_id will be the thread id of the created thread.
OK, what if you want to use a member function inside a class?
if you want to execute a member function, you can do this, it is a little tricker, but in fact, it is very easy to use, don't be scared by these at first,
these are called template, it is a very power tool in C++, however, you don't need to worry about these at all for now, all you need to do is, copy and paste these fuzzy code to somewhere in your code, but donot paste them into a class :)
I never tried these...in face, this template was stealed from a bbs, thx him for the sharing, it's very helpful
and, when you want to use a member function to create a thread, do this:
Let's say the class name is MyClass, and the object is myObj, if the call is inside another member function of MyClass,
you can also use "this" as the object reference.
of course, the a_function also need to be match the thread function prototype, such as
This is almost everything about threading in Windows.
(OK. I'm lying...there ARE much MORE:D, and do threading right is very HARD.)
Go threading, but don't go too far for now. 你懂的
cheer up.