Ich habe gerade versucht diese Funktion zu nutzen und in meine Registry Klasse eingebaut:
Delphi-Quellcode:
type
TMpuRegistry = class(TObject)
private
FhkResult: HKEY;
FMachine: PWideChar;
FhKey: HKEY;
function GetMachine: WideString;
function GetHKey: HKEY;
public
constructor Create(const Machine: string; hKey: HKEY);
constructor CreateW(const Machine: WideString; hKey: HKEY);
destructor Destroy; override;
function Connect: LongInt;
function CreateKey(Root: HKEY; const SubKey: string): LongInt;
function CreateKeyW(Root: HKEY; const SubKey: WideString): LongInt;
function OpenKey(const SubKey: string; samDesired: REGSAM): LongInt;
function OpenKeyW(const SubKey: WideString; samDesired: REGSAM): LongInt;
function ReadInt(const ValueName: string; var Value: Integer): LongInt;
function ReadIntW(const ValueName: WideString; var Value: Integer): LongInt;
function ReadByte(const ValueName: string; var Value: Byte; default: Byte = 0): LongInt;
function ReadByteW(const ValueName: WideString; var Value: Byte; default: Byte = 0): LongInt;
function ReadBool(const ValueName: string; var Value: Boolean; default: Boolean = True): LongInt;
function ReadBoolW(const ValueName: string; var Value: Boolean; default: Boolean = True): LongInt;
function ReadString(const ValueName: string; var Value: string): LongInt;
function ReadStringW(const ValueName: WideString; var Value: WideString): LongInt;
function WriteInt(const ValueName: string; Value: Integer): LongInt;
function WriteIntW(const ValueName: WideString; Value: Integer): LongInt;
function WriteByte(const ValueName: string; Value: Byte): LongInt;
function WriteByteW(const ValueName: WideString; Value: Byte): LongInt;
function WriteBool(const ValueName: string; Value: Boolean): LongInt;
function WriteBoolW(const ValueName: WideString; Value: Boolean): LongInt;
function WriteString(const ValueName: string; Value: string): LongInt;
function WriteStringW(const ValueName: WideString; const Value: WideString): LongInt;
function DeleteValueName(const ValueName: string): LongInt;
function DeleteSubKey(const SubKey: string): LongInt;
function DeleteTree(const SubKey: String): Longint;
property Machine: WideString read GetMachine;
property hKey: HKEY read GetHKey;
end;
implementation
function SHDeleteKey(key: HKEY; SubKey: LPCSTR): Integer; external 'shlwapi.dll' name 'SHDeleteKeyW';
//...;
function TMpuRegistry.DeleteTree(const SubKey: String): LongInt;
begin
result := SHDeleteKey(FhkResult, PChar(SubKey));
end;
Aber ich bekomme eine AccessViolation nach dem Aufruf. Woran kann das liegen?
FhkResult ist gültig.
Edit: Hmpf, es hat mal wieder das
stdcall gefehlt.