
;--- macros:
;--- CStr()
;--- CStrW()
;--- return
;--- @AdjustThis
;--- @MakeIUnknownStubs

ifndef CStr

;--- CStr() define a string in .CONST
;--- or in .CONST$2 if .CONST is the current section

CStr macro y:VARARG
local sym
ifidni @CurSeg,<CONST>
CONST$2 segment public FLAT 'CONST'
else
CONST segment public FLAT 'CONST'
endif
  ifidni <y>,<"">
    sym db 0
  else
    sym db y,0
  endif
ifidni @CurSeg,<CONST$2>
CONST$2 ends
else
CONST ends
endif
	exitm <offset sym>
	endm

endif

;--- CStrW defines a wide string in .CONST
;--- returns a pointer to that string

CStrW macro y:req
local sym

ifidni @CurSeg,<CONST>
CONST$2 segment public 'CONST'
else
CONST segment public 'CONST'
endif
	align 2
sym dw y,0
@CurSeg ends
	exitm <offset sym>
	endm

;--- return: return a value in eax

ifndef return

return macro x
ifnb <x>
 if (OPATTR x) eq 4	;;constant?
  if x
	mov eax,x
  else
	xor eax,eax
  endif
 else
	mov eax,x
 endif
endif
	ret
	endm

endif	;return

;--- @AdjustThis: used for multiple inheritance
;--- mainly in COM objects. If there exist more than one
;--- vtable, this_ ptr has to be adjusted

@AdjustThis macro
if CastOffset
	sub this_,CastOffset
endif
	endm

;--- @MakeIUnknownStubs: used for multiple inheritance
;--- in COM objects. adjust this_ ptr, then call standard IUnknown method

@MakeIUnknownStubs macro objofs, suffix
QueryInterface_&suffix::
if objofs
	sub dword ptr [esp+4],objofs
endif
	jmp QueryInterface
	align 4
AddRef_&suffix::
if objofs
	sub dword ptr [esp+4],objofs
endif
	jmp AddRef
	align 4
Release_&suffix::
if objofs
	sub dword ptr [esp+4],objofs
endif
	jmp Release
	endm

