加载DLL不止一次? [英] Load a DLL More Than Once?

查看:248
本文介绍了加载DLL不止一次?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我使用LoadLibrary函数在Windows中加载DLL。我的问题是这样的:如果我为同一个DLL调用这个方法多次,我得到处理不同的DLL的实例,或者他们都会引用同一个实例?

I'm using the LoadLibrary function to load a DLL in Windows. My question is this: If I call this method more than once for the same DLL, do I get handles to different instances of the DLL, or will they all refer to the same instance?

此外,这种行为如何与Linux SO文件相关联,它是相同还是完全不同,我可以在这方面做什么假设?感谢。

Additionally, how does this behaviour correlate to Linux SO files, is it the same or completely different, and what assumptions can I make in this regard? Thanks.

推荐答案

MSDN文档说明:


系统在所有加载的
模块上维护每个进程的引用计数。调用LoadLibrary增加引用计数。调用
FreeLibrary或FreeLibraryAndExitThread函数减少
引用计数。当引用计数
达到零时或者当进程终止时(不管
引用计数),系统卸载模块。

The system maintains a per-process reference count on all loaded modules. Calling LoadLibrary increments the reference count. Calling the FreeLibrary or FreeLibraryAndExitThread function decrements the reference count. The system unloads a module when its reference count reaches zero or when the process terminates (regardless of the reference count).

所以,似乎加载模块多次(没有匹配调用FreeLibrary)将返回相同的句柄。

So it would appear that loading the module more than once (without matching calls to FreeLibrary) will return the same handle.

这篇关于加载DLL不止一次?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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