![]() |
RenFile
Hallo Leute,
der folgende Code löst unter Vista eine "Zugriffsverletzung ... in Modul 'Kernel32.dll' lesen von Adresse 2" aus, unter W98 ist alles in Ordnung. Woran kann das liegen? Ist RenFile bei Vista geändert worden?
Delphi-Quellcode:
MfG
if MessageDlg(s,mtConfirmation,[mbYes,MbNo,mbHelp],10) = mrYes then begin
if RenFile(Oldname,Bli.Folder + Newname) then // <--- HIER ------------ begin if Config.CBit[Ord(Confirm)] then ShowMessage('Neuer Namen: "' + Newname + '"'); BLi.Bildnamen[Bildpos]:=Newname; Renamed:=true end end; Willie1 |
Re: RenFile
Was ist den RenFile? Von der Funktion habe ich noch nichts gehört, weder unter Delphi noch kenne ich sie aus der WinAPI.
Und bitte editier deinen Beitrag und ihm einen aussagekräftigeren Titel. |
Re: RenFile
Guten Morgen,
RenFile, ist das eine Win-Api Routine? Tritt das Problem bei allen möglichen Dateien auf? Oder tritt es nur bei bestimmten Dateien/Verzeichnissen auf? Grüße Klaus |
Umbenennen von Files mit Windows
Sorry, ich habe meine Frage mit "zu heißer Nadel gestrickt"!
Eigene Funktion RenFile sieht so aus:
Delphi-Quellcode:
Der Fehler tritt bei beliebigen Dateien und Pfaden nur unter Vista auf.
function RenFile(const Oldname,Newname: string): Boolean;
var SHFOS: TSHFileOpStruct; a,n: array[0..255] of Char; begin if FileExists(Oldname) then begin FillChar(a, SizeOf(a), 0); StrPCopy(a, ExpandFilename(Oldname)+#0#0); FillChar(n, SizeOf(n), 0); StrPCopy(n, ExpandFilename(Newname)+#0#0); with SHFOS do begin Wnd:=0; wFunc:=FO_RENAME; pFrom:=a; pTo:=n; fFlags:=FOF_SIMPLEPROGRESS; fAnyOperationsAborted:=false; hNameMappings:=nil; end; Result:=(ShFileOperation(SHFOS) = 0) and (SHFOS.fAnyOperationsAborted = LongBool(false)) and FileExists(NewName) end else Result:=false end; {RenFile} |
Re: RenFile
Und an welcher Stelle in der Funktion tritt die Zugriffsverletzung genau auf? Und welche Entwicklungsumgebung wird genutzt?
Und der Titel ist immer noch recht unbefriedigend. Vorschlag: "Datei umbenennen mit ShFileOperation schlägt unter Vista fehl" |
Re: RenFile
auch wen es nicht DER Fehler ist
Delphi-Quellcode:
LongBool(false) ist zwar immer 0, aber LongBool(true) ... nja, vorallem für die WinAPI ist =LongBool(true) nicht immer das Selbe
// statt
(SHFOS.fAnyOperationsAborted = LongBool(false)) // lieber not SHFOS.fAnyOperationsAborted |
Re: RenFile
.. mag das eventuell damit etwas zu tun haben:
There are two versions of this structure, an ANSI version (SHFILEOPSTRUCTA) and a Unicode version (SHFILEOPSTRUCTW). The Unicode version is identical to the ANSI version, except that wide character strings (LPCWSTR) are used in place of ANSI character strings (LPCSTR). On Microsoft Windows 98 and earlier, only the ANSI version is supported. On Microsoft Windows NT 4.0 and later, both the ANSI and Unicode versions of this structure are supported. SHFILEOPSTRUCTW and SHFILEOPTSTRUCTA should never be used directly; the appropriate structure is redefined as SHFILEOPSTRUCT by the precompiler depending on whether the application is compiled for ANSI or Unicode. SHNAMEMAPPING has similar ANSI and Unicode versions. For ANSI applications, hNameMappings points to an int followed by an array of ANSI SHNAMEMAPPING structures. For Unicode applications, hNameMappings points to an int followed by an array of Unicode SHNAMEMAPPING structures. However, on Windows NT 4.0 and later, SHFileOperation always returns a handle to a Unicode set of SHNAMEMAPPING structures. If you want applications to be functional with all versions of Windows, the application must employ conditional code to deal with name mappings. For example: Copy Code
Code:
Treat hNameMappings as a pointer to a structure whose members are a UINT value followed by a pointer to an array of SHNAMEMAPPING structures, as seen in its declaration:
x = SHFileOperation(&shop);
if (fWin9x) HandleAnsiNameMappings(shop.hNameMappings); else HandleUnicodeNameMappings(shop.hNameMappings); ![]() Grüße Klaus |
Re: RenFile
es kommt dann darauf an, welche Version Delphi aufruft.
die WinAPI kennt SHFileOperation garnicht Delphi 2009 leitet SHFileOperation nach SHFileOperationW um und alles andere nach SHFileOperationA SHFileOperationA ist ANSI und SHFileOperationW demnach Unicode ja und Win98 kennt standardmäßig kein Unicode (aber da sollte das Programm garnicht erst starten, wenn SHFileOperationW fest eingebunden ist, da dort der ProgrammLoader meckern sollte) |
Re: RenFile
Luckie,
ich benutze die Bibliothek GDIAPI von ![]() Also Delphi 6. Ich werde mit euren Tipps (Danke Klaus + himitsu) versuchen das Problem zu lösen und melde mich später nochmal. Gruß W. |
Re: RenFile
Warum wird nicht die Function RenameFile() genutzt? Die ist (mind.) ab Delphi6 in allen Delphi-Versionen vorhanden und geht auch unter Vista, bei vorhanden Schreibrechten)
|
Alle Zeitangaben in WEZ +1. Es ist jetzt 00:49 Uhr. |
Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
LinkBacks Enabled by vBSEO © 2011, Crawlability, Inc.
Delphi-PRAXiS (c) 2002 - 2023 by Daniel R. Wolf, 2024 by Thomas Breitkreuz