Archive: RegisterTlb Function (for those who need this)


RegisterTlb Function (for those who need this)
It took me some time to learn System.dll and make this working, so I post it for anyone who may need this.

My motivation was to register stdole2.tlb as I install VB6 runtimes. Microsoft's installers (PDW and VSI) seem to register this, too. The NSIS archive tipp (how to install vb6 runtime) does not register this file, supplied version of UpgradeDll isn't able to do this.

It seems that on my PC (Windows XP) running this causes stdole2.tlb to be registered for the first time. But VB6 apps (and VB6 and Office) are installed already so I don't know whether it really is necessary or a "should do". Nevertheless: Here's the function including call example. I didn't test it widely yet but regarding to MSDN it should work on Win95 and newer.


...
Push "C:\WINDOWS\System32\stdole2.tlb"
Call RegisterTlb
...


Function RegisterTlb
Exch $R0 ; save old R0 and get filename as R0
Push $R1 ; save R1
Push $R2 ; save R2
; now register TLB file R0
StrCpy $R1 0 ; init R1 with 0 (maybe not neccessary)
System::Call "Oleaut32::LoadTypeLib(w, *i) i (R0, R1R1) .R2"
; R2 contains result, 0 if ok
IntCmp $R2 0 cont
LogText "LoadTypeLib returned $R2 with $R0"
; debug MessageBox MB_OK "LoadTypeLib returned $R2 with $R0"
Goto exit
cont:
; now R1 contains pointer to typelib
System::Call "Oleaut32::RegisterTypeLib(i, w, i) i (R1, R0, 0) .R2"
; R2 contains result, 0 if ok
IntCmp $R2 0 exit
LogText "RegisterTypeLib returned $R2 with $R1, $R0"
; debug MessageBox MB_OK "RegisterTypeLib returned $R2 with $R1, $R0"
exit:
;; debug MessageBox MB_OK "RegisterTlb: all ok"
Pop $R2 ; R2 restore
Pop $R1 ; R1 restore
Pop $R0 ; R0 restore
FunctionEnd


Please create an archive page for it.