- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
我正在使用下面的方法
[DllImport("kernel32.dll", SetLastError=true)]
static extern int GetProcessId(IntPtr hWnd);
尝试获取正在运行的进程的 processId,而我拥有的唯一信息是 HWND。我的问题是它总是返回错误代码 6,即 ERROR_INVALID_HANDLE。我想我可能会将参数更改为 int 类型,但这也没有用。我无法枚举正在运行的进程,因为任何时候可能有超过 1 个实例在运行。
谁能看出我做错了什么?
注意:该进程是从暴露给框架的自动化对象产生的,并且只提供 HWND 属性。也许还有另一种方法可以让进程 ID 看到,因为我编写的代码首先负责运行它?
我的代码看起来与此类似...
AutomationApplication.Application extApp = new AutomationApplication.Application(); extApp.Run(); ...
最佳答案
GetProcessId在给定进程句柄而不是窗口句柄时获取进程 ID。它实际上是:
[DllImport("kernel32", SetLastError = true)]
static extern int GetProcessId(IntPtr hProcess);
如果您有一个窗口句柄,那么您需要 GetWindowThreadProcessId功能:
[DllImport("user32")]
static extern int GetWindowThreadProcessId(IntPtr hWnd, out int processId);
这将返回线程 ID,并将进程 ID 放入输出参数中。
关于c# - 无法从 GetProcessId(.. hWnd) (pInvoke) 中提取进程 ID,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/1283564/
当我执行下面的代码时——: #include #include using namespace std; int main() { cout << GetCurrentProcessId()
我使用 GetProcessID 不小心从应用程序中删除了 Win2K 兼容性. 我这样使用它,以获取已启动应用程序的主要 HWND。 ShellExecuteEx(&info); // Launch
我正在使用下面的方法 [DllImport("kernel32.dll", SetLastError=true)] static extern int GetProcessId(Int
我早些时候发布了一个发送消息问题,我们得出的结论是,从 Xchat 获取聊天窗口非常困难。我现在已经转移到 ThrashIRC 并使用 spy++ 能够找到聊天窗口(突出显示): 如您所见,它确实有一
我在调试 Android 项目时遇到问题。我可以部署到设备并运行它,一切正常,但如果我尝试调试,应用程序将部署到设备并非常短暂地打开,启动画面显示但应用程序随后关闭。 我在 Visual Studio
我是一名优秀的程序员,十分优秀!