a bare minimum of what you need to use threads in VC++. Threads allow your program to do multiple things at the same time (multithreading) instead of in a linear sequence. For instance, you could have your program doing an infinately looped complex task and at the same time be waiting for the user to enter a 'stop' key. Using multithreading, the user could press the 'stop' key at _any_ time to stop the program.

Step 1: #including the Propper Stuff

even if you have already started an app as a non MFC console application, you can use threads in your app.

1) First, go into setting and set it so that it uses MFC as a static library

2) Then add #include below the #include "stdafx" that should already be in your program

3) meanwhile, if you have
#include "windows.h" or #include "mmsystem.h"
put these two _above_ the #include "stdafx.h"

4) Be careful, the order in which you declare the #includes matters a lot!! (if the way you have it gives errors during compile, reorder them til it works).
Your "TempChar" is actually a pointer to void (or void *). This can carry anything to your thread, it could be nothing as you suggest, or a pointer to an XML string, or an array of structures... anything. This parameter is there so that you can communicate to your thread, it could be data that it should operate on or information about how to get to syncronization objects so that the rest of your program can signal it, or anything else that you need to provide to the thread for its execution. The TempChar is what is passed to your thread in that LPVOID pParam (LPVOID is the same as void *).
ohhhh, cool. I just communicate with the thread via global variables :P I don't write huge commercially viable programs, just smallish ones for research, so don't yell at me for using globals :)

About This Instructable




Bio: www.leevonk.com
More by leevonk:WolfPack: Large-Dog Carrier Vortex-Drive Micro ROV (ROVVor) Squintasaurus: cybernetic dynamically adjustable vision enhancement system 
Add instructable to: