How to parse the C ++ CreateThread Parameter

Source: Internet
Author: User

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:

 
 
  1. Typedef struct SParam
  2. {
  3. Int No;
  4. Unsigned short chnlID;
  5. Unsigned short sessionID;
  6. } UParam, * sParam;
  7. Dword winapi AccountManager (PVOID pParam );
  8. Void main ()
  9. {
  10. DWORD dwThreadId;
  11. HANDLE hThrd = NULL; // thread handle
  12. SParam sparam;
  13. SParam * p;
  14. Sparam. No = 1;
  15. Sparam. chnlID = 1;
  16. Sparam. sessionID = 1;
  17. P = & sparam;
  18. HThrd = (HANDLE) CreateThread (NULL,
  19. 0,
  20. AccountManager,
  21. P,
  22. 0,
  23. DwThreadId;
  24. }
  25. Dword winapi AccountManager (PVOID pParam)
  26. {
  27. SParam sparam;
  28. Sparam = (sParam) pParam;
  29. Try
  30. {
  31. /* Run is a self-written method. Run (int I, unsigned short
    ChnlID, unsigned short sessionID )*/
  32. Run (sparam-> No, sparam-> chnlID, sparam-> sessionID );
  33. }
  34. Catch (...)
  35. {
  36. Logger. error ("AccountManager (% d): System error. \ r \ n", threadId );
  37. }
  38. }

In general, the C ++ CreateThread parameter code is for reference only.

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.