Java 可以在另一个进程中注入DLL吗?

Can Java inject DLL in another process?

实际上我已经问过关于我的问题的问题。为防止人们再次询问不相关详细信息,我将post此背景信息,您可以跳过:

I'm making a automation application. This application does some tasks for the user over time for specific window. When these taks are required to be made, window flashes in taskbar and sometimes even steals focus to get the user to do the task. Once the automation is here, this is no longer wanted - the user will only focus the window when he wants to check how well is the automation doing it's job.

I discovered this focus and flash disable dll project thanks to this superuser post about applications stealing focus.

我的自动化应用程序在 Java 中。因此,虽然我可以打开一个 DLL 注入应用程序并手动禁用闪烁,但我想将它集成到 java 应用程序中——例如作为一个设置选项。当用户选择禁用闪烁和窃取焦点时,将注入dll。

当然,这需要 Java 才能注入我的 .dll 文件。我找到了这个项目:dotnet-dll-injector 但它只处理 .NET dll 文件。

问: 有没有办法在 Java 中选择一个 .dll 文件并将其注入进程?如果解决方案不简单,哪些库会导致这种情况?

我注意到 CreateRemoteThread 在某种程度上与 DLL 注入有关。也许 JNA 库支持它?

我不知道 Java 中的原生方法。

既然您已经在 .NET 中找到了可行的解决方案并且您的任务是 Windows 特定的,我建议如下:

将 dotnet-dll-injector 构建为 DLL 并从您的 Java 应用中调用它。 How to call into .NET dll from Java

编辑:更容易将其构建为控制台应用程序并使用 Runtime.getRuntime().exec("...");

或者,如果您仍处于开发过程的早期阶段,并且没有立即跨平台的计划,只需在 C# 中完成所有操作,省去一些麻烦。