Index: trunk/Include/Classes/ActiveBasic/Strings/SPrintF.ab
===================================================================
--- trunk/Include/Classes/ActiveBasic/Strings/SPrintF.ab	(revision 390)
+++ trunk/Include/Classes/ActiveBasic/Strings/SPrintF.ab	(revision 391)
@@ -818,8 +818,10 @@
 
 	Dim sb = New System.Text.StringBuilder
+	If sb.Length = &hfeeefeee Then Debug
 	With sb
 		Dim prefixFunc = tr.Prefix
 		Dim prefix = prefixFunc(x, flags)
 		sb.Append(prefix)
+		If sb.Length = &hfeeefeee Then Debug
 
 		Dim prefixLen = 0 As DWord
@@ -832,4 +834,5 @@
 		Dim bufStartPos = convertFunc(buf, x, flags)
 
+		If sb.Length = &hfeeefeee Then Debug
 		Dim len = (tr.MaxSize - bufStartPos) As Long
 		If len < 0 Then
@@ -841,6 +844,8 @@
 
 		.Append(buf, bufStartPos + 1, len)
+		If sb.Length = &hfeeefeee Then Debug
 
 		AdjustFieldWidth(sb, field, flags And (Not (Sign Or Blank)), prefixLen)
+		If sb.Length = &hfeeefeee Then Debug
 	End With
 	FormatIntegerEx = sb.ToString()
Index: trunk/Include/Classes/ActiveBasic/Strings/Strings.ab
===================================================================
--- trunk/Include/Classes/ActiveBasic/Strings/Strings.ab	(revision 390)
+++ trunk/Include/Classes/ActiveBasic/Strings/Strings.ab	(revision 391)
@@ -199,6 +199,6 @@
 
 Namespace Detail
-Function Split(s As String, c As StrChar) As System.Collections.ArrayList
-	Split = New System.Collections.ArrayList
+Function Split(s As String, c As StrChar) As System.Collections.Generic.List<String>
+	Split = New System.Collections.Generic.List<String>
 
 	Dim last = 0 As Long
Index: trunk/Include/Classes/System/Exception.ab
===================================================================
--- trunk/Include/Classes/System/Exception.ab	(revision 390)
+++ trunk/Include/Classes/System/Exception.ab	(revision 391)
@@ -3,4 +3,5 @@
 #require <Classes/ActiveBasic/misc.ab>
 
+Namespace ActiveBasic
 '右のコメントは対応するCOR_E_ナントカのコード
 Const AB_E_EXCEPTION = &h80041500 '80131500
@@ -12,4 +13,6 @@
 Const AB_E_NOTSUPPORTED = &h80041515 '80131515
 Const AB_E_PLATFORMNOTSUPPORTED = &h80041539 '80131539
