Solve a compilation error created by a thread in MFC

Source: Internet
Author: User

Error message: Error c2665: 'afxbeginthread': none of the 2 overloads can convert parameter 1 from type 'unsigned int (void *)'

 

Today, I used winsdk to write a thread in the company. When I came back, I wanted to write it using some encapsulation classes of MFC. I found it was really simple and many parameters were not used.

Use afxbeginthread to create a thread pointer, that is, cwinthread * thread.

 

Let's take a look at the Code:

 

Cwinthread * thread;

Thread = afxbeginthread (threadcallfunc, (lpvoid) This );

 

Because threadcallfunc is a callback function of a thread, I use Class Wizard to add a member function to the View class,

The generated function is

 

Uint cvedioview: threadcallfunc (lpvoid pparam)
{
Return 0;
}

 

After compilation, the following error occurs: Error c2665: 'afxbeginthread': none of the 2 overloads can convert parameter 1 from type 'unsigned int (void *)'

 

Google many times said that the callback function must be static. The final problem is that you should not use Class Wizard to add member functions to the View class, but add a function in CPP, that is:

Uint threadcallfunc (lpvoid pparam)

{

Return 0;

}

That's all.

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.