在远程Windows框中动态运行DLL? [英] dynamically running a DLL at a remote Windows box?

查看:217
本文介绍了在远程Windows框中动态运行DLL?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述



说一个用户想要将自己的DLL文件发送到远程服务器并运行该DLL在远程站点的功能。用户可能能够提供功能入口点以及所需参数,但不能再提供。 (例如没有头文件)



我正在考虑在远程站点设置代理可执行文件,可以(1)动态加载和绑定未知的DLL,(2)运行带有参数的函数。这是一个很好的方法,还是可执行的?

解决方案

您可以使用动态加载DLL的方法。



通常您通过将.LIB静态链接到项目并编译它来使用DLL。要在运行时动态加载DLL,请使用以下WIN32 API函数和其他一些技巧。



LoadLibaray();
LoadLibarayEx();
GetProcAddress();
FreeLibrary();



还有一些其他的技巧




  • 您需要将dll函数声明为导出。

  • 在c ++中,您需要使用externC来防止函数的名称变化。

  • FARPROC ... with GetProcAddress



这一切都在以下wiki文章中解释 - http://en.wikipedia.org/wiki/Dynamic-link_library



您在远程机器上安装可执行文件的想法是一个很好的选择。只要您同意用户的功能名称和参数。如果dll符合这一点,那么dll可以随时更改,而不需要你改变EXE。一旦设置和工作,添加额外的功能就很简单。


Is there a way of dynamically running a DLL at a remote Windows box?

Say a user wants to send a his own DLL file to a remote server and run a function in that DLL at the remote site. The user may be able to provide function entry points as well as required parameters, but no more. (e.g. no header file)

I am thinking of setting up an agent executable at the remote site that can (1) dynamically load and bind a unknown DLL and (2) run a function with parameters. Is this a good a approach, or is such an executable possible?

解决方案

You can use a technique of Dynamically loading your DLL's.

Normally you use a DLL by statically linking a .LIB into your project and compiling it. To load a DLL dynamically at runtime you use the following WIN32 API functions and a few other tricks.

LoadLibaray(); LoadLibarayEx(); GetProcAddress(); FreeLibrary();

There are some other tricks involved

  • You need to declare the dll functions as export'ed.
  • In c++ you need to use extern "C" to prevent name mangling of your functions.
  • FARPROC ... with GetProcAddress

It is all explained in the following wiki article - http://en.wikipedia.org/wiki/Dynamic-link_library

Your idea of installing an executable on the remote machine is a good one. So long as you agree on the function names and parameters with the user. If the dll complies with this then the dll can be changed at any time without requiring you EXE to be changed. Once set up and working it is simple to add extra functions.

这篇关于在远程Windows框中动态运行DLL?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