+
+End Namespace
 
 /*
@@ -57,5 +60,5 @@
 	Sub Exception()
 		init(GetType().FullName, Nothing)
-		hr = AB_E_EXCEPTION
+		hr = ActiveBasic.AB_E_EXCEPTION
 	End Sub
 	/*!
@@ -65,5 +68,5 @@
 	Sub Exception(message As String)
 		init(message, Nothing)
-		hr = AB_E_EXCEPTION
+		hr = ActiveBasic.AB_E_EXCEPTION
 	End Sub
 	/*!
@@ -74,5 +77,5 @@
 	Sub Exception(message As String, innerException As Exception)
 		init(message, innerException)
-		hr = AB_E_EXCEPTION
+		hr = ActiveBasic.AB_E_EXCEPTION
 	End Sub
 
@@ -190,5 +193,5 @@
 	Sub SystemException()
 		Exception(GetType().FullName, Nothing)
-		HResult = AB_E_SYSTEM
+		HResult = ActiveBasic.AB_E_SYSTEM
 	End Sub
 	/*!
@@ -198,5 +201,5 @@
 	Sub SystemException(message As String)
 		Exception(message, Nothing)
-		HResult = AB_E_SYSTEM
+		HResult = ActiveBasic.AB_E_SYSTEM
 	End Sub
 	/*!
@@ -207,5 +210,5 @@
 	Sub SystemException(message As String, innerException As Exception)
 		Exception(message, innerException)
-		HResult = AB_E_SYSTEM
+		HResult = ActiveBasic.AB_E_SYSTEM
 	End Sub
 End Class
@@ -224,5 +227,5 @@
 	Sub ArgumentException()
 		SystemException("One or more arguments have invalid value.", Nothing)
-		HResult = AB_E_ARGUMENT
+		HResult = ActiveBasic.AB_E_ARGUMENT
 	End Sub
 	/*!
@@ -232,5 +235,5 @@
 	Sub ArgumentException(message As String)
 		SystemException(message, Nothing)
-		HResult = AB_E_ARGUMENT
+		HResult = ActiveBasic.AB_E_ARGUMENT
 	End Sub
 	/*!
@@ -241,5 +244,5 @@
 	Sub ArgumentException(message As String, innerException As Exception)
 		SystemException(message, innerException)
-		HResult = AB_E_ARGUMENT
+		HResult = ActiveBasic.AB_E_ARGUMENT
 	End Sub
 	/*!
@@ -251,5 +254,5 @@
 		SystemException(message, Nothing)
 		param = paramName
-		HResult = AB_E_ARGUMENT
+		HResult = ActiveBasic.AB_E_ARGUMENT
 	End Sub
 	/*!
@@ -262,5 +265,5 @@
 		SystemException(message, innerException)
 		param = paramName
-		HResult = AB_E_ARGUMENT
+		HResult = ActiveBasic.AB_E_ARGUMENT
 	End Sub
 
@@ -337,5 +340,5 @@
 	Sub ArgumentOutOfRangeException()
 		ArgumentException("One or more arguments ware out of range value.", "", Nothing)
-		HResult = AB_E_ARGUMENTOUTOFRANGE
+		HResult = ActiveBasic.AB_E_ARGUMENTOUTOFRANGE
 	End Sub
 	/*!
@@ -345,5 +348,5 @@
 	Sub ArgumentOutOfRangeException(message As String)
 		ArgumentException(message, "", Nothing)
-		HResult = AB_E_ARGUMENTOUTOFRANGE
+		HResult = ActiveBasic.AB_E_ARGUMENTOUTOFRANGE
 	End Sub
 	/*!
@@ -354,5 +357,5 @@
 	Sub ArgumentOutOfRangeException(message As String, innerException As Exception)
 		ArgumentException(message, "", innerException)
-		HResult = AB_E_ARGUMENTOUTOFRANGE
+		HResult = ActiveBasic.AB_E_ARGUMENTOUTOFRANGE
 	End Sub
 	/*!
@@ -363,5 +366,5 @@
 	Sub ArgumentOutOfRangeException(message As String, paramName As String)
 		ArgumentException(message, paramName, Nothing)
-		HResult = AB_E_ARGUMENTOUTOFRANGE
+		HResult = ActiveBasic.AB_E_ARGUMENTOUTOFRANGE
 	End Sub
 	/*!
@@ -374,5 +377,5 @@
 		ArgumentException(message, paramName, Nothing)
 		actualValueObject = actualValue
-		HResult = AB_E_ARGUMENTOUTOFRANGE
+		HResult = ActiveBasic.AB_E_ARGUMENTOUTOFRANGE
 	End Sub
 
@@ -411,5 +414,5 @@
 	Sub IndexOutOfRangeException()
 		SystemException("The index was out of range value.", Nothing)
-		HResult = AB_E_INDEXOUTOFRANGE
+		HResult = ActiveBasic.AB_E_INDEXOUTOFRANGE
 	End Sub
 	/*!
@@ -419,5 +422,5 @@
 	Sub IndexOutOfRangeException(message As String)
 		SystemException(message, Nothing)
-		HResult = AB_E_INDEXOUTOFRANGE
+		HResult = ActiveBasic.AB_E_INDEXOUTOFRANGE
 	End Sub
 	/*!
@@ -428,5 +431,5 @@
 	Sub IndexOutOfRangeException(message As String, innerException As Exception)
 		SystemException(message, innerException)
-		HResult = AB_E_INDEXOUTOFRANGE
+		HResult = ActiveBasic.AB_E_INDEXOUTOFRANGE
 	End Sub
 End Class
@@ -445,5 +448,5 @@
 	Sub InvalidOperationException()
 		SystemException("The operation is invalid.", Nothing)
-		HResult = AB_E_INVALIDOPERATION
+		HResult = ActiveBasic.AB_E_INVALIDOPERATION
 	End Sub
 	/*!
@@ -453,5 +456,5 @@
 	Sub InvalidOperationException(message As String)
 		SystemException(message, Nothing)
-		HResult = AB_E_INVALIDOPERATION
+		HResult = ActiveBasic.AB_E_INVALIDOPERATION
 	End Sub
 	/*!
@@ -462,6 +465,65 @@
 	Sub InvalidOperationException(message As String, innerException As Exception)
 		SystemException(message, innerException)
-		HResult = AB_E_INVALIDOPERATION
-	End Sub
+		HResult = ActiveBasic.AB_E_INVALIDOPERATION
+	End Sub
+End Class
+
+/*!
+@brief	博されたオブジェクトを操作しようとしたことを表す例外
+@author	Egtra
+@date	2007/12/06
+*/
+Class ObjectDisposedException
+	Inherits InvalidOperationException
+Public
+	/*!
+	@biref	コンストラクタ
+	*/
+	Sub ObjectDisposedException()
+		InvalidOperationException("The object has been disposed.", Nothing)
+		HResult = ActiveBasic.AB_E_INVALIDOPERATION
+	End Sub
+	/*!
+	@biref	コンストラクタ
+	@param[in] message	エラーメッセージ
+	*/
+	Sub ObjectDisposedException(message As String)
+		InvalidOperationException(message, Nothing)
+		HResult = ActiveBasic.AB_E_INVALIDOPERATION
+	End Sub
+	/*!
+	@biref	コンストラクタ
+	@param[in] message	エラーメッセージ
+	@param[in] innerException	内部例外
+	*/
+	Sub ObjectDisposedException(message As String, innerException As Exception)
+		InvalidOperationException(message, innerException)
+		HResult = ActiveBasic.AB_E_INVALIDOPERATION
+	End Sub
+	/*!
+	@biref	コンストラクタ
+	@param[in] objectName	操作しようとしたオブジェクトの名前
+	@param[in] message	エラーメッセージ
+	*/
+	Sub ObjectDisposedException(objectName As String, message As String)
+		InvalidOperationException(message, Nothing)
+		HResult = ActiveBasic.AB_E_INVALIDOPERATION
+		objName = " object: " + objectName
+	End Sub
+	/*!
+	@brief	この例外が発生したとき、操作しようとしていたオブジェクトの名前を返す。
+	*/
+	Function ObjectName() As String
+		Return objName
+	End Function
+
+	Override Function ToString() As String
+		ToString = Super.ToString()
+		If Not ActiveBasic.IsNothing(objName) Then
+			ToString += objName
+		End If
+	End Function
+Private
+	objName As String
 End Class
 
