如何判断一个动态库正在被使用中

解决方案 »

  1.   

    Function IsFileInUse(const FileName:String):Boolean;
    var
       hFile:Handle;
    begin
       Result:=false;
       if not FileExists(FileName) then Exit;   hFile=CreateFile(Pchar(FileName),
                        GENERIC_READ or GENERIC_WRITE,
                        0,
                        NULL,
                        OPEN_EXISTING,
                        FILE_ATTRIBUTE_NORMAL,
                        0);
       Result:=hFile=-1;
       if not Result then  CloseHandle(hFile);
    End;
      

  2.   

    Function IsFileInUse(const FileName:String):Boolean;
    var
       hFile:Thandle;
    begin
       Result:=false;
       if not FileExists(FileName) then Exit;   hFile:=CreateFile(Pchar(FileName),
                        GENERIC_READ or GENERIC_WRITE,
                        0,
                        NULL,
                        OPEN_EXISTING,
                        FILE_ATTRIBUTE_NORMAL,
                        0);
       Result:=hFile=-1;
       if not Result then  CloseHandle(hFile);
    End;