In this article, we will detail the specific application of the C ++ CreateThread parameter to help you get some help and improve programming efficiency. Next let's take a look at the correct use of the C ++ CreateThread parameter.
The project is under VS2003, And the CreateThread function is used. It indicates that CreateThread should not be called on the Internet, but _ beginthreadex should be used. Because it is used, write the usage of parameters in CreateThread.
First, define the structure of the C ++ CreateThread parameter to be passed:
- Typedef struct SParam
- {
- Int No;
- Unsigned short chnlID;
- Unsigned short sessionID;
- } UParam, * sParam;
- Dword winapi AccountManager (PVOID pParam );
- Void main ()
- {
- DWORD dwThreadId;
- HANDLE hThrd = NULL; // thread handle
- SParam sparam;
- SParam * p;
- Sparam. No = 1;
- Sparam. chnlID = 1;
- Sparam. sessionID = 1;
- P = & sparam;
- HThrd = (HANDLE) CreateThread (NULL,
- 0,
- AccountManager,
- P,
- 0,
- DwThreadId;
- }
- Dword winapi AccountManager (PVOID pParam)
- {
- SParam sparam;
- Sparam = (sParam) pParam;
- Try
- {
- /* Run is a self-written method. Run (int I, unsigned short
ChnlID, unsigned short sessionID )*/
- Run (sparam-> No, sparam-> chnlID, sparam-> sessionID );
- }
- Catch (...)
- {
- Logger. error ("AccountManager (% d): System error. \ r \ n", threadId );
- }
- }
In general, the C ++ CreateThread parameter code is for reference only.