@@ -513,5 +575,5 @@
 	Sub NotSupportedException()
 		SystemException("This operation is not supported,", Nothing)
-		HResult = AB_E_NOTSUPPORTED
+		HResult = ActiveBasic.AB_E_NOTSUPPORTED
 	End Sub
 	/*!
@@ -521,5 +583,5 @@
 	Sub NotSupportedException(message As String)
 		SystemException(message, Nothing)
-		HResult = AB_E_NOTSUPPORTED
+		HResult = ActiveBasic.AB_E_NOTSUPPORTED
 	End Sub
 	/*!
@@ -530,5 +592,5 @@
 	Sub NotSupportedException(message As String, innerException As Exception)
 		SystemException(message, innerException)
-		HResult = AB_E_NOTSUPPORTED
+		HResult = ActiveBasic.AB_E_NOTSUPPORTED
 	End Sub
 End Class
@@ -547,5 +609,5 @@
 	Sub PlatformNotSupportedException()
 		NotSupportedException("This operation is not supported in this platform.", Nothing)
-		HResult = AB_E_PLATFORMNOTSUPPORTED
+		HResult = ActiveBasic.AB_E_PLATFORMNOTSUPPORTED
 	End Sub
 	/*!
@@ -555,5 +617,5 @@
 	Sub PlatformNotSupportedException(message As String)
 		NotSupportedException(message, Nothing)
-		HResult = AB_E_PLATFORMNOTSUPPORTED
+		HResult = ActiveBasic.AB_E_PLATFORMNOTSUPPORTED
 	End Sub
 	/*!
@@ -564,5 +626,5 @@
 	Sub PlatformNotSupportedException(message As String, innerException As Exception)
 		NotSupportedException(message, innerException)
-		HResult = AB_E_PLATFORMNOTSUPPORTED
+		HResult = ActiveBasic.AB_E_PLATFORMNOTSUPPORTED
 	End Sub
 End Class
Index: trunk/Include/Classes/System/IO/Exception.ab
===================================================================
--- trunk/Include/Classes/System/IO/Exception.ab	(revision 391)
+++ trunk/Include/Classes/System/IO/Exception.ab	(revision 391)
@@ -0,0 +1,81 @@
+/*!
+@file
+@brief	System.IOに属す例外クラスの定義
+*/
+
+Namespace ActiveBasic
+
+Const AB_E_IO = &h80041620 '80131620
+
+End Namespace
+
+Namespace System
+Namespace IO
+
+/*!
+@brief	IO処理に関する例外のクラス
+@author	Egtra
+@date	2007/12/06
+*/
+Class IOException
+	Inherits SystemException
+Public
+	/*!
+	@biref	コンストラクタ
+	*/
+	Sub IOException()
+		Exception(GetType().FullName, Nothing)
+		HResult = ActiveBasic.AB_E_IO
+	End Sub
+	/*!
+	@biref	コンストラクタ
+	@param[in] message	エラーメッセージ
+	*/
+	Sub IOException(message As String)
+		Exception(message, Nothing)
+		HResult = ActiveBasic.AB_E_IO
+	End Sub
+	/*!
+	@biref	コンストラクタ
+	@param[in] message	エラーメッセージ
+	@param[in] innerException	内部例外
+	*/
+	Sub IOException(message As String, innerException As Exception)
+		Exception(message, innerException)
+		HResult = ActiveBasic.AB_E_IO
+	End Sub
+	/*!
+	@biref	コンストラクタ
+	@param[in] message	エラーメッセージ
+	@param[in] hr	HRESULT例外値
+	*/
+	Sub IOException(message As String, hr As HRESULT)
+		Exception(message, Nothing)
+		HResult = hr
+	End Sub
+End Class
+
+Namespace Detail
+	/*!
+	@brief	Windowsエラー値を基にIOExceptionを投げる。
+	@param[in] message	エラーメッセージ
+	@author	Egtra
+	@date	2007/12/06
+	*/
+	Sub ThrowWinIOException(msg As String, error As DWord)
+'		Throw IOException(msg, HRESULT_FROM_WIN32(error))
+	End Sub
+
+	/*!
+	@brief	GetLastError()の値を基にIOExceptionを投げる。
+	@param[in] message	エラーメッセージ
+	@author	Egtra
+	@date	2007/12/06
+	*/
+	Sub ThrowWinLastErrorIOException(msg As String)
+'		Throw IOException(msg, HRESULT_FROM_WIN32(GetLastError()))
+	End Sub
+End Namespace
+
+End Namespace 'IO
+End Namespace 'System
Index: trunk/Include/Classes/System/IO/FileStream.ab
===================================================================
--- trunk/Include/Classes/System/IO/FileStream.ab	(revision 390)
+++ trunk/Include/Classes/System/IO/FileStream.ab	(revision 391)
@@ -4,11 +4,11 @@
 /* ほんとはmiscに入れるかかファイルを分けたほうがいいかもしれないが一先ず実装 */
 Enum FileOptions
