将托管DLL注入本机进程问题
我需要在聊天程序中对 Richedit 控件进行子类化(我正在尝试制作一个音乐机器人)。 我不知道如何用 c/c++ 编码,但我能够使用 C++ 将托管代码注入到使用 CLR 托管的聊天程序中。但出现了一些问题。希望我能从这里得到一些帮助。
- 我的托管代码将在完成线程后退出。我需要保持它运行
- 当我尝试使用 SetWindowLong api 和 GWL_WNDPROC 子类化 richedit 控件时,聊天程序冻结了。
有人能指出我正确的方法吗?或者甚至可以在托管代码中执行此操作吗?
谢谢
I need to subclass a richedit control in a chat program (I am trying to make a musicbot).
I dont know how to code in c/c++ but i was able to use c++ to inject a managed code into the chat program using CLR Hosting. But couple problems occurs. Hopefully I can get some help from here.
- My managed code would exit after it finished the thread. I need to keep it running
- When I tried to subclass the richedit control using SetWindowLong api and GWL_WNDPROC the chat program froze.
Could someone point me to a right way to do this? Or is it even possible to do this in managed code?
Thanks
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
这类事情取决于很多因素,并且可能很难开展。你能提供更多细节吗?
一般来说,对于 1:如果您使用
ICLRRuntimeHost::ExecuteInDefaultAppDomain(pwzAssemblyPath, pwzTypeName, pwzMethodName, pwzArgument)
来执行托管代码,则一旦指定的方法,托管执行就会停止由pwzMethodName
完成。如果您想要持久执行其他任务,并且不想让此调用同时挂起,那么最好的选择是让pwzMethodName
在另一个线程上启动一些程序循环函数。至于2,如果您将代码注入目标进程并与控件交互,则线程安全可能是一个大问题。我个人没有使用过 SetWindowLong api,但它可能与从非调度程序线程修改控件有关。
This sort of stuff depends on a lot of factors and can be hard to get going. Can you provide more details?
At a general level, for 1: If you are using
ICLRRuntimeHost::ExecuteInDefaultAppDomain(pwzAssemblyPath, pwzTypeName, pwzMethodName, pwzArgument)
to execute your managed code, then the managed execution will stop as soon as the method denoted bypwzMethodName
finishes. If you have other tasks you want to do persistently, and don't want to have this call hang in the meantime, your best bet is to havepwzMethodName
start up some program loop function on another thread.As for 2, if you're injecting code into a target process and interacting with controls, thread safety can be a huge issue. I personally haven't used SetWindowLong api but it could be something to do with modifying controls from a non-dispatcher thread.
这是我的 C#
这是我的 C++ 代码
Here is My C#
And here is my C++ code
另一种“更动态”的方法是用托管 C++ 编写一个可以注入的库。
托管 C++ 库可以导出本机函数以用于将其加载到另一个进程中。
仅在托管 C++ 库中编写一些允许您加载额外库的代码。
该库可以重新用于注入未来的对象...
请参阅:http://www.vbib.be/index.php?name=PNphpBB2&file=viewtopic&p=38982
Another "More Dynamic" way is to write a library in Managed C++ that can be injected.
A managed C++ library can export native functions to use for loading it into another process.
Only write some code in that Managed C++ library that allows you to load extra libraries.
That library can be re-used to inject future objects...
See: http://www.vbib.be/index.php?name=PNphpBB2&file=viewtopic&p=38982