本文整理自网络,侵删。
//转贴者:以前看过陆麟先生翻译过一篇这样的文章,是c版本的,我用delphi改写了没成功,今天去清华bbs转悠看见了这篇delphi版本的,特贴出来
发信人: Litoad (Rick), 信区: Delphi
标 题: Self-Delete程序之Delphi版本,终于搞定了。 (转载)
发信站: BBS 水木清华站 (Mon Jun 4 20:51:55 2001)
【 以下文字转载自 Programming 讨论区 】
发信人: Litoad (Rick), 信区: Programming
标 题: Self-Delete程序之Delphi版本,终于搞定了。
发信站: BBS 水木清华站 (Mon Jun 4 20:50:42 2001)
到Borland的论坛去问了问,确实跟laoduan说得一样,要自己GetProcAddress。代码如下: program Project1;
uses
windows;
procedure DeleteSelf;
var
module : HMODULE;
buf : array [ 0 .. MAX_PATH - 1 ] of char;
p : ULONG;
hKrnl32 : HMODULE;
pExitProcess, pDeleteFile, pFreeLibrary : pointer;
begin
module := GetModuleHandle ( nil );
GetModuleFileName ( module, buf, sizeof ( buf ) );
CloseHandle ( THandle ( 4 ) );
p := ULONG ( module ) + 1;
//上面这一句什么意思?
hKrnl32 := GetModuleHandle ( 'kernel32' );
pExitProcess := GetProcAddress ( hKrnl32, 'ExitProcess' );
pDeleteFile := GetProcAddress ( hKrnl32, 'DeleteFileA' );
pFreeLibrary := GetProcAddress ( hKrnl32, 'FreeLibrary' );
asm
lea eax, buf
push 0
push 0
push eax
push pExitProcess
push p
push pDeleteFile
push pFreeLibrary
ret
end;
end;
相关阅读 >>
Delphi idftp 错误:socket error 10054 �c connection reset by peer -连接被重置
indy tidtcpclient 的一个用法上要留意的问题,以及 http
Delphi win32,win64用于单/多线程计数素数的整数性能比较
Delphi xe 无法编译apk提示sdk路径问题时?sdk路径配置方法
更多相关阅读请进入《Delphi》频道 >>