-	Asynchronous
-	DeleteOnClose
-	Encrypted
-	None
-	RandomAccess
-	SequentialScan
-	WriteThrough 
+	None = 0
+	Asynchronous = FILE_FLAG_OVERLAPPED
+	DeleteOnClose = FILE_FLAG_DELETE_ON_CLOSE
+	Encrypted = FILE_ATTRIBUTE_ENCRYPTED
+	RandomAccess = FILE_FLAG_RANDOM_ACCESS
+	SequentialScan = FILE_FLAG_SEQUENTIAL_SCAN
+	WriteThrough = FILE_FLAG_WRITE_THROUGH
 End Enum
 
@@ -75,21 +75,10 @@
 		End Select
 
-		Select Case options
-			Case FileOptions.Asynchronous
-				op=FILE_FLAG_OVERLAPPED
-			Case FileOptions.DeleteOnClose
-				op=FILE_FLAG_DELETE_ON_CLOSE
-			Case FileOptions.Encrypted
-			Case FileOptions.None
-				op=0
-			Case FileOptions.RandomAccess
-				op=FILE_FLAG_RANDOM_ACCESS
-			Case FileOptions.SequentialScan
-				op=FILE_FLAG_SEQUENTIAL_SCAN
-			Case FileOptions.WriteThrough
-				op=FILE_FLAG_WRITE_THROUGH
-		End Select
-
-		This.handle=CreateFile(path As PSTR,ac,sh,ByVal NULL,mo,op,0)
+		op = options As DWord
+		If Not Environment.OSVersion.Platform = PlatformID.Win32NT Then
+			op And= Not FILE_FLAG_OVERLAPPED
+		End If
+
+		This.handle=CreateFile(ToTCStr(path),ac,sh,ByVal NULL,mo,op,0)
 		If This.handle=INVALID_HANDLE_VALUE Then
 		'エラー処理
@@ -134,6 +123,8 @@
 	End Sub
 Public
+	/*!
+	@brief	ファイルが読み込みに対応しているかを返す
+	*/
 	Override Function CanRead() As Boolean
