How to Use AfxBeginThread in C ++ Part8 MFC (Code instance ),

Source: Internet
Author: User

How to Use AfxBeginThread in C ++ Part8 MFC (Code instance ),
How to Use AfxBeginThread in C ++ Part8 MFC (code example)

1. The AfxBeginThread parameter.

// Multi-threaded function definition; UINT Thread1 (int pParam) {int nSize = pParam; // your other processing code... Return 0;} // use of multiple threads; int nSize = 50; AfxBeginThread (AFX_THREADPROC) Thread1, (VOID *) nSize, THREAD_PRIORITY_NORMAL, 0, 0, NULL );

AfxBeginThread. If you want to pass multiple parameters or input struct

// Define a global struct; typedef struct SthData {int iStr; int iEnd;} * pSthData; // multithreading function definition; VOID Thread1 (LPVOID lpParam) {// obtain the value in the struct; SthData * pStcSthData = (SthData *) lpParam; int iStr = pStcSthData-> iStr; int iEnd = pStcSthData-> iEnd; // your other processing code... // Remember to delete the pointer of the struct and point to NULL; delete pStcSthData; pStcSthData = NULL;} // use of multiple threads; pSthData pDataValue1 = new SthData; memset (pDataValue1, 0x00, sizeof (SthData); pDataValue1-> iStr = 0; pDataValue1-> iEnd = 10; AfxBeginThread (AFX_THREADPROC) Thread1, pDataValue1, success, 0, 0, NULL );

Note: After the struct is created, you need:

Delete pDataValue1; pDataValue1 = NULL; // prevents wild pointers

Otherwise, the internal data of the struct is garbled during debugging.

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.