#include once "window9.bi"

Function GetGadgetText(ByVal gadget As long) As USTRING Export
	var nChars = GetWindowTextLength(GadgetID(gadget))
	dim as USTRING sTemp
	if nChars<1 then return sTemp	
	#ifdef UNICODE		
		dim as USTRING sRet = WSPACE(nChars+1)
		SendMessage(GadgetID(gadget),WM_GETTEXT,nChars+1,Cast(LPARAM,*sRet))
		return sRet	
	#else
		dim as zstring ptr pText = allocate(nChars+1)
		if pText then
			pText[nChars]=0
			SendMessage(GadgetID(gadget),WM_GETTEXT,nChars+1,Cast(LPARAM,pText))
			Function = PeekS(pText)
			deallocate(pText)
		endif
	#EndIf
End Function