-		/* ファイルが読み込みに対応しているかを返す */
 		If This.fileAccess And GENERIC_READ Then
 			Return True
@@ -143,6 +134,8 @@
 	End Function
 
+	/*!
+	@brief	ファイルがシークに対応しているかを返す
+	*/
 	Override Function CanSeek() As Boolean
-		/* ファイルがシークに対応しているかを返す */
 		If GetFileType(This.handle)=FILE_TYPE_DISK Then
 			Return True
@@ -157,6 +150,8 @@
 '	End Function*/
 
+	/*!
+	@brief	ファイルが書き込みに対応しているかを返す
+	*/
 	Override Function CanWrite() As Boolean
-		/* ファイルが書き込みに対応しているかを返す */
 		If This.fileAccess And GENERIC_WRITE Then
 			Return True
@@ -168,6 +163,8 @@
 	/*Handle*/
 
+	/*!
+	@brief	ファイルが非同期操作に対応しているかを返す
+	*/
 	Function IsAsync() As Boolean
-		/* ファイルが非同期操作に対応しているかを返す */
 		If This.fileOptions And FILE_FLAG_OVERLAPPED /*FileOptions.Asynchronous*/ Then
 			Return True
@@ -178,8 +175,18 @@
 
 	Override Function Length() As Int64
+		disposedCheck()
 		If This.CanSeek() Then
-			Dim length As LARGE_INTEGER
-			length.LowPart=GetFileSize(This.handle,VarPtr(length.HighPart) As *DWord)
-			Return MAKEQWORD(length.LowPart,length.HighPart) As Int64
+			Dim length = VarPtr(Length) As *ULARGE_INTEGER
+			length->LowPart = GetFileSize(This.handle, VarPtr(length->HighPart))
+			If LODWORD(Length) = INVALID_FILE_SIZE Then
+				Dim error = GetLastError()
+				If error <> NO_ERROR Then
+'					Detail.ThrowWinIOException("FileStream.Read: Failed to read.", error)
+				End If
+			End If
+			
+			If Length < 0 Then
+				Debug 'Throw OverflowException
+			End If
 		End If
 	End Function
@@ -190,4 +197,5 @@
 	
 	Override Sub Position(value As Int64)
+		disposedCheck()
 		If This.CanSeek() Then
 			If This.IsAsync() Then
@@ -202,4 +210,5 @@
 	End Sub
 	Override Function Position() As Int64
+		disposedCheck()
 		If This.CanSeek() Then
 			If This.IsAsync() Then
@@ -266,5 +275,9 @@
 
 	Override Sub Flush()
-		FlushFileBuffers(This.handle)
+		disposedCheck()
+		Dim ret = FlushFileBuffers(This.handle)
+		If ret = FALSE Then
+'			Detail.ThrowWinLastErrorIOException("FileStream.Read: Failed to read.")
+		End If
 	End Sub
 
@@ -273,8 +286,4 @@
 	End Function*/
 
-	Override Function GetHashCode() As Long
-		Return ObjPtr(This) As Long
-	End Function
-
 /*	GetLifetimeService*/
 
@@ -286,4 +295,5 @@
 
 	Sub Lock(position As Int64, length As Int64)
+		disposedCheck()
 		If position < 0 Then
 			Throw New ArgumentOutOfRangeException("FileStream.Lock: An argument is negative value.", New System.Int64(position), "position")
@@ -296,26 +306,56 @@
 
 	Override Function Read( buffer As *Byte, offset As Long, count As Long) As Long
-		If This.CanRead() Then
-			Dim readBytes As DWord
-			If This.IsAsync() Then
-				Dim overlapped As OVERLAPPED
-				SetQWord(VarPtr(overlapped.Offset), offset)
-				Dim ret = ReadFile(This.handle, VarPtr(buffer[offset]), count, 0, overlapped)
+		disposedCheck()
+		If buffer = 0 Then
+'			Throw ArgumentNullException("FileStream.Read: An argument is null value.", "buffer")
+		ElseIf Not This.CanRead() Then
+'			Throw NotSupportedException("FileStream.Read: This stream is not readable.")
+		End If
+
+		Dim ret As BOOL
+		Dim readBytes As DWord
+		If This.IsAsync() Then
+			Dim overlapped As OVERLAPPED
+			SetQWord(VarPtr(overlapped.Offset), offset)
+			overlapped.hEvent = CreateEvent(0, TRUE, FALSE, 0)
+			If overlapped.hEvent = 0 Then
+'				Throw OutOfMemoryException("FileStream.Read: Failed to create an event object.")
+			End If
+			Try
+				ret = ReadFile(This.handle, VarPtr(buffer[offset]), count, 0, overlapped)
 				If ret = FALSE Then
