各位高手,我想实现一个将指定网址添加到收藏夹,编译的时候没什么问题,但是一执行,就老报错,还请各位帮我看看~ 哪里出了问题? 谢谢~~procedure TForm1.Button1Click(Sender: TObject);
const
CLSID_ShellUIHelper:TGUID='{64AB4BB7-111E-11D1-8F79-00C04FC2FBE1}';
var
ShellUIHelper:ISHellUIHelper;
url,title:Olevariant;begin
url:='www.sohu.com';
title:='搜狐';
ShellUIHelper:=CreateComObject(CLSID_SHELLUIHELPER) as IShellUIHelper;
ShellUIHelper.AddFavorite(url,title);//执行到这句报错
end;
const
CLSID_ShellUIHelper:TGUID='{64AB4BB7-111E-11D1-8F79-00C04FC2FBE1}';
var
ShellUIHelper:ISHellUIHelper;
url,title:Olevariant;begin
url:='www.sohu.com';
title:='搜狐';
ShellUIHelper:=CreateComObject(CLSID_SHELLUIHELPER) as IShellUIHelper;
ShellUIHelper.AddFavorite(url,title);//执行到这句报错
end;
procedure TForm1.AddFavorite(IE: TEmbeddedWB);
procedure CreateUrl(AUrlPath, AUrl: PChar);
var
URLfile: TIniFile;
begin
URLfile := TIniFile.Create(String(AUrlPath));
RLfile.WriteString('InternetShortcut', 'URL', String(AUrl));
RLfile.Free;
end;
var
AddFav: function(Handle: THandle;
UrlPath: PChar; UrlPathSize: Cardinal;
Title: PChar; TitleSize: Cardinal;
FavIDLIST: pItemIDList): Bool; stdcall;
FDoc: IHTMLDocument2;
UrlPath, url, title: array[0..MAX_PATH] of char;
H: HWnd;
pidl: pItemIDList;
FRetOK: Bool;
begin
FDoc := IHTMLDocument2(IE.Document);
if FDoc = nil then exit;
StrPCopy(Title, FDoc.Get_title);
StrPCopy(url, FDoc.Get_url);
if Url <> '' then
begin
H := LoadLibrary(PChar('shdocvw.dll'));
if H <> 0 then
begin
SHGetSpecialFolderLocation(0, CSIDL_FAVORITES, pidl);
AddFav := GetProcAddress(H, PChar('DoAddToFavDlg'));
if Assigned(AddFav) then
FRetOK :=AddFav(Handle, UrlPath, Sizeof(UrlPath), Title, Sizeof(Title), pidl)
end;
FreeLibrary(h);
if FRetOK then
CreateUrl(UrlPath, Url);
end
end;