Ich habe folgenden Quelltext bekommen um die Windows Links auszulesen!! Es klappt auch alles. Der Compiler gibt mir nur am FreeMem eine Fehler Meldeung aus, warum???
function GetShellLinkInfo(LinkName: string): TShellLinkInfo;<BR>
var HRes: HResult;<BR>
Link: IShellLink;<BR>
PerFile: IPersistFile;<BR>
Buffer: array[0..255] of Char;<BR>
IntBuffer: Integer;<BR>
WordBuffer: Word;<BR>
Size: Integer;<BR>
W: PChar;<BR>
Data: TWin32FindData;<BR>
begin<BR>
result.Error:=True;<BR>
Size:=(MAX_PATH*2); //MAX_PATH ist definiert in Ole2<BR>
GetMem(W, MAX_PATH*2);<BR>
StringToWideChar(LinkName, W, Size);<BR>
<BR>
HRes := CoInitialize(nil);<BR>
HRes := CoCreateInstance(TGUID(CLSID_ShellLink), nil, CLSCTX_INPROC_SERVER,
TGUID(IID_IShellLinkA), Link);<BR>
if not Succeeded(HRes) then result.Error:=False;<BR>
<BR>
Link._AddRef; //wichtig !!!<BR>
ReallocMem(W, Length(LinkName) +1 );<BR>
<BR>
HRes:=Link.QueryInterface(system.TGUID(IID_IPersis tFile), PerFile);<BR>
if not Succeeded(HRes) then result.Error:=False;<BR>
<BR>
HRes := PerFile.Load(W, STGM_READ);<BR>
if not Succeeded(HRes) then result.Error:=False;<BR>
<BR>
result.LinkName:=LinkName;<BR>
<BR>
//Beschreibung<BR>
Link.GetDescription(@Buffer, MAX_PATH-5);<BR>
result.Description := StrPas(Buffer);<BR>
<BR>
//Ziel<BR>
Link.GetPath(@Buffer, MAX_PATH-5, Data, SLGP_UNCPRIORITY);<BR>
result.FileName := StrPas(Buffer);<BR>
<BR>
//Arbeitsverzeichnis<BR>
Link.GetWorkingDirectory(@Buffer, MAX_PATH-5);<BR>
result.WorkingDirectory := StrPas(Buffer);<BR>
<BR>
//Argumente<BR>
Link.GetArguments(@Buffer, MAX_PATH-5);<BR>
result.Arguments := StrPas(Buffer);<BR>
<BR>
//FensterStatus<BR>
Link.GetShowCmd(IntBuffer); //SW_SHOWNORMAL, SW_SHOWMINNOACTIVE, SW_SHOWMAXIMIZED<BR>
result.WindowState := IntBuffer;<BR>
<BR>
//HotKey<BR>
Link.GetHotKey(WordBuffer);<BR>
result.HotKey := GetHotKey(WordBuffer);<BR>
<BR>
//Icon<BR>
Link.GetIconLocation(@Buffer, MAX_PATH-5, IntBuffer);<BR>
result.IconFileName := StrPas(Buffer);<BR>
result.IconIndex := IntBuffer;<BR>
<BR><BR>
Link._Release;<BR>
PerFile.Release;<BR>
CoUninitialize;<BR>
FreeMem(W, Size);<BR>
end;<BR>
end;<BR>
<BR>
Ich bin für jede Hilfe dankbar!!
Danke
Daniel
function GetShellLinkInfo(LinkName: string): TShellLinkInfo;<BR>
var HRes: HResult;<BR>
Link: IShellLink;<BR>
PerFile: IPersistFile;<BR>
Buffer: array[0..255] of Char;<BR>
IntBuffer: Integer;<BR>
WordBuffer: Word;<BR>
Size: Integer;<BR>
W: PChar;<BR>
Data: TWin32FindData;<BR>
begin<BR>
result.Error:=True;<BR>
Size:=(MAX_PATH*2); //MAX_PATH ist definiert in Ole2<BR>
GetMem(W, MAX_PATH*2);<BR>
StringToWideChar(LinkName, W, Size);<BR>
<BR>
HRes := CoInitialize(nil);<BR>
HRes := CoCreateInstance(TGUID(CLSID_ShellLink), nil, CLSCTX_INPROC_SERVER,
TGUID(IID_IShellLinkA), Link);<BR>
if not Succeeded(HRes) then result.Error:=False;<BR>
<BR>
Link._AddRef; //wichtig !!!<BR>
ReallocMem(W, Length(LinkName) +1 );<BR>
<BR>
HRes:=Link.QueryInterface(system.TGUID(IID_IPersis tFile), PerFile);<BR>
if not Succeeded(HRes) then result.Error:=False;<BR>
<BR>
HRes := PerFile.Load(W, STGM_READ);<BR>
if not Succeeded(HRes) then result.Error:=False;<BR>
<BR>
result.LinkName:=LinkName;<BR>
<BR>
//Beschreibung<BR>
Link.GetDescription(@Buffer, MAX_PATH-5);<BR>
result.Description := StrPas(Buffer);<BR>
<BR>
//Ziel<BR>
Link.GetPath(@Buffer, MAX_PATH-5, Data, SLGP_UNCPRIORITY);<BR>
result.FileName := StrPas(Buffer);<BR>
<BR>
//Arbeitsverzeichnis<BR>
Link.GetWorkingDirectory(@Buffer, MAX_PATH-5);<BR>
result.WorkingDirectory := StrPas(Buffer);<BR>
<BR>
//Argumente<BR>
Link.GetArguments(@Buffer, MAX_PATH-5);<BR>
result.Arguments := StrPas(Buffer);<BR>
<BR>
//FensterStatus<BR>
Link.GetShowCmd(IntBuffer); //SW_SHOWNORMAL, SW_SHOWMINNOACTIVE, SW_SHOWMAXIMIZED<BR>
result.WindowState := IntBuffer;<BR>
<BR>
//HotKey<BR>
Link.GetHotKey(WordBuffer);<BR>
result.HotKey := GetHotKey(WordBuffer);<BR>
<BR>
//Icon<BR>
Link.GetIconLocation(@Buffer, MAX_PATH-5, IntBuffer);<BR>
result.IconFileName := StrPas(Buffer);<BR>
result.IconIndex := IntBuffer;<BR>
<BR><BR>
Link._Release;<BR>
PerFile.Release;<BR>
CoUninitialize;<BR>
FreeMem(W, Size);<BR>
end;<BR>
end;<BR>
<BR>
Ich bin für jede Hilfe dankbar!!
Danke
Daniel
Comment