#include once "window9.bi"

#ifdef UNICODE
	Function Read_String(ByVal H As handle) As USTRING Export
		Dim bBuf As Short
		Dim iRetBytes As ulong
		Dim sRet As USTRING
		Do
			ReadFile(H, @bBuf, 2, Cast(LPDWORD,@iRetBytes), 0)
			If bBuf<>13 and bBuf<>10 Then
				If iRetBytes=0 Then Exit do
				sRet = sRet & WChr(bBuf)
			EndIf
			If iRetBytes=0 Or bBuf=10 Then Exit do
		Loop
		Return sRet
	End Function	
#else	
	Function Read_String(ByVal H As handle) As USTRING Export
		Dim bBuf As Byte
		Dim iRetBytes As ulong
		Dim sRet As USTRING
		Do
			ReadFile(H, @bBuf, 1, Cast(LPDWORD,@iRetBytes), 0)
			If bBuf<>13 and bBuf<>10 Then
				If iRetBytes=0 Then Exit do
				sRet = sRet & Chr(bBuf)
			EndIf
			If iRetBytes=0 Or bBuf=10 Then Exit do
		Loop
		Return sRet
	End Function	
#EndIf