-					If GetLastError() = ERROR_IO_PENDING Then
-						GetOverlappedResult(This.handle, overlapped, readBytes, TRUE)
+					Dim error = GetLastError()
+					If error <> ERROR_IO_PENDING Then
+'						Detail.ThrowWinIOException("FileStream.Read: Failed to read.", error)
 					End If
 				End If
+				ret = GetOverlappedResult(This.handle, overlapped, readBytes, TRUE)
+				If ret = FALSE Then
+'					Detail.ThrowWinLastErrorIOException("FileStream.Read: Failed to read.")
+				End If
 				offset += Read
-			Else
-				ReadFile(This.handle,VarPtr(buffer[offset]),count,VarPtr(readBytes),ByVal NULL)
-			End If
-			Read = readBytes As Long
-		End If
-	End Function
-
-/*	ReferenceEquals*/
-
-	Override Function Seek(offset As Int64, origin As SeekOrigin) As Long
+			Finally
+				CloseHandle(overlapped.hEvent)
+			End Try
+		Else
+			ret = ReadFile(This.handle,VarPtr(buffer[offset]),count,VarPtr(readBytes),ByVal NULL)
+			If ret = FALSE Then
+'				Detail.ThrowWinLastErrorIOException("FileStream.Read: Failed to read.")
+			End If
+		End If
+		Read = readBytes As Long
+	End Function
+
+	/*!
+	@brief	ストリームの現在位置を移動させる。
+	@param[in] offset	originからの移動量
+	@param[in] origin	移動の基準位置
+	@return	移動後の新しい現在位置
+	@exception DisposedException	既にストリームが閉じられている場合
+	@exception ArgumentException	移動後の位置が負の位置（ファイル先頭より手前）になる場合
+	@exception IOException	その他エラーが発生した場合
+	*/
+	Override Function Seek(offset As Int64, origin As SeekOrigin) As Int64
+		disposedCheck()
 		If This.CanSeek() Then
 			If This.IsAsync() Then
@@ -328,16 +368,21 @@
 						This.offset = This.Length + offset
 				End Select
+				Seek = This.offset As Int64
+				If Seek < 0 Then
+'					Throw ArgumentException("FileStream.Seek: Cannot seek to negative offset.")
+				End If
 			Else
-				Dim seek As LARGE_INTEGER
-				seek.LowPart=LODWORD(offset)
-				seek.HighPart=HIDWORD(offset)
-				Select Case origin
-					Case SeekOrigin.Begin
-						Return SetFilePointer(This.handle,seek.LowPart,VarPtr(seek.HighPart) As *DWord,FILE_BEGIN)
-					Case SeekOrigin.Current
-						Return SetFilePointer(This.handle,seek.LowPart,VarPtr(seek.HighPart) As *DWord,FILE_CURRENT)
-					Case SeekOrigin.End
-						Return SetFilePointer(This.handle,seek.LowPart,VarPtr(seek.HighPart) As *DWord,FILE_CURRENT)
-				End Select
+				Dim seek = VarPtr(offset) As *ULARGE_INTEGER
+				Dim ret = SetFilePointer(This.handle, seek->LowPart, VarPtr(seek->HighPart), origin As DWord)
+				If ret = INVALID_SET_FILE_POINTER Then
+					Dim error = GetLastError()
+					If error = ERROR_NEGATIVE_SEEK Then
+'						Throw ArgumentException("FileStream.Seek: Cannot seek to negative offset.")
+					ElseIf error <> NO_ERROR Then
+'						Throw Detail.ThrowWinIOException("FileStream.Seek: Failed to seek.", error)
+					End If
+				End If
+				seek->LowPart = ret
+				Seek = offset
 			End If
 		End If
@@ -349,4 +394,5 @@
 
 	Override Sub SetLength(value As Int64)
+		disposedCheck()
 		If This.CanWrite() and This.CanSeek() Then
 			If This.IsAsync() Then
@@ -354,5 +400,9 @@
 				Dim current = This.Position()
 				This.Position(value)
-				SetEndOfFile(This.handle)
+				Dim ret = SetEndOfFile(This.handle)
+				If ret = FALSE Then
+					Detail.ThrowWinLastErrorIOException("FileStream.Read: Failed to read.")
+				End If
+				Position = current
 			End If
 		End If
@@ -366,4 +416,5 @@
 
 	Sub Unlock(position As Int64, length As Int64)
+		disposedCheck()
 		If position < 0 Then
 			Throw New ArgumentOutOfRangeException("FileStream.Lock: An argument is negative value.", New System.Int64(position), "position")
@@ -371,10 +422,13 @@
 			Throw New ArgumentOutOfRangeException("FileStream.Lock: An argument is negative value.", New System.Int64(length), "length")
 		End If
-		UnlockFile(handle, LODWORD(position As QWord), HIDWORD(position As QWord),
+		Dim ret = UnlockFile(handle, LODWORD(position As QWord), HIDWORD(position As QWord),
 			LODWORD(length As QWord), HIDWORD(length As QWord))
-	End Sub
-
+		If ret = FALSE Then
+			Detail.ThrowWinLastErrorIOException("FileStream.Read: Failed to read.")
+		End If
+	End Sub
 
 	Override Sub Write(buffer As *Byte, offset As Long, count As Long)
+		disposedCheck()
 		If This.CanWrite() Then
 			Dim writeBytes As DWord
@@ -382,11 +436,11 @@
 				Dim overlapped As OVERLAPPED
 				SetQWord(VarPtr(overlapped.Offset), offset)
+				overlapped.hEvent = CreateEvent(0, TRUE, FALSE, 0)
 				Dim ret = WriteFile(This.handle, VarPtr(buffer[offset]), count, 0, overlapped)
-				If ret = FALSE Then
-					If GetLastError() = ERROR_IO_PENDING Then
-						GetOverlappedResult(This.handle, overlapped, writeBytes, TRUE)
-					End If
+				If ret <> FALSE Or GetLastError() = ERROR_IO_PENDING Then
+					GetOverlappedResult(This.handle, overlapped, writeBytes, TRUE)
 				End If
 				offset += writeBytes
+				CloseHandle(overlapped.hEvent)
 			Else
 				WriteFile(This.handle, VarPtr(buffer[offset]), count, VarPtr(writeBytes), ByVal NULL)
@@ -394,5 +448,4 @@
 		End If
 	End Sub
-
 
 Protected
@@ -405,8 +458,11 @@
 	End Function
 
-/*	Dispose
-	Finalize
-	MemberwiseClone*/
 Private
+	Sub disposedCheck()
+		If handle = 0 Then
+'			Throw ObjectDisposedException("FileStream: This stream has closed.")
+		End If
+	End Sub
+
 End Class
 
Index: trunk/Include/Classes/System/IO/Stream.ab
===================================================================
--- trunk/Include/Classes/System/IO/Stream.ab	(revision 390)
+++ trunk/Include/Classes/System/IO/Stream.ab	(revision 391)
@@ -70,5 +70,5 @@
 	End Function
 
-	Abstract Function Seek(offset As Int64, origin As SeekOrigin) As Long
+	Abstract Function Seek(offset As Int64, origin As SeekOrigin) As Int64
 	Abstract Sub SetLength(value As Int64)
 	Abstract Sub Write(buffer As *Byte, offset As Long, count As Long)
Index: trunk/Include/Classes/System/IO/misc.ab
===================================================================
--- trunk/Include/Classes/System/IO/misc.ab	(revision 390)
+++ trunk/Include/Classes/System/IO/misc.ab	(revision 391)
@@ -1,9 +1,10 @@
 
-TypeDef /* [Delegate] */ AsyncCallback = *Sub(ByRef ar As System.IAsyncResult)
+Namespace System
+Namespace IO
 
 Enum SeekOrigin
-	Begin
-	Current
-	End
+	Begin = FILE_BEGIN
+	Current = FILE_CURRENT
+	End = FILE_END
 End Enum
 
@@ -12,2 +13,5 @@
 	TopDirectoryOnly
 End Enum
+
+End Namespace 'IO
+End Namespace 'System
Index: trunk/Include/Classes/System/String.ab
===================================================================
--- trunk/Include/Classes/System/String.ab	(revision 390)
+++ trunk/Include/Classes/System/String.ab	(revision 391)
@@ -347,5 +347,5 @@
 		Const Function Contains(s As String) As Boolean
 			If Object.ReferenceEquals(s, Nothing) Then
-				Throw New ArgumentNullException("String.Contains: An argument is out of range value.", "s")
+				Throw New ArgumentNullException("String.Contains: An argument is null value.", "s")
 			ElseIf s = "" Then
 				Return True
Index: trunk/Include/Classes/System/misc.ab
===================================================================
--- trunk/Include/Classes/System/misc.ab	(revision 390)
+++ trunk/Include/Classes/System/misc.ab	(revision 391)
@@ -11,5 +11,5 @@
 	' Properties
 	Function AsyncState() As Object
-	Function AsyncWaitHandle() As System.Threading.WaitHandle
+	Function AsyncWaitHandle() As Threading.WaitHandle
 	Function CompletedSynchronously() As Boolean
 	Function IsCompleted() As Boolean
@@ -36,4 +36,8 @@
 End Class
 
+'Delegate Sub AsyncCallback(ar As IAsyncResult)
+Delegate Sub AsyncCallback(ar As VoidPtr)
+
+
 End Namespace 'System
 #require <Classes/System/Threading/WaitHandle.ab>
Index: trunk/Include/Classes/index.ab
===================================================================
--- trunk/Include/Classes/index.ab	(revision 390)
+++ trunk/Include/Classes/index.ab	(revision 391)
@@ -58,4 +58,5 @@
 #require "./System/IO/DirectorySecurity.ab"
 #require "./System/IO/DriveInfo.ab"
+#require "./System/IO/Exception.ab"
 #require "./System/IO/File.ab"
 #require "./System/IO/FileInfo.ab"
Index: trunk/Include/basic/command.sbp
===================================================================
--- trunk/Include/basic/command.sbp	(revision 390)
+++ trunk/Include/basic/command.sbp	(revision 391)
@@ -158,6 +158,5 @@
 	
 	Dim i = 0 As Long
-	Dim i2 As Long, i3 As Long
-	Dim buffer = New System.Text.StringBuilder(GetFileSize(_System_hFile[FileNumber], 0) + 1)
+	Dim buffer = New System.Text.StringBuilder(256)
 	Dim temp[1] As StrChar
 	Dim dwAccessBytes As DWord
@@ -167,6 +166,6 @@
 		'次のデータをサーチ
 		Do
-			i2=ReadFile(_System_hFile[FileNumber],temp,SizeOf (StrChar),VarPtr(dwAccessBytes),ByVal 0)
-			If i2=0 or dwAccessBytes=0 Then
+			Dim ret = ReadFile(_System_hFile[FileNumber],temp,SizeOf (StrChar),VarPtr(dwAccessBytes),ByVal 0)
+			If ret=0 or dwAccessBytes=0 Then
 				'error
 				Exit Macro
@@ -176,11 +175,8 @@
 
 		'読み込み
-		i3=-1
 		IsStr=0
 		While 1
-			i3++
-
-			i2=ReadFile(_System_hFile[FileNumber],temp,SizeOf (StrChar),VarPtr(dwAccessBytes),ByVal 0)
-			If i2=0 or (i3=0 and dwAccessBytes=0) Then
+			Dim ret = ReadFile(_System_hFile[FileNumber],temp,SizeOf (StrChar),VarPtr(dwAccessBytes),ByVal 0)
+			If ret = 0 or dwAccessBytes = 0 Then
 				'error
 				Exit Macro
@@ -188,5 +184,5 @@
 			If temp[0]=34 Then IsStr=IsStr xor 1
 
-			buffer[i3]=temp[0]
+			buffer.Append(temp[0])
 			If dwAccessBytes=0 or temp[0]=0 or temp[0]=13 or temp[0]=10 or (IsStr=0 and temp[0]=Asc(",")) or (IsStr=0 and (temp[0]=32 or temp[0]=9) and _System_InputDataType[i]<>_System_Type_String) Then
 				If temp[0]=13 Then
@@ -210,5 +206,5 @@
 				End If
 
-				buffer[i3]=0
+				buffer.Append(0 As StrChar)
 				Exit While
 			End If
Index: trunk/Include/basic/dos_console.sbp
===================================================================
--- trunk/Include/basic/dos_console.sbp	(revision 390)
+++ trunk/Include/basic/dos_console.sbp	(revision 391)
@@ -40,5 +40,5 @@
 			Goto *InputReStart
 		End If
-		_System_Input_SetArgument(_System_InputDataPtr[i], _System_InputDataType[i], broken[i].ToString)
+		_System_Input_SetArgument(_System_InputDataPtr[i], _System_InputDataType[i], broken[i])
 	Next
 
Index: trunk/Include/system/debug.sbp
===================================================================
--- trunk/Include/system/debug.sbp	(revision 390)
+++ trunk/Include/system/debug.sbp	(revision 391)
@@ -29,4 +29,8 @@
 End Function
 
+/*!
+@brief デバッグ用Set_LONG_PTR。
+削除すると、ABプログラムが正常にデバッグ実行できなくなる。
+*/
 Sub _DebugSys_Set_LONG_PTR(pPtr As VoidPtr, lpData As LONG_PTR)
 #ifdef _WIN64
