本文整理自网络,侵删。
//转贴者:以前看过陆麟先生翻译过一篇这样的文章,是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 tfdquery提交tfdmemtable修改的数据
Delphi tscreen 类 - 通过 screen 更换光标
Delphi中break,exit,abort跳出循环的比较
Delphi 2010 复制整个文件夹(当然包括嵌套文件夹)
更多相关阅读请进入《Delphi》频道 >>