views:

52

answers:

1

In PostThreadMessage my thread ID is correct, but I am getting the error 1444 ("Invalid thread identifier. ").

Anyone know how to fix it?

+1  A: 

The OS is the authority on whether thread IDs are valid, so if it's telling you your ID is invalid, then your ID is probably invalid. You have to trust the error codes until you can prove they're wrong, or else there's no use checking them at all. Before blaming the OS, make sure you've ruled out all other possibilities. Here are some examples:

  • Maybe you used the thread handle instead.
  • Maybe the thread has finished running already.
  • Maybe the thread wasn't created successfully in the first place. Make sure you check the return value from CreateThread.
  • Maybe the thread belongs to a process running on a different desktop.
  • Maybe the thread doesn't have a message queue. A thread can create a message queue for itself by calling GetMessage or PeekMessage, for example.
Rob Kennedy
Ya i have used getmessage now .....its working now
SPB
By the way, I got those last two failure reasons by reading the [documentation for `PostThreadMessage`](http://msdn.microsoft.com/en-us/library/ms644946.aspx); it mentions `ERROR_INVALID_THREAD_ID` all over the place.
Rob Kennedy