Delphi-PRAXiS

Delphi-PRAXiS (https://www.delphipraxis.net/forum.php)
-   Win32/Win64 API (native code) (https://www.delphipraxis.net/17-win32-win64-api-native-code/)
-   -   FindFirstFileW - Handle-Problem (https://www.delphipraxis.net/155105-findfirstfilew-handle-problem.html)

e-gon 8. Okt 2010 12:59

FindFirstFileW - Handle-Problem
 
Hallo,

um bei Dateien mit internationalen Schriftzeichen die Dateigröße ermitteln zu können, habe ich folgenden Code geschrieben:
Delphi-Quellcode:
function GetFileSize(const FileName: widestring): Int64;
var H: THandle;
     D: TWIN32FindDataW;
begin
  H:= FindFirstFileW(PWideChar(FileName),D);
  if H<>INVALID_HANDLE_VALUE then begin
    if D.dwFileAttributes and FILE_ATTRIBUTE_DIRECTORY=0 then
      Result:= (Int64(D.nFileSizeHigh) shl 32) or D.nFileSizeLow
    else Result:= 0;
    CloseHandle(H); // funktioniert nicht!
  end
  else Result:= -1;
end;
Allerdings bekomme ich bei CloseHandle(H) immer ein Exception der Klasse EExternalException. Meldung: 'Externe Exception C0000008'
Wo ist da der Fehler? Das Handle muss ich ja freigeben. Aber wie sonst?

Gruß
e-gon

Björn Ole 8. Okt 2010 13:08

AW: FindFirstFileW - Handle-Problem
 
Siehe MSDN-Library durchsuchenFindFirstFile :

Zitat:

When the search handle is no longer needed, close it by using the FindClose function, not CloseHandle.

Also
Delphi-Quellcode:
Windows.FindClose(H);
.

e-gon 8. Okt 2010 13:16

AW: FindFirstFileW - Handle-Problem
 
Danke, jetzt tut's! :-D


Alle Zeitangaben in WEZ +1. Es ist jetzt 20:21 Uhr.

Powered by vBulletin® Copyright ©2000 - 2024, Jelsoft Enterprises Ltd.
LinkBacks Enabled by vBSEO © 2011, Crawlability, Inc.
Delphi-PRAXiS (c) 2002 - 2023 by Daniel R. Wolf, 2024 by Thomas Breitkreuz