在 Delphi 中加载同一 DLL 的两个实例

发布于 2024-08-29 22:16:39 字数 374 浏览 5 评论 0原文

这是我的问题:我想创建同一个 DLL 的两个单独的实例。

以下内容不起作用,因为 Handle1 和 Handle2 将获得相同的地址

  Handle1 := LoadLibrary('mydll.dll');
  Handle2 := LoadLibrary('mydll.dll');

以下内容有效,但我必须复制 DLL 并将其重命名为其他名称(这似乎有点愚蠢)

  Handle1 := LoadLibrary('mydll.dll');
  Handle2 := LoadLibrary('mydll2.dll');

有没有办法只拥有一个DLL 文件,但加载它的几个实例?

Here's my problem: I would like to create two separate instances of the same DLL.

The following doesn't work because Handle1 and Handle2 will get the same address

  Handle1 := LoadLibrary('mydll.dll');
  Handle2 := LoadLibrary('mydll.dll');

The following works, but I have to make a copy of the DLL and rename it to something else (which seems a bit silly)

  Handle1 := LoadLibrary('mydll.dll');
  Handle2 := LoadLibrary('mydll2.dll');

Is there a way to have only one DLL file, but load several instances of it?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(3

匿名。 2024-09-05 22:16:39

我认为这是不可能的。

您必须编写一个加载 dll 的 .exe。然后,您可以跨多个进程(.exe),每个进程都将运行自己的 dll 实例。您必须使用 IPC(进程间通信)技术来与 .exe 进行通信。当然可行,但并不完全是理所当然的事情。

I don't think that's possible.

You'd have to write a .exe which loads the dll. Then you can span multiple processes (the .exe), and each will run its own instance of the dll. You'd have to use IPC (inter process communication) techniques to communicate with the .exes. Certainly doable, but not exactly a no-brainer.

美人迟暮 2024-09-05 22:16:39

它不能与 LoadLibrary 一起使用,因为 Windows 会检查 dll 是否已加载,并且会一次又一次返回相同的句柄。

我有一些代码最初是为了从绑定到可执行文件的资源加载 dll,但我想也可以对填充了文件内容的内存区域执行相同的操作。我看不出有什么理由它不能工作两次,但我还没有测试过。

您可以在这里找到它:
http://svn.berlios。 de/viewvc/dzchart/utilities/dzLib/trunk/src/u_dzResourceDllLoader.pas?view=markup

它是我的库 dzlib 的一部分,可在 MPL 下使用。

It won't work with LoadLibrary because Windows checks whether the dll has already been loaded and will return the same handle again and again.

I have got some code that was originally meant to load a dll from a resource bound to the executable but I guess it would also be possible to do the same for a memory area which was filled with the content of a file. I can't see any reason why it would not work twice, but I have not tested it.

You can find it here:
http://svn.berlios.de/viewvc/dzchart/utilities/dzLib/trunk/src/u_dzResourceDllLoader.pas?view=markup

It is part of my library dzlib which is available under the MPL.

箹锭⒈辈孓 2024-09-05 22:16:39

Windows XP 引入了 Win32 DLL 的并行执行(这些人对此了解很多)。

经过大量的努力,您现在可以:

Windows XP introduced side-by-side execution for Win32 DLL's (these guys know a lot about it).

With a lot of hoops you can now:

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文