-2
HANDLE hThread = CreateThread(NULL, 0, ManageThread, (LPVOID)lParam, 0, NULL);
WaitForSingleObject(hThread, INFINITE);

How can I pass serveral HANDLE param via lParam?

I have to use serveral HANDLE variable on hThread.

DWORD WINAPI ManageThread(LPVOID lParam)
{
    HANDLE hPingpong = ...; //From lParam;
    HANDLE hVolley = ...; //From lParam;
    ...
    HANDLE hBasket = ...; //From lParam;
    ...

    return GetLastError();
}

I would appreciate it if you could help me generate lParam.

Bryant
  • 324
  • 2
  • 15
  • 2
    Use a structure or an array. Note that [WaitForMultipleObjects](https://msdn.microsoft.com/en-us/library/windows/desktop/ms687025(v=vs.85).aspx) requires an array of handles, if you ever plan on using it. – rcgldr Jul 11 '17 at 14:24
  • Dear rcgldr, Can you explain it in detail? I have to pass serveral parameters via only one thread function. – Bryant Jul 11 '17 at 14:27
  • As an example of using an array, say you create an array of handles named aHandle. Then for each handle, use a define: | #define hPingpong aHandle[0] | #define hVolley aHandle[1] | ... . Set lParam = aHandle when creating the thread. – rcgldr Jul 11 '17 at 14:31
  • Sorry, you didn't understand my question. If that case I cannot use serveral parameter at same time. I had misunderstood before it, but now you explained me wrong way. I can not do what you say. Thank you for your kindness rcgldr. – Bryant Jul 11 '17 at 14:40
  • Create an array, and pass it via `lParam`. – David Heffernan Jul 11 '17 at 14:52
  • I found a way to send several parameters. Make structure contains several types of parameters. Thank you David Heffernan. – Bryant Jul 11 '17 at 15:16
  • Downvoted. Reason: Lack of research. This question has been asked a bazillion times already, and has been sufficiently answered. Pick a duplicate you like. – IInspectable Jul 11 '17 at 15:43

1 Answers1

0

I found the best way to pass serveral paramters to single thread.

Using Structure : )

structure PARAM_PAIR {
    HANDLE hVolley;
    HANDLE hSoccer;
    ...
    DWORD dwVolleyScore;
    DWORD dwSoccerSocre;
}

PARAM_PAIR* param_pair;
param_pair = new PARAM_PAIR;

HANDLE hThread = CreateThread(NULL, 0, ManageThread, param_pair, 0, NULL);
WaitForSingleObject(hThread, INFINITE);

Thank you for all answered. Bryant

Bryant
  • 324
  • 2
  • 15