阅读《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;

解决方案 »

  1.   

    type
      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是个函数类型,可以用来定义这种类型的“函数变量”。
      

  2.   

    惭愧,感谢二楼,请问这种“函数变量”的概念是DELPHI哪部分知识里的,是动态链接库还是面向对象,我怎么没有查到?
      

  3.   

    这个是动态调用动态库的函数的定义,当你动态调用动态链接库的函数时,可以这样定义。和VC的typedef类似,给你个VC调用动态链接库函数的例子,你看了就懂了。
            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文件。");  
            }