Passing Windows C ++ Stream Parameters

In Windows C ++, the following creates a stream:

CreateThread(NULL, NULL, function, parameter, NULL, &threadID); 

This will launch the “function” in the new thread and pass the “parameter” as void * or LPVOID.

Suppose I want to pass two parameters to a “function”, is there a better way to do this, besides creating a data structure containing two variables, and then casting the data structure as an LPVOID?

+4
source share
3 answers

No, this is the only way. Just create a structure with two data members and pass it as void *

+11
source

This is the standard way to pass a parameter to a stream, but your new cann stream can access any memory in the process, so something that is difficult to transfer, or you can access a lot of data as a shared resource, as long as you provide the appropriate synchronization control .

0
source

I think there is a much better way, and I use it all the time in inline code. It actually grew out of a desire to pass a member method to a function that is very similar to CreateThread (). The reason why this was desired was because the class already had all the parameters necessary for the stream code as a data element (with the corresponding setters). I wrote a more detailed explanation that you can refer to if you are interested. In the entry where you see OSTaskCreate (), just mentally replace CreateMethod ().

0
source

Source: https://habr.com/ru/post/1347965/


All Articles