#include once "window9.bi"

#ifdef UNICODE
	Function PeekS(ByVal Memory As Any Ptr, byval iLen As Integer) As USTRING Export
		Dim sRetString As USTRING
		Dim iCountBytes As Integer
		If iLen = 0 Then
			While TRUE
				If *Cast(byte Ptr,(Memory+iCountBytes))<>0 Then
					iCountBytes+=2
				Else
					Exit While
				EndIf
			Wend
		Else
			iCountBytes = iLen
		EndIf
		If iCountBytes<>0 Then
			sRetString = WSpace(iCountBytes+1)
			CopyMemory(cast(any ptr , *sRetString), Memory ,iCountBytes*2)
		EndIf
		Return sRetString
	End Function	
#else	
	Function PeekS(ByVal Memory As Any Ptr, byval iLen As Integer) As USTRING Export
		Dim sRetString As USTRING
		Dim iCountBytes As Integer
		If iLen = 0 Then
			While TRUE
				If *Cast(Byte Ptr,(Memory+iCountBytes))<>0 Then
					iCountBytes+=1
				Else
					Exit While
				EndIf
			Wend
		Else
			iCountBytes = iLen
		EndIf
		If iCountBytes<>0 Then
			sRetString = Space(iCountBytes)
			CopyMemory(SAdd(sRetString),Cast(Byte Ptr,Memory),iCountBytes)
			Return sRetString
		EndIf
	End Function	
#EndIf

