my $pid_raw_value = "\x0" x Win32::API::Type->sizeof("LPDWORD"); GetWindowThreadProcessId($hwnd, $pid_raw_value); my $window_pid = Win32::API::Type::Unpack("LPDWORD", $pid_raw_value);