AfxLoadLibrary 和 LoadLibrary的区别

For AfxLoadLibrary, and serving as the dll search rule: When no path is specified, the function searches for the file in the following sequence:
The directory from which the application loaded.

The current directory.

Windows 95/98: The Windows system directory. Windows NT: The 32-bit Windows system directory. The name of this directory is SYSTEM32.

Windows NT only: The 16-bit Windows system directory. There is no Win32 function that obtains the path of this directory, but it is searched. The name of this directory is SYSTEM.

The Windows directory.

The directories that are listed in the PATH environment variable.

Each process maintains a reference count for each loaded library module. This reference count is incremented each time AfxLoadLibrary is called and is decremented each time AfxFreeLibrary is called. When the reference count reaches zero, the module is unmapped from the address space of the calling process and the handle is no longer valid.


        Be sure to use AfxLoadLibrary and AfxFreeLibrary (instead of the Win32 functions LoadLibrary and FreeLibrary) if your application uses multiple threads and if it dynamically loads an extension DLL. Using AfxLoadLibrary and AfxFreeLibrary insures that the startup and shutdown code that executes when the extension DLL is loaded and unloaded does not corrupt the global MFC state.


        进程调用 LoadLibrary(或 AfxLoadLibrary)以显式链接到 DLL。如果成功,函数将指定的 DLL 映射到调用进程的地址空间中并返回此 DLL 的句柄,该句柄可与用于显式链接的其他函数(如 GetProcAddress 和 FreeLibrary)一起使用。
LoadLibrary 尝试使用用于隐式链接的同一搜索序列来定位 DLL。如果系统无法找到 DLL 或者入口点函数返回 FALSE,LoadLibrary 将返回 NULL。如果对 LoadLibrary 的调用所指定的 DLL 模块已映射到调用进程的地址空间中,则函数仅返回 DLL 的句柄并递增模块的引用数。
如果 DLL 有入口点函数,则操作系统在调用 LoadLibrary 的进程上下文中调用此函数。如果由于以前调用了 LoadLibrary 但没有相应地调用 FreeLibrary 函数而导致 DLL 已经附加到进程,则不会调用此入口点函数。
加载扩展 DLL 的 MFC 应用程序应使用 AfxLoadLibrary,而不应使用 LoadLibrary。AfxLoadLibrary 在调用 LoadLibrary 之前将处理线程同步。AfxLoadLibrary 的接口(函数原型)与 LoadLibrary 相同。
如果出于某种原因 Windows 无法加载 DLL,进程可以尝试从错误恢复。例如,进程可通知用户所发生的错误,并让用户指定 DLL 的其他路径。

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值