看流星社区

 找回密码
 注册账号
查看: 4149|回复: 0

易语言DLL卸载自身

[复制链接]

该用户从未签到

发表于 2013-4-11 08:55:07 | 显示全部楼层 |阅读模式
由于软件需要,DLL需要卸载自身

于是看了下msdn 发现有这么个api

FreeLibraryAndExitThread


The FreeLibraryAndExitThread function decrements the reference count of a loaded dynamic-link library (DLL) by one, then calls ExitThread to terminate the calling thread. The function does not return.


VOIDFreeLibraryAndExitThread(HMODULEhModule, DWORDdwExitCode);

ParametershModule[in] Handle to the DLL module whose reference count the function decrements. The LoadLibrary or GetModuleHandleEx function returns this handle.

Do not call this function with a handle returned by the GetModuleHandle function, since this function does not maintain a reference count for the module.

dwExitCode[in] Exit code for the calling thread. Return Values

This function does not return a value. Invalid module handles are ignored.

Remarks

The FreeLibraryAndExitThread function allows threads that are executing within a DLL to safely free the DLL in which they are executing and terminate themselves. If they were to call FreeLibrary and ExitThread separately, a race condition would exist. The library could be unloaded before ExitThread is called.

Requirements Requires Windows XP, Windows 2000 Professional, Windows NT Workstation 3.5 and later, Windows Me, Windows 98, or Windows 95.Requires Windows Server 2003, Windows 2000 Server, or Windows NT Server 3.5 and later.

Declared in Winbase.h; include Windows.h.

Link to Kernel32.lib.

Requires Kernel32.dll.


这个API将释放库并退出线程,于是乎……

将这个函数调用放到线程中去,创建这个线程就可以了。

FreeLibraryAndExitThread 的首参数是模块实例句柄 而易的入口函数 _启动子程序 并没有这个参数传入

但这并不妨碍我们下一步工作 要获取模块实例句柄有很多种方法.

例如 叮咚茶发过的 取模块实例句柄

.版本 2

.子程序 取自身模块句柄, 整数型, , 主要用于取DLL本身取模块句柄,弥补易语言DLL自身无法取模块句柄不足

置入代码 ({ 86, 232, 0, 0, 0, 0, 88, 100, 139, 53, 48, 0, 0, 0, 139, 118, 12, 139, 118, 28, 86, 139, 94, 8, 59, 195, 114, 13, 139, 78, 16, 3, 203, 59, 193, 119, 4, 139, 195, 235, 21, 139, 54, 139, 30, 59, 28, 36, 117, 227, 100, 161, 24, 0, 0, 0, 139, 64, 48, 139, 64, 8, 94, 94, 201, 195 })
返回 (0)


又或者你的dll支持黑月处理的话,可以通过黑月dll入口函数获取,又或是通过GetModuleHandle得到实例句柄,方法多种多样.


测试结果:一切正常~~
点击按钮快速添加回复内容: 支持 高兴 激动 给力 加油 苦寻 生气 回帖 路过 感恩
您需要登录后才可以回帖 登录 | 注册账号

本版积分规则

小黑屋|手机版|Archiver|看流星社区 |网站地图

GMT+8, 2024-4-26 07:45

Powered by Kanliuxing X3.4

© 2010-2019 kanliuxing.com

快速回复 返回顶部 返回列表