Page 1 of 1

call "window.external.addFavorite"

Posted: Tue May 04, 2004 6:33 am
by bingo
:?: how convert linkname to "COleVariant" ?

Code: Select all

;call "window.external.addFavorite"
Procedure addfavorite(link.s,linkname.s) 

;linkname to "COleVariant" ??? 

;link in unicode 
mem.s = Space(1000) 
MultiByteToWideChar_(#CP_ACP, 0, link, -1, mem, 1000) 

CoInitialize_(0) 
If CoCreateInstance_(?CLSID_ShellUIHelper,0,1,?IID_IShellUIHelper,@Object.IShellUIHelper) = 0 
   Object\AddFavorite(@mem,@linkname); 
   Object\Release() 
EndIf 
CoUninitialize_() 

DataSection 
  CLSID_ShellUIHelper: 
    Data.l $64AB4BB7 
    Data.w $111E,$11D1 
    Data.b $8F,$79,$00,$C0,$4F,$C2,$FB,$E1 
  IID_IShellUIHelper: 
    Data.l $729FE2F8 
    Data.w $1EA8,$11D1 
    Data.b $8F,$85,$00,$C0,$4F,$C2,$FB,$E1 
EndDataSection 
  
EndProcedure 

addfavorite("http://www.purebasic.com","your linkname") 

End
sample like:

#include "ExDisp.h"

IShellUIHelper* pShell = NULL;
HRESULT hr = CoCreateInstance(CLSID_ShellUIHelper, NULL, CLSCTX_SERVER,
IID_IShellUIHelper, (void**)&pShell);
if (hr == S_OK)
{
COleVariant vtTitle("Microsoft");
pShell->AddFavorite(OLESTR("http://www.microsoft.com"), &vtTitle);
pShell->Release();
}

Posted: Tue May 04, 2004 7:34 pm
by bingo
:lol: "learning by doing"

Code: Select all

Global memo.s

Procedure str2unicode(convert.s)
memo.s = Space(1000)
MultiByteToWideChar_(#CP_ACP, 0, convert, -1, memo, 1000)
  ProcedureReturn @memo
EndProcedure


;"window.external.addFavorite" call in pb
Procedure addfavorite(link.s,linkname.s)

;convert linkname to "COleVariant"
Structure Variant
    Type.w
    Reserved1.w
    Reserved2.w    
    Reserved3.w
    String.l
EndStructure

#VT_BSTR = 8
a.Variant\Type = #VT_BSTR

;unicode in variant ...
a\String = SysAllocString_(str2unicode(linkname)) 

CoInitialize_(0)
If CoCreateInstance_(?CLSID_ShellUIHelper,0,1,?IID_IShellUIHelper,@Object.IShellUIHelper) = 0
   Object\AddFavorite(str2unicode(link),@a);
   Object\Release()
EndIf
CoUninitialize_()

DataSection
  CLSID_ShellUIHelper:
    Data.l $64AB4BB7
    Data.w $111E,$11D1
    Data.b $8F,$79,$00,$C0,$4F,$C2,$FB,$E1
  IID_IShellUIHelper:
    Data.l $729FE2F8
    Data.w $1EA8,$11D1
    Data.b $8F,$85,$00,$C0,$4F,$C2,$FB,$E1
EndDataSection
  
EndProcedure

addfavorite("http://www.purebasic.com","the best basic ...")

End