| |

VerySource

 Forgot password?
 Register
Search
View: 823|Reply: 7

About BeginThreadex () function, master teach

[Copy link]

3

Threads

4

Posts

5.00

Credits

Newbie

Rank: 1

Credits
5.00

 China

Post time: 2020-3-10 19:00:01
| Show all posts |Read mode
Question (1) In a program of a member function of a class, I have the following statement:

h [0] = (HANDLE) :: _ beginthreadex (NULL, 0, bank_allocation, NULL, 0,&uld);

Where bank_allocation is the name of another member function in the class, which is declared as follows:

UINT __stdcall Cresource :: bank_allocation (LPVOID lpParam);

The compilation error (the error location is where beginThreadex () is used above), the prompt is as follows:
G:\resource\resource.cpp (100): error C2664: '_beginthreadex': cannot convert parameter 3 from 'unsigned int (void *)' to 'unsigned int (__stdcall *) (void *)'
        None of the functions with this name in scope match the target type
The reason for the error is the wrong parameter type. I can't figure it out. I have declared the type of the bank_allocation () function as UINT __stdcall.
(2) How to use beginThreadex to pass parameters to the new thread? For example, to pass an integer variable
Reply

Use magic Report

0

Threads

3

Posts

0.00

Credits

Newbie

Rank: 1

Credits
0.00

 China

Post time: 2020-3-12 09:26:14
| Show all posts
If the thread entry is a member function of the class, it must be defined in the form of static UINT __stdcall ThreadRun (void * p). The function name is arbitrary.
Reply

Use magic Report

0

Threads

1

Posts

2.00

Credits

Newbie

Rank: 1

Credits
2.00

 China

Post time: 2020-6-22 13:45:01
| Show all posts
static unsigned __stdcall bank_allocation(LPVOID);

Declare like this
Reply

Use magic Report

0

Threads

7

Posts

7.00

Credits

Newbie

Rank: 1

Credits
7.00

 China

Post time: 2020-6-24 13:15:01
| Show all posts
The member function has this pointer, so that when the thread is started, the parameters do not match.
So you have to use static member functions
Reply

Use magic Report

0

Threads

7

Posts

7.00

Credits

Newbie

Rank: 1

Credits
7.00

 China

Post time: 2020-6-24 18:45:01
| Show all posts
unsigned long _beginthreadex( void *security, unsigned stack_size, unsigned (__stdcall *start_address )( void * ), void *arglist, unsigned initflag, unsigned *thrdaddr );

arglist is the parameter
Reply

Use magic Report

0

Threads

14

Posts

11.00

Credits

Newbie

Rank: 1

Credits
11.00

 China

Post time: 2020-7-8 19:15:01
| Show all posts
Encountered the same problem, reported an error saying that the parameters did not match, no error after declared static
Reply

Use magic Report

2

Threads

16

Posts

11.00

Credits

Newbie

Rank: 1

Credits
11.00

 China

Post time: 2020-7-14 00:15:01
| Show all posts
Two methods:
Just declare in the file, not in the class
Use static
Reply

Use magic Report

3

Threads

4

Posts

5.00

Credits

Newbie

Rank: 1

Credits
5.00

 China

 Author| Post time: 2020-7-16 12:00:01
| Show all posts
static unsigned __stdcall bank_allocation(LPVOID);
Isn't it possible to declare it like this, is it not necessary to add a class reference to the parameters of static function members? Which is the following
static unsigned __stdcall bank_allocation(LPVOID, Cresource&);
But after making this modification, the compilation still made mistakes, (there is no mistake), the prompt is as follows:
c:\documents and settings\h\Desktop\resource\resource.cpp(152): error C2664:'_beginthreadex': cannot convert parameter 3 from'unsigned int (void *,class Cresource&)' to'unsigned int (__stdcall *)(void *)'
Reply

Use magic Report

You have to log in before you can reply Login | Register

Points Rules

Contact us|Archive|Mobile|CopyRight © 2008-2023|verysource.com ( 京ICP备17048824号-1 )

Quick Reply To Top Return to the list