阅读《DELPHI下深入WINDOWS核心编程》第2章钩子原理的第一个例子中这样一段定义函数的代码:我没有看懂得彩色的那段代码,其中的function不知道什么意思,请大家帮我解释一下,多谢
implementationvar
function NewCreateFileA(lpFileName: PChar;dwDesiredAccess, dwShareMode: DWORD;
lpSecurityAttributes: PSecurityAttributes;dwCreationDisposition,dwFlagsAndAttributes: DWORD;
hTemplateFile: THandle): THandle;stdcall;
type
TCreateFileA=function(lpFileName: PChar;dwDesiredAccess, dwShareMode: DWORD;
lpSecurityAttributes: PSecurityAttributes;dwCreationDisposition,dwFlagsAndAttributes: DWORD;
hTemplateFile: THandle): THandle;stdcall;
begin
////////////////////
end;
implementationvar
function NewCreateFileA(lpFileName: PChar;dwDesiredAccess, dwShareMode: DWORD;
lpSecurityAttributes: PSecurityAttributes;dwCreationDisposition,dwFlagsAndAttributes: DWORD;
hTemplateFile: THandle): THandle;stdcall;
type
TCreateFileA=function(lpFileName: PChar;dwDesiredAccess, dwShareMode: DWORD;
lpSecurityAttributes: PSecurityAttributes;dwCreationDisposition,dwFlagsAndAttributes: DWORD;
hTemplateFile: THandle): THandle;stdcall;
begin
////////////////////
end;
TCreateFile = function(lpFileName: PChar; dwDesiredAccess, dwShareMode: DWORD;
lpSecurityAttributes: PSecurityAttributes; dwCreationDisposition, dwFlagsAndAttributes: DWORD;
hTemplateFile: THandle): THandle; stdcall;
TCreateFileA = function(lpFileName: PAnsiChar; dwDesiredAccess, dwShareMode: DWORD;
lpSecurityAttributes: PSecurityAttributes; dwCreationDisposition, dwFlagsAndAttributes: DWORD;
hTemplateFile: THandle): THandle; stdcall;
TCreateFileW = function(lpFileName: PWideChar; dwDesiredAccess, dwShareMode: DWORD;
lpSecurityAttributes: PSecurityAttributes; dwCreationDisposition, dwFlagsAndAttributes: DWORD;
hTemplateFile: THandle): THandle; stdcall;var
OldCreateFile: TCreateFile;
OldCreateFileA: TCreateFileA;
OldCreateFileW: TCreateFileW;看了这个就大概懂了吧。你可以这样理解,TCreateFileA是个函数类型,可以用来定义这种类型的“函数变量”。
HINSTANCE hInst = LoadLibrary("seekcrypt.dll");
if(hInst)
{
typedef int (*_seekcrypt)(int,unsigned char* ,int,unsigned char*,unsigned char* ,int* );
_seekcrypt seekcrypt = NULL;
seekcrypt = (_seekcrypt)GetProcAddress(hInst, "seekcrpyt");
if(seekcrypt)
{
int i=seekcrypt(1,'12',2,'1212','2323',4);
CString aa;
aa.Format("%d%s",i,aa);
AfxMessageBox(aa);
}
FreeLibrary(hInst);
}else{
AfxMessageBox("找不到seekcrypt.dll文件。");
}