为什么有时GetWindowThreadProcessId返回0

为什么有时GetWindowThreadProcessId返回0

本文介绍了为什么有时GetWindowThreadProcessId返回0?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用远程调用在目标地址空间中注入.NET SpyLib.我需要向通过 GetWindowThreadProcessId 创建该远程进程的窗口线程发送消息.

I am injecting a .NET SpyLib in the target address space using remote invocation. I need to send a message to that window's thread which created that remote process via GetWindowThreadProcessId.

我在Windows 7上工作.不幸的是,大多数情况下它返回0.有时,它会提供适当的线程ID(在重新启动Windows之后).

I am working on Windows 7. Unfortunately it returns 0 most of the time. Sometimes it gives the appropriate thread id (after restarting Windows).

为什么用 GetWindowThreadProcessId 会出现这种奇怪的行为?

Why am I getting this strange behavior with GetWindowThreadProcessId?

推荐答案

GetWindowThreadProcessId 有一个社区内容"部分,其中DDeBen在问您问题的两年之前就已经回答了您的问题.:)

The MSDN documentation for GetWindowThreadProcessId has a Community Content section, in which DDeBen has already answered your questions two years before you even asked your question. :)

将来可能需要记住,当不确定不确定的故障状态时, GetLastError()通常是Win32 API中需要使用的功能.MSDN通常会提供指向它的链接,但是即使不提供链接,将其签出也不会对您造成伤害.但是,请注意,在托管代码中, GetLastError()需要特殊待遇,否则您最终将得到虚假结果,只会使您感到困惑.

In the future it might help to remember that GetLastError() is often the function you need to go to in the Win32 API when you have failure states you are unsure of. MSDN will generally give a link to it, but even if it does not, it can't hurt to check it out. However, be aware that in managed code GetLastError() requires special treatment or you will end up with bogus results that will only end up confusing you.

这篇关于为什么有时GetWindowThreadProcessId返回0?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

08-24 09:02