You can use GetProcessIdOfThread api for newer versions of windows.
For older versions you have to find it manually using the ToolHelp library functions Thread32First/Thread32Next searching for the threadid and getting the process id from the THREADENTRY32 structure.