在一个上钩的过程为什么Control.FromHandle(IntPtr的)返回null,返回&QUOT有效的对象,形式及QUOT;?在另一种上瘾的过程?过程、上瘾、形式、对象

2023-09-03 16:48:08 作者:平你眉间川

我面临着与走出一些迷上过程中的所有控件的一个问题。我SpyDll射入上钩过程中成功地,但是当我检查语句

I am facing a problem related to get out all the controls from some hooked process. My SpyDll launched into hooked process sucessfully, But when I check the statement

控制控制= Control.FromHandle(MainWindowHandle),返回null到控制对象,其中MainWindowhandle是大呼过瘾的过程,你总是从.NET过程级启动该进程后拍摄只是一个本地主窗口句柄

Control control = Control.FromHandle(MainWindowHandle), it returns null into control object where "MainWindowhandle"is just a native main window handle of that hooked process, which you always take from .NET "Process" class after launching that process.

但STRANGLY它发生在其他一些上钩的过程是相同的C#.net应用程序,它会返回主的WinForm有效的对象。

But STRANGLY it happens that in some other hooked process which is the same C# .NET application, it returns valid object of Main "WinForm".

那么,为什么它不会上述情况下工作?有没有例外情况使用MainWindowHandle正常。在我的例子都是用C#编写单独的.NET托管流程。任何过程的配置需要保持特别在创建这个过程?

So why it will not work in above case? Are there any exceptions to use "MainWindowHandle" properly. In my case both are seperate .NET managed processes programmed in C#. Any process configuration needs to maintain specially while creating that process?

问候 乌斯曼

推荐答案

1)请记住,可能有多个AppDomain,你只能得到当前进程的当前应用程序域的控制对象。 你也需要AFAIK使用权ruuntime版本,但我不知道这一点。

1.) Keep in mind, that there may be multiple appdomains and you can only get the control-objects of the current appdomain in the current process. Also you have to use the right ruuntime-version afaik, but I am not sure about that.

2。)你为什么要控制手柄反正,它更方便易直接使用原始手柄的工作,你甚至可以在另一个过程中,没有DLL注入使用本机功能的。 如果你真的需要管理的控制对象,然后点击检查出的 Application.OpenForms 集合,而不是该句柄搜索!

2.) Why do you want the control handle anyways, it is much more convinient to work with native handles directly, you can even use the native functions from within another process, no dll injection. If you really need the managed control-objects, then check out the Application.OpenForms collection instead of that handle search!