!searchreplace BASENAME "${__FILE__}" ".nsi" ""
OutFile `${BASENAME}.exe`
Name `${BASENAME}`
Caption "$(^Name)"
ShowInstDetails show

!macro _GetErrorCode dwMessageId
	System::Call Kernel32::FormatMessage(i0x00000100|0x00001000|0x00000200,,i${dwMessageId},i0x0400,*i.r1,,)i.r0
	IntOp $0 $0 - 2
	System::Call *$1(&t$0.r0)
	System::Call Kernel32::LocalFree(ir1)
!macroend
!macro GetErrorCode RETURN_VALUE
	Push ${RETURN_VALUE}
	System::Store sR0R1
	!insertmacro _GetErrorCode R0
	DetailPrint 'Return Value = $0'
	!insertmacro _GetErrorCode R1
	DetailPrint 'last-error code = $0'
	System::Store l
!macroend

!define COM_CallMethod "!insertmacro _COM_CallMethod "
!macro _COM_CallMethod _vto _ParamsDecl _IFacePtr _Params
	System::Call `${_IFacePtr}->${_vto}${_ParamsDecl} ${_Params}`
!macroend

!define ITypeLib->GetLibAttr "${COM_CallMethod}7 (i)i. "
!define ITypeLib->ReleaseTLibAttr "${COM_CallMethod}12 ()i. "

Section
	StrCpy $0 msxml.dll
	DetailPrint LoadTypeLib()
	System::Call Oleaut32::LoadTypeLib(wr0,*i.r1)i.r2?e
	!insertmacro GetErrorCode $2

	DetailPrint ITypeLib->GetLibAttr
	System::call *(g,i,i,i,i,i)i.R0 ;  TLIBATTR  structure
	${ITypeLib->GetLibAttr} $1 (R0).r2?e
	!insertmacro GetErrorCode $2

	System::Call *$R0(g.R1,i.R2,i.R3,i.R4,i.R5,i.R6)
	${ITypeLib->ReleaseTLibAttr} $1 ()
	System::free $R0
;	TypeLib::GetLibVersion $0
;	Pop $R5
;	Pop $R4

	DetailPrint 'TLIBATTR structure'
	DetailPrint GUID=$R1
	DetailPrint CLID=$R2
	DetailPrint SYSKIND=$R3
	DetailPrint MajorVerNum=$R4
	DetailPrint MinorVerNum=$R5
	DetailPrint LibFlags=$R6
	ReadRegStr $0 HKLM SOFTWARE\Classes\TypeLib\$R1\$R4.$R5 ''
	DetailPrint Name=$0
	ReadRegStr $0 HKLM SOFTWARE\Classes\TypeLib\$R1\$R4.$R5\0\Win32 ''
	DetailPrint Path=$0
SectionEnd
