Index: /trunk/Include/Classes/ActiveBasic/Windows/CriticalSection.ab
===================================================================
--- /trunk/Include/Classes/ActiveBasic/Windows/CriticalSection.ab	(revision 410)
+++ /trunk/Include/Classes/ActiveBasic/Windows/CriticalSection.ab	(revision 411)
@@ -9,5 +9,5 @@
 
 Class CriticalSection
-'	Inherits System.IDisposable
+	Implements System.IDisposable
 Public
 	Sub CriticalSection()
@@ -20,5 +20,5 @@
 	End Sub
 
-	/*Override*/ Sub Dispose()
+	Sub Dispose()
 		If InterlockedIncrement(disposed) = 0 Then
 			DeleteCriticalSection(cs)
Index: /trunk/Include/Classes/System/Exception.ab
===================================================================
--- /trunk/Include/Classes/System/Exception.ab	(revision 410)
+++ /trunk/Include/Classes/System/Exception.ab	(revision 411)
@@ -13,4 +13,5 @@
 Const AB_E_NOTSUPPORTED = &h80041515 '80131515
 Const AB_E_PLATFORMNOTSUPPORTED = &h80041539 '80131539
+Const AB_E_KEYNOTFOUND = &h80041577 '80131577
 
 End Namespace
Index: /trunk/Include/Classes/System/Text/DecoderFallback.ab
===================================================================
--- /trunk/Include/Classes/System/Text/DecoderFallback.ab	(revision 411)
+++ /trunk/Include/Classes/System/Text/DecoderFallback.ab	(revision 411)
@@ -0,0 +1,227 @@
+/*!
+@file	Classes/System/IO/Fallback.ab
+@date	2007/12/09
+*/
+
+Namespace System
+Namespace Text
+
+/*!
+@brief	復号時、復号できないバイト並びに遭遇したときの処理を提供する
+@date	2007/12/09
+@auther	Egtra
+*/
+Class DecoderFallback
+Public
+	/*!
+	@brief	フォールバックを行う
+	@param[in] bytesUnknown	復号中の文字列
+	@param[in] len	bytesUnknownの要素数
+	@param[in] index	問題の列の開始位置
+	@param[out] bufLen	戻り値の要素数
+	@return フォールバック文字列
+	*/
+	Abstract Function Fallback(bytesUnknown As *Byte, len As Long, index As Long, ByRef bufLen As Long) As *WCHAR
+
+	/*!
+	@brief	このDecoderFallbackの処理で生成される可能性のある最大の文字列の長さを返す。
+	*/
+	Abstract Function MaxCharCount() As Long
+
+	/*!
+	@brief	フォールバックとして、例外を投げるDecoderFallbackを返す。
+	@bug	未実装
+	*/
+	Static Function ExceptionFallback() As DecoderFallback
+	End Function
+
+	/*!
+	@brief	フォールバックとして、適当な文字に変換するDecoderFallbackを返す。
+	*/
+	Static Function ReplacementFallback() As DecoderFallback
+		ReplacementFallback = replacementFallback
+	End Function
+
+Private
+	Static replacementFallback = New DecoderReplacementFallback
+End Class
+
+/*!
+@brief	復号時、復号できないバイト並びに遭遇したときの処理を提供する
+@date	2007/12/09
+@auther	Egtra
+*/
+Class DecoderReplacementFallback
+	Inherits DecoderFallback
+Public
+	/*!
+	@brief	既定のフォールバック文字列でDecoderReplacementFallbackを構築する。
+	*/
+	Sub DecoderReplacementFallback()
+		str = VarPtr(default)
+		len = 1
+	End Sub
+
+	/*!
+	@brief	指定された文字列でDecoderReplacementFallbackを構築する。
+	@param[in] replacement	代替文字列
+	@param[in] length	replacementの長さ
+	*/
+	Sub DecoderReplacementFallback(replacement As *WCHAR, length As Long)
+		If replacement = 0 Then
+			Throw New ArgumentNullException("replacement")
+		ElseIf length < 0 Then
+			Throw New ArgumentOutOfRangeException("length")
+		End If
+		str = replacement
+		len = length
+	End Sub
+#ifndef __STRING_IS_NOT_UNICODE
+	/*!
+	@brief	指定された文字列でDecoderReplacementFallbackを構築する。
+	@param[in] replacement	代替文字列
+	*/
+	Sub DecoderReplacementFallback(replacement As String)
+		If ActiveBasic.IsNothing(replacement) Then
+			Throw New ArgumentNullException("replacement")
+		End If
+		With replacement
+			str = .StrPtr
+			len = .Length
+		End With
+	End Sub
+#endif
+	/*!
+	@brief	フォールバックを行う。
+	*/
+	Override Function Fallback(bytesUnknown As *Byte, bytesLen As Long, index As Long, ByRef bufLen As Long) As *WCHAR
+		bufLen = len
+		Dim bufSize = len * SizeOf (WCHAR)
+		Fallback = GC_malloc_atomic(bufSize)
+		memcpy(Fallback, str, bufSize)
+	End Function
+	/*!
+	@brief	このDecoderFallbackの処理で生成される可能性のある最大の文字列の長さを返す。
+	*/
+	Override Function MaxCharCount() As Long
+		MaxCharCount = len
+	End Function
+	/*!
+	@brief	代替文字列を返す
+	@return	代替文字列へのポインタ
+	
+	長さはDefaultStringLengthで得られる
+	*/
+	Function DefaultStringArray() As *WCHAR
+		DefaultStringArray = str
+	End Function
+
+	/*!
+	@brief	代替文字列の長さを返す
+	*/
+	Function DefaultStringLength() As Long
+		DefaultStringLength = len
+	End Function
+
+#ifndef __STRING_IS_NOT_UNICODE
+	/*!
+	@brief	代替文字列を返す
+	@return	代替文字列
+	*/
+	Function DefaultString() As String
+		DefaultString = New String(str, len)
+	End Function
+#endif
+
+Private
+	str As *WCHAR
+	len As Long
+
+	Static default = &h3f As WCHAR '? 疑問符
+End Class
+
+/*!
+@brief	
+@date	2007/12/27
+@auther	Egtra
+*/
+Class DecoderExceptionFallback
+	Inherits DecoderFallback
+Public
+	/*!
+	@brief
+	*/
+	Sub DecoderExceptionFallback()
+	End Sub
+
+	/*!
+	@brief	指定された文字列でDecoderReplacementFallbackを構築する。
+	@param[in] replacement	代替文字列
+	@param[in] length	replacementの長さ
+	*/
+	Sub DecoderReplacementFallback(replacement As *WCHAR, length As Long)
+		If replacement = 0 Then
+			Throw New ArgumentNullException("replacement")
+		ElseIf length < 0 Then
+			Throw New ArgumentOutOfRangeException("length")
+		End If
+	End Sub
+#ifndef __STRING_IS_NOT_UNICODE
+	/*!
+	@brief	指定された文字列でDecoderReplacementFallbackを構築する。
+	@param[in] replacement	代替文字列
+	*/
+	Sub DecoderReplacementFallback(replacement As String)
+		If ActiveBasic.IsNothing(replacement) Then
+			Throw New ArgumentNullException("replacement")
+		End If
+		With replacement
+			str = .StrPtr
+			len = .Length
+		End With
+	End Sub
+#endif
+	/*!
+	@brief	フォールバックを行う。
+	@exception DecoderFallbackException
+	*/
+	Override Function Fallback(bytesUnknown As *Byte, bytesLen As Long, index As Long, ByRef bufLen As Long) As *WCHAR
+		'Throw New DecoderFallbackException
+	End Function
+
+	/*!
+	@brief	このDecoderFallbackの処理で生成される可能性のある最大の文字列の長さを返す。
+	@return	常に0
+	*/
+	Override Function MaxCharCount() As Long
+		MaxCharCount = 0
+	End Function
+End Class
+
+/*!
+@brief	DecoderExceptionFallbackでフォールバックが起こった時に投げられる例外
+@date	2007/12/27
+@auther Egtra
+*/
+Class DecoderFallbackException
+	Inherits ArgumentException
+Public
+	Sub DecoderFallbackException()
+
+	End Sub
+
+	Sub DecoderFallbackException(message As String)
+	End Sub
+
+	Sub DecoderFallbackException(message As String, innerException As Exception)
+	End Sub
+
+'bytesの大きさはどうしよう
+	Sub DecoderFallbackException(message As String, bytesUnknown As *Byte, index As Long)
+	End Sub
+
+
+End Class
+
+End Namespace 'Text
+End Namespace 'System
Index: /trunk/Include/Classes/System/Text/Encoding.ab
===================================================================
--- /trunk/Include/Classes/System/Text/Encoding.ab	(revision 411)
+++ /trunk/Include/Classes/System/Text/Encoding.ab	(revision 411)
@@ -0,0 +1,779 @@
+#define __STRING_IS_NOT_UNICODE 'なぜか認識されないので
+
+/*!
+@file	Classes/System/Text/Encoding.ab
+@brief	Encodingクラスとそれに関係するクラスなどの宣言・定義
+*/
+
+Namespace System
+Namespace Text
+
+/*!
+@brief	各種の文字符号化（エンコーディング）を行うためのクラス
+@date	2007/12/07
+@auther	Egtra
+
+なお、このクラスで、文字列の長さやバッファの大きさを指定するときには、
+1 chars = 2バイト（UTF-16符号単位）、1 bytes = 1バイトの単位で指定する。
+
+*/
+Class Encoding
+	Implements ICloneable
+Public
+	/*!
+	@brief	簡易的複製を作成する。
+	*/
+	Abstract Function Clone() As Object
+
+'	Override Function Equals(y As Object) As Boolean
+'	End Function
+
+'	Override Function GetHashCode() As Long
+'	End Function
+
+Public
+	Sub Encoding()
+		decoderFallback = New DecoderReplacementFallback
+	End Sub
+
+	/*!
+	@brief	符号化して得られる文字列の長さを計算する。
+	@param[in] s	対象文字列
+	@param[in] n	sの長さ
+	@return	符号化して得られる文字列の長さ
+	@date	2007/12/08
+	*/
+	Function GetBytesCount(s As *WCHAR, n As Long) As Long
+		If s = 0 Then
+			Throw New ArgumentNullException("Encoding.GetBytesCount: An argument is null value.", "s")
+		ElseIf n < 0 Then
+			Throw New ArgumentOutOfRangeException("Encoding.GetBytesCount: An argument is out of range value.", "n")
+		End If
+		Return GetBytesCountCore(s, n)
+	End Function
+#ifndef __STRING_IS_NOT_UNICODE
+	/*!
+	@brief	符号化して得られる文字列の長さを計算する。
+	@param[in] s	対象文字列
+	@return	符号化して得られる文字列の長さ
+	@date	2007/12/08
+	*/
+	Function GetBytesCount(s As String) As Long
+		If ActiveBasic.IsNothing(s) Then
+			Throw New ArgumentNullException("Encoding.GetBytesCount: An argument is null value.", "s")
+		End If
+		Return GetBytesCountCore(StrPtr(s), s.Length)
+	End Function
+#endif
+	/*!
+	@brief	符号化して得られる文字列の長さを計算する。
+	@param[in] s	対象文字列
+	@param[in] index	開始位置
+	@param[in] count	符号化する文字の数
+	@return	符号化して得られる文字列の長さ
+	@date	2007/12/08
+	*/
+	Function GetBytesCount(s As *WCHAR, index As Long, count As Long) As Long
+		If s = 0 Then
+			Throw New ArgumentNullException("Encoding.GetBytesCount: An argument is null value.", "s")
+		ElseIf index < 0 Then
+			Throw New ArgumentOutOfRangeException("Encoding.GetBytesCount: An argument is out of range value.", "index")
+		ElseIf count < 0 Then
+			Throw New ArgumentOutOfRangeException("Encoding.GetBytesCount: An argument is out of range value.", "count")
+		End If
+		Return GetBytesCountCore(VarPtr(s[index]), count)
+	End Function
+Protected
+	/*!
+	@brief	GetBytesCountの実装を行う。
+	@param[in] s	対象文字列
+	@param[in] n	sの長さ
+	@return	符号化して得られる文字列の長さ
+	@date	2007/12/08
+	*/
+	Abstract Function GetBytesCountCore(s As *WCHAR, n As Long) As Long
+Public
+	/*!
+	@brief	符号化する。
+	@param[in] chars	入力
+	@param[in] charCount	charsの長さ
+	@param[out] bytes	出力
+	@param[in] byteCount	bytesのバッファの大きさ
+	@return bytesに書き込まれたバイト数
+	@date	2007/12/08
+	*/
+	Function GetBytes(chars As *WCHAR, charCount As Long, bytes As *Byte, byteCount As Long) As Long
+		If chars = 0 Then
+			Throw New ArgumentNullException("Encoding.GetBytes: An argument is null value.", "chars")
+		ElseIf bytes = 0 Then
+			Throw New ArgumentNullException("Encoding.GetBytes: An argument is null value.", "bytes")
+		ElseIf charCount < 0 Then
+			Throw New ArgumentOutOfRangeException("Encoding.GetBytes: An argument is out of range value.", "charCount")
+		ElseIf byteCount < 0 Then
+			Throw New ArgumentOutOfRangeException("Encoding.GetBytes: An argument is out of range value.", "byteCount")
+		End If
+
+		Return GetBytesCore(chars, charCount, bytes, byteCount)
+	End Function
+	/*!
+	@brief	符号化する。
+	@param[in] chars	入力
+	@param[in] index	charsの開始位置
+	@param[in] count	符号化する文字の数
+	@param[out] bytes	出力
+	@param[in] byteCount	bytesのバッファの大きさ
+	@return bytesに書き込まれたバイト数
+	@date	2007/12/08
+	*/
+	Function GetBytes(chars As *WCHAR, index As Long, count As Long, bytes As *Byte, byteCount As Long) As Long
+		If chars = 0 Then
+			Throw New ArgumentNullException("Encoding.GetBytes: An argument is null value.", "chars")
+		ElseIf bytes = 0 Then
+			Throw New ArgumentNullException("Encoding.GetBytes: An argument is null value.", "bytes")
+		ElseIf index < 0 Then
+			Throw New ArgumentOutOfRangeException("Encoding.GetBytesCount: An argument is out of range value.", "index")
+		ElseIf count < 0 Then
+			Throw New ArgumentOutOfRangeException("Encoding.GetBytesCount: An argument is out of range value.", "count")
+		ElseIf byteCount < 0 Then
+			Throw New ArgumentOutOfRangeException("Encoding.GetBytes: An argument is out of range value.", "byteCount")
+		End If
+
+		Return GetBytesCore(VarPtr(chars[index]), count, bytes, byteCount)
+	End Function
+#ifndef __STRING_IS_NOT_UNICODE
+	/*!
+	@brief	符号化する。
+	@param[in] s	入力
+	@param[in] index	sの開始位置
+	@param[in] count	符号化する文字の数
+	@param[out] bytes	出力
+	@param[in] byteCount	bytesのバッファの大きさ
+	@return bytesに書き込まれたバイト数
+	@date	2007/12/08
+	*/
+	Function GetBytes(s As String, index As Long, count As Long, bytes As *Byte, byteCount As Long) As Long
+		If chars = 0 Then
+			Throw New ArgumentNullException("Encoding.GetBytes: An argument is null value.", "chars")
+		ElseIf bytes = 0 Then
+			Throw New ArgumentNullException("Encoding.GetBytes: An argument is null value.", "bytes")
+		ElseIf index < 0 Or index >= s.Length Then
+			Throw New ArgumentOutOfRangeException("Encoding.GetBytes: An argument is out of range value.", "index")
+		ElseIf count < 0 Or index + count >= s.Length Then
+			Throw New ArgumentOutOfRangeException("Encoding.GetBytes: An argument is out of range value.", "count")
+		ElseIf byteCount < 0 Then
+			Throw New ArgumentOutOfRangeException("Encoding.GetBytes: An argument is out of range value.", "byteCount")
+		End If
+		Dim p = StrPtr(s)
+		Return GetBytesCore(VarPtr(p[index]), count, bytes, byteCount)
+	End Function
+#endif
+Protected
+	/*!
+	@brief	GetBytesの処理を行う。
+	@param[in] chars	入力
+	@param[in] charCount	charsの長さ
+	@param[out] bytes	出力
+	@param[in] byteCount	bytesのバッファの大きさ
+	@return bytesに書き込まれたバイト数
+	@exception ArgumentException	バッファの大きさが足りない
+	@exception EncoderFallbackException	フォールバックが発生した
+	@date	2007/12/08
+	*/
+	Abstract Function GetBytesCore(chars As *WCHAR, charCount As Long, bytes As *Byte, byteCount As Long) As Long
+
+Public
+	/*!
+	@brief	復号して得られる文字列の長さを計算する。
+	@param[in] s	対象文字列
+	@param[in] n	sの長さ
+	@return	復号して得られる文字列の長さ
+	@date	2007/12/08
+	*/
+	Function GetCharsCount(s As *Byte, n As Long) As Long
+		If s = 0 Then
+			Throw New ArgumentNullException("Encoding.GetCharsCount: An argument is null value.", "s")
+		ElseIf n < 0 Then
+			Throw New ArgumentOutOfRangeException("Encoding.GetCharsCount: An argument is out of range value.", "n")
+		End If
+		Return GetCharsCountCore(s, n)
+	End Function
+	/*!
+	@brief	復号して得られる文字列の長さを計算する。
+	@param[in] s	対象文字列
+	@param[in] index	開始位置
+	@param[in] count	符号化する文字の数
+	@return	符号化して得られる文字列の長さ
+	@date	2007/12/08
+	*/
+	Function GetCharsCount(s As *Byte, index As Long, count As Long) As Long
+		If s = 0 Then
+			Throw New ArgumentNullException("Encoding.GetCharsCount: An argument is null value.", "s")
+		ElseIf index < 0 Then
+			Throw New ArgumentOutOfRangeException("Encoding.GetCharsCount: An argument is out of range value.", "index")
+		ElseIf count < 0 Then
+			Throw New ArgumentOutOfRangeException("Encoding.GetCharsCount: An argument is out of range value.", "count")
+		End If
+		Return GetCharsCountCore(VarPtr(s[index]), count)
+	End Function
+Protected
+	/*!
+	@brief	GetCharsCountの処理を行う。
+	@param[in] s	対象文字列
+	@param[in] n	sの長さ
+	@return	符号化して得られる文字列の長さ
+	@date	2007/12/08
+	*/
+	Abstract Function GetCharsCountCore(s As *Byte, n As Long) As Long
+	/*!
+	*/
+Public
+	/*!
+	@brief	復号する。
+	@param[in] bytes	入力
+	@param[in] byteCount	charsの長さ
+	@param[out] chars	出力
+	@param[in] charCount	bytesのバッファの大きさ
+	@return bytesに書き込まれたバイト数
+	@date	2007/12/08
+	*/
+	Function GetChars(bytes As *Byte, byteCount As Long, chars As *WCHAR, charCount As Long) As Long
+		If chars = 0 Then
+			Throw New ArgumentNullException("Encoding.GetChars: An argument is null value.", "chars")
+		ElseIf bytes = 0 Then
+			Throw New ArgumentNullException("Encoding.GetChars: An argument is null value.", "bytes")
+		ElseIf charCount < 0 Then
+			Throw New ArgumentOutOfRangeException("Encoding.GetChars: An argument is out of range value.", "charCount")
+		ElseIf byteCount < 0 Then
+			Throw New ArgumentOutOfRangeException("Encoding.GetChars: An argument is out of range value.", "byteCount")
+		End If
+
+		Return GetCharsCore(bytes, byteCount, chars, charCount)
+	End Function
+	/*!
+	@brief	復号する。
+	@param[in] bytes	入力
+	@param[in] index	charsの開始位置
+	@param[in] count	符号化する文字の数
+	@param[out] chars	出力
+	@param[in] charCount	bytesのバッファの大きさ
+	@return bytesに書き込まれたバイト数
+	@date	2007/12/08
+	*/
+	Function GetChars(bytes As *Byte, index As Long, count As Long, chars As *WCHAR, charCount As Long) As Long
+		If chars = 0 Then
+			Throw New ArgumentNullException("Encoding.GetChars: An argument is null value.", "chars")
+		ElseIf bytes = 0 Then
+			Throw New ArgumentNullException("Encoding.GetChars: An argument is null value.", "bytes")
+		ElseIf index < 0 Then
+			Throw New ArgumentOutOfRangeException("Encoding.GetChars: An argument is out of range value.", "index")
+		ElseIf count < 0 Then
+			Throw New ArgumentOutOfRangeException("Encoding.GetChars: An argument is out of range value.", "count")
+		ElseIf charCount < 0 Then
+			Throw New ArgumentOutOfRangeException("Encoding.GetChars: An argument is out of range value.", "byteCount")
+		End If
+
+		Return GetCharsCore(VarPtr(bytes[index]), count, chars, charCount)
+	End Function
+Protected
+	/*!
+	@brief	GetCharsの処理を行う。
+	@param[in] bytes	入力
+	@param[in] byteCount	charsの長さ
+	@param[out] chars	出力
+	@param[in] charCount	bytesのバッファの大きさ
+	@return bytesに書き込まれたバイト数
+	@exception ArgumentException	バッファの大きさが足りない
+	@exception EncoderFallbackException	フォールバックが発生した
+	@date	2007/12/08
+	*/
+	Abstract Function GetCharsCore(bytes As *Byte, byteCount As Long, chars As *WCHAR, charCount As Long) As Long
+Public
+#ifndef __STRING_IS_NOT_UNICODE
+	/*!
+	@brief	復号し、Stringで結果を返す。
+	@param[in] bytes	入力
+	@param[in] byteCount	charsの長さ
+	@return	変換結果の文字列
+	@date	2007/12/08
+	*/
+	Function GetString(bytes As *Byte, byteCount As Long) As String
+		If bytes = 0 Then
+			Throw New ArgumentNullException("Encoding.GetString: An argument is null value.", "bytes")
+		ElseIf byteCount < 0 Then
+			Throw New ArgumentOutOfRangeException("Encoding.GetString: An argument is out of range value.", "byteCount")
+		End If
+		Return getStringCore(bytes, byteCount)
+	End Function
+	/*!
+	@brief	復号し、Stringで結果を返す。
+	@param[in] bytes	入力
+	@param[in] index	charsの開始位置
+	@param[in] count	符号化する文字の数
+	@return	変換結果の文字列
+	@date	2007/12/08
+	*/
+	Function GetString(bytes As *Byte, index As Long, count As Long) As String
+		If bytes = 0 Then
+			Throw New ArgumentNullException("Encoding.GetString: An argument is null value.", "bytes")
+		ElseIf index < 0 Then
+			Throw New ArgumentOutOfRangeException("Encoding.GetString: An argument is out of range value.", "index")
+		ElseIf count < 0 Then
+			Throw New ArgumentOutOfRangeException("Encoding.GetString: An argument is out of range value.", "count")
+		End If
+		Return getStringCore(VarPtr(bytes[index]), count)
+	End Function
+Private
+
+	Function getStringCore(bytes As *Byte, byteCount As Long) As String
+		Dim sb = New StringBuilder
+		Dim bufSize = GetMaxCharCount(byteCount)
+		sb.Length = bufSize
+		Dim len = GetCharsCore(bytes, byteCount, StrPtr(sb), bufSize)
+		sb.Length = len
+		getStringCore = sb.ToString
+	End Function
+#endif
+
+Public
+	/*!
+	@brief	符号器を取得する。
+	*/
+	Abstract Function GetDecoder() As Decoder
+
+	/*!
+	@brief	復号器を取得する。
+	*/
+	Abstract Function GetEncoder() As Encoder
+
+	/*!
+	@brief	ある長さの文字列を符号化して得られるバイト列の最大の長さを返す。
+	*/
+	Abstract Function GetMaxByteCount(charCount As Long) As Long
+
+	/*!
+	@brief	ある長さのバイト列を復号して得られる文字列の最大の長さを返す。
+	*/
+	Abstract Function GetMaxCharCount(charCount As Long) As Long
+
+	/*!
+	@brief	符号化された文字列の先頭につける識別文字列の取得
+	ようするにUTFのBOM
+	*/
+	Virtual Function GetPreamble() As *Byte
+		Return 0
+	End Function
+
+	/*!
+	@brief	GetPreambleの配列の要素数
+	*/
+	Virtual Function GetPreambleLength() As Long
+		Return 0
+	End Function
+
+	/*!
+	@brief	正規化されるかどうか。
+	*/
+	Abstract Function IsAlwaysNormalized() As Boolean
+
+	/*!
+	@brief	指定された方式で正規化されるかどうか。
+	*/
+	Abstract Function IsAlwaysNormalized(form As NormalizationForm) As Boolean
+
+	Abstract Function BodyName() As String
+	Abstract Function HeaderName() As String
+
+	/*!
+	@brief	コードページの取得。
+	*/
+'	Abstract Function CodePage() As Long
+	/*!
+	@brief	最も厳密に対応するWindowsコードページの取得。
+	*/
+'	Abstract Function WindowsCodePage() As Long
+
+	Function DecoderFallback() As DecoderFallback
+		Return decoderFallback
+	End Function
+
+	Sub DecoderFallback(f As DecoderFallback)
+		If ActiveBasic.IsNothing(f) Then
+			Throw New ArgumentNullException("f")
+		End If
+		decoderFallback = f
+	End Sub
+
+	Function EncoderFallback() As EncoderFallback
+		Return encoderFallback
+	End Function
+
+	Sub EncoderFallback(f As EncoderFallback)
+		If ActiveBasic.IsNothing(f) Then
+			Throw New ArgumentNullException("f")
+		End If
+		encoderFallback = f
+	End Sub
+
+Private
+	decoderFallback As DecoderFallback
+	encoderFallback As EncoderFallback
+Public
+	/*!
+	@brief	この符号化形式の名前の取得。
+	*/
+	Abstract Function EncodingName() As String
+
+	/*!
+	@brief	この符号化形式のIANA登録名の取得。
+	*/
+	Abstract Function WebName() As String
+
+'	Abstract Function IsBrowserDisplay() As Boolean
+'	Abstract Function IsBrowserSave() As Boolean
+'	Abstract Function IsMailNewsDisplay() As Boolean
+'	Abstract Function IsMailNewsSave() As Boolean
+
+'	Abstract Function IsReadOnly() Boolean
+
+	/*!
+	@brief	この符号化形式が、1バイト文字だけを使う（複数バイト文字を使わない）かどうか。
+	*/
+	Abstract Function IsSingleByte() As Boolean
+
+	'GetPreamble
+
+	/*!
+	@brief	ある符号化文字列から別の符号化文字列へ変換する。
+	@param[in] srcEncoding	入力の符号化方式
+	@param[in] dstEncoding	出力の符号化方式
+	@param[in] bytes	入力文字列
+	@param[in] size	バイト単位での文字列の長さ
+	@return	出力文字列
+	@exception ArgumentNullException	srcEncoding, dstEncoding, bytesの少なくとも1つ以上がNothing/NULLのとき。
+	@exception ArgumentOutOfRangeException	sizeが明らかに範囲外（負の値など）のとき。
+	@exception DecoderFallbackException
+	@exception EncoderFallbackException
+	*/
+	Static Function Convert(srcEncoding As Encoding, dstEncoding As Encoding, bytes As *Byte, size As Long) As *Byte
+	End Function
+	
+	Static Function Convert(srcEncoding As Encoding, dstEncoding As Encoding, bytes As *Byte, index As Long, count As Long) As *Byte
+	End Function
+
+	/*!
+	@brief	指定したコードページ用のEncodingインスタンスの取得。
+	*/
+	Static Function GetEncoding(codepage As Long) As Encoding
+	End Function
+'	Static Function GetEncoding(codepage As Long, encoderFallback As EncoderFallback, decoderFallback As DecoderFallback) As Encoding
+'	End Function
+	/*!
+	@brief	指定した符号化形式名用のEncodingインスタンスの取得。
+	*/
+	Static Function GetEncoding(name As String) As Encoding
+	End Function
+'	Static Function GetEncoding(name As String, encoderFallback As EncoderFallback, decoderFallback As DecoderFallback) As Encoding
+'	End Function
+
+	/*!
+	@brief	システム既定のANSIコードページ用のEncodingインスタンスの取得。
+	*/
+	Static Function Default() As Encoding
+	End Function
+	/*!
+	@brief	UTF-7用のEncodingインスタンスの取得。
+	*/
+	Static Function UTF7() As Encoding
+	End Function
+	/*!
+	@brief	UTF-8用のEncodingインスタンスの取得。
+	*/
+	Static Function UTF8() As Encoding
+	End Function
+	/*!
+	@brief	UTF-16LE用のEncodingインスタンスの取得。
+	*/
+	Static Function UTF16() As Encoding
+	End Function
+	/*!
+	@brief	UTF-16BE用のEncodingインスタンスの取得。
+	*/
+	Static Function UTF16BE() As Encoding
+	End Function
+	/*!
+	@brief	UTF-32LE用のEncodingインスタンスの取得。
+	*/
+	Static Function UTF32() As Encoding
+	End Function
+End Class
+
+/*!
+@brief	復号を行うクラス
+@date	2007/12/19
+@auther	Egtra
+*/
+Class Decoder
+Public
+	/*!
+	@brief	変換する
+	@param[in] bytes	入力
+	@param[in] byteIndex 入力開始位置
+	@param[in] byteCount 入力要素数
+	@param[out] chars	出力
+	@param[in] charIndex 出力開始位置
+	@param[in] charCount 出力要素数
+	@param[in] flush	終了後に内部状態を初期化するかどうか
+	@param[out] charsUsed	使用された入力の要素数
+	@param[out] bytesUsed	出力の内、実際に書き込まれた要素数
+	@param[out] completed	入力の全ての文字が変換に使われたかどうか
+	*/
+	Sub Convert(bytes As *Byte, byteIndex As Long, byteCount As Long,
+		chars As *WCHAR, charIndex As Long, charCount As Long, flush As Boolean,
+		ByRef bytesUsed As Long, ByRef charsUsed As Long, ByRef completed As Boolean)
+
+		If bytes = 0 Then
+			Throw New ArgumentNullException("bytes")
+		ElseIf byteIndex < 0 Then
+			Throw New ArgumentOutOfRangeException("byteIndex")
+		ElseIf byteCount < 0 Then
+			Throw New ArgumentOutOfRangeException("byteCount")
+		ElseIf chars = 0 Then
+			Throw New ArgumentNullException("chars")
+		ElseIf charIndex < 0 Then
+			Throw New ArgumentOutOfRangeException("charIndex")
+		ElseIf charCount < 0 Then
+			Throw New ArgumentOutOfRangeException("charCount")
+		End If
+		ConvertCore(VarPtr(bytes[byteIndex]), byteCount, VarPtr(chars[charIndex]), charCount, flush, bytesUsed, charsUsed, completed)
+	End Sub
+
+	/*!
+	@overload Sub Convert(bytes As *Byte, byteIndex As Long, byteCount As Long,
+		chars As *WCHAR, charIndex As Long, charCount As Long, flush As Boolean,
+		ByRef bytesUsed As Long, ByRef charsUsed As Long, ByRef completed As Boolean)
+	*/
+	Sub Convert(bytes As *Byte, byteCount As Long,
+		chars As *WCHAR, charCount As Long, flush As Boolean,
+		ByRef bytesUsed As Long, ByRef charsUsed As Long, ByRef completed As Boolean)
+
+		If bytes = 0 Then
+			Throw New ArgumentNullException("bytes")
+		ElseIf byteCount < 0 Then
+			Throw New ArgumentOutOfRangeException("byteCount")
+		ElseIf chars = 0 Then
+			Throw New ArgumentNullException("chars")
+		ElseIf charCount < 0 Then
+			Throw New ArgumentOutOfRangeException("charCount")
+		End If
+		ConvertCore(bytes, byteCount, chars, charCount, flush, bytesUsed, charsUsed, completed)
+	End Sub
+
+	/*!
+	@brief	変換する
+	@param[in] bytes	入力
+	@param[in] byteIndex 入力開始位置
+	@param[in] byteCount 入力要素数
+	@param[out] chars	出力
+	@param[in] charIndex 出力開始位置
+	@param[in] charCount 出力要素数
+	@param[in] flush	終了後に内部状態を初期化するかどうか
+	@return	出力の内、実際に書き込まれた要素数
+	*/
+	Function GetChars(bytes As *Byte, byteIndex As Long, byteCount As Long, chars As *WCHAR, charIndex As Long, charCount As Long, flush As Boolean) As Long
+		Dim bytesUsed As Long
+		Dim completed As Boolean
+		Convert(bytes, byteIndex, byteCount, chars, charIndex, charCount, flush, bytesUsed, GetChars, completed)
+	End Function
+
+	/*!
+	@overload Function GetChars(bytes As *Byte, byteIndex As Long, byteCount As Long, chars As *WCHAR, charIndex As Long, charCount As Long, flush As Boolean) As Long
+	*/
+	Function GetChars(bytes As *Byte, byteCount As Long, chars As *WCHAR, charCount As Long, flush As Boolean) As Long
+		Dim bytesUsed As Long
+		Dim completed As Boolean
+		Convert(bytes, byteCount, chars, charCount, flush, bytesUsed, GetChars, completed)
+	End Function
+
+	/*!
+	@overload Function GetChars(bytes As *Byte, byteIndex As Long, byteCount As Long, chars As *WCHAR, charIndex As Long, charCount As Long, flush As Boolean) As Long
+	*/
+	Function GetChars(bytes As *Byte, byteIndex As Long, byteCount As Long, chars As *WCHAR, charIndex As Long, charCount As Long) As Long
+		GetChars = GetChars(bytes, byteIndex, byteCount, chars, charIndex, charCount, False)
+	End Function
+
+	/*!
+	@brief	フォールバックの取得
+	*/
+	Function Fallback() As DecoderFallback
+		Return fallback
+	End Function
+
+	/*!
+	@brief	フォールバックの設定
+	*/
+	Sub Fallback(newFallback As DecoderFallback)
+		If ActiveBasic.IsNothing(newFallback) Then
+			Throw New ArgumentNullException("newFallback")
+		End If
+		fallback = newFallback
+	End Sub
+Protected
+	/*!
+	@brief	実際に変換するメソッド
+	@param[in] bytes	入力
+	@param[in] byteCount 入力要素数
+	@param[out] chars	出力
+	@param[in] charCount 出力要素数
+	@param[in] flush	終了後に内部状態を初期化するかどうか
+	@param[out] charsUsed	使用された入力の要素数
+	@param[out] bytesUsed	出力の内、実際に書き込まれた要素数
+	@param[out] completed	入力の全ての文字が変換に使われたかどうか
+	*/
+	Abstract Sub ConvertCore(bytes As *Byte, byteCount As Long, chars As *WCHAR, charCount As Long, flush As Boolean,
+		ByRef bytesUsed As Long, ByRef charsUsed As Long, ByRef completed As Boolean)
+
+Private
+	fallback As DecoderFallback
+End Class
+
+/*!
+@brief	符号化を行うクラス
+@date	2007/12/19
+@auther	Egtra
+*/
+Class Encoder
+Public
+	/*!
+	@brief	変換する
+	@param[in] chars	入力
+	@param[in] charIndex 入力開始位置
+	@param[in] charCount 入力要素数
+	@param[out] bytes	出力
+	@param[in] byteIndex 出力開始位置
+	@param[in] byteCount 出力要素数
+	@param[in] flush	終了後に内部状態を初期化するかどうか
+	@param[out] charsUsed	使用された入力の要素数
+	@param[out] bytesUsed	出力の内、実際に書き込まれた要素数
+	@param[out] completed	入力の全ての文字が変換に使われたかどうか
+	*/
+	Sub Convert(chars As *WCHAR, charIndex As Long, charCount As Long,
+		bytes As *Byte, byteIndex As Long, byteCount As Long, flush As Boolean,
+		ByRef charsUsed As Long, ByRef bytesUsed As Long, ByRef completed As Boolean)
+
+		If chars = 0 Then
+			Throw New ArgumentNullException("chars")
+		ElseIf charIndex < 0 Then
+			Throw New ArgumentOutOfRangeException("charIndex")
+		ElseIf charCount < 0 Then
+			Throw New ArgumentOutOfRangeException("charCount")
+		ElseIf bytes = 0 Then
+			Throw New ArgumentNullException("bytes")
+		ElseIf byteIndex < 0 Then
+			Throw New ArgumentOutOfRangeException("byteIndex")
+		ElseIf byteCount < 0 Then
+			Throw New ArgumentOutOfRangeException("byteCount")
+		End If
+		ConvertCore(VarPtr(chars[charIndex]), charCount, VarPtr(bytes[byteIndex]), byteCount, flush, charsUsed, bytesUsed, completed)
+	End Sub
+
+	/*!
+	@overload Sub Convert(chars As *WCHAR, charIndex As Long, charCount As Long,
+		bytes As *Byte, byteIndex As Long, byteCount As Long, flush As Boolean,
+		ByRef charsUsed As Long, ByRef bytesUsed As Long, ByRef completed As Boolean)
+	*/
+	Sub Convert(chars As *WCHAR, charCount As Long,
+		bytes As *Byte, byteCount As Long, flush As Boolean,
+		ByRef charsUsed As Long, ByRef bytesUsed As Long, ByRef completed As Boolean)
+
+		If chars = 0 Then
+			Throw New ArgumentNullException("chars")
+		ElseIf charCount < 0 Then
+			Throw New ArgumentOutOfRangeException("charCount")
+		ElseIf bytes = 0 Then
+			Throw New ArgumentNullException("bytes")
+		ElseIf byteCount < 0 Then
+			Throw New ArgumentOutOfRangeException("byteCount")
+		End If
+		ConvertCore(chars, charCount, bytes, byteCount, flush, charsUsed, bytesUsed, completed)
+	End Sub
+
+	/*!
+	@brief	変換する
+	@param[in] chars	入力
+	@param[in] charIndex 入力開始位置
+	@param[in] charCount 入力要素数
+	@param[out] bytes	出力
+	@param[in] byteIndex 出力開始位置
+	@param[in] byteCount 出力要素数
+	@param[in] flush	終了後に内部状態を初期化するかどうか
+	@return bytesUsed	出力の内、実際に書き込まれた要素数
+	*/
+	Function GetBytes(chars As *WCHAR, charIndex As Long, charCount As Long, bytes As *Byte, byteIndex As Long, byteCount As Long, flush As Boolean) As Long
+		Dim charsUsed As Long
+		Dim completed As Boolean
+		Convert(chars, charIndex, charCount, bytes, byteIndex, byteCount, flush, charsUsed, GetBytes, completed)
+	End Function
+
+	/*!
+	@overload Function GetBytes(chars As *WCHAR, charIndex As Long, charCount As Long, bytes As *Byte, byteIndex As Long, byteCount As Long, flush As Boolean) As Long
+	*/
+	Function GetBytes(chars As *WCHAR, charCount As Long, bytes As *Byte, byteCount As Long, flush As Boolean) As Long
+		Dim charsUsed As Long
+		Dim completed As Boolean
+		Convert(chars, charCount, bytes, byteCount, flush, charsUsed, GetBytes, completed)
+	End Function
+
+	/*!
+	@overload Function GetBytes(chars As *WCHAR, charIndex As Long, charCount As Long, bytes As *Byte, byteIndex As Long, byteCount As Long, flush As Boolean) As Long
+	*/
+	Function GetBytes(chars As *WCHAR, charIndex As Long, charCount As Long, bytes As *Byte, byteIndex As Long, byteCount As Long) As Long
+		GetBytes = GetBytes(chars, charIndex, charCount, bytes, byteIndex, byteCount, False)
+	End Function
+
+	/*!
+	@brief	フォールバックの取得
+	*/
+	Function Fallback() As EncoderFallback
+		Return fallback
+	End Function
+
+	/*!
+	@brief	フォールバックの設定
+	*/
+	Sub Fallback(newFallback As EncoderFallback)
+		If ActiveBasic.IsNothing(newFallback) Then
+			Throw New ArgumentNullException("newFallback")
+		End If
+		fallback = newFallback
+	End Sub
+Protected
+	/*!
+	@brief	実際に変換するメソッド
+	@param[in] chars	入力
+	@param[in] charCount 入力要素数
+	@param[out] bytes	出力
+	@param[in] byteCount 出力要素数
+	@param[in] flush	終了後に内部状態を初期化するかどうか
+	@param[out] bytesUsed	使用された入力の要素数
+	@param[out] charsUsed	出力の内、実際に書き込まれた要素数
+	@param[out] completed	入力の全ての文字が変換に使われたかどうか
+	*/
+	Abstract Sub ConvertCore(chars As *WCHAR, charCount As Long, bytes As *Byte, byteCount As Long, flush As Boolean,
+		ByRef bytesUsed As Long, ByRef charsUsed As Long, ByRef completed As Boolean)
+
+Private
+	fallback As EncoderFallback
+End Class
+
+Enum NormalizationForm
+	FormC
+	FormD
+	FormKC
+	FormKD
+End Enum
+
+Class EncoderFallback
+End Class
+
+End Namespace 'Text
+End Namespace 'System
Index: /trunk/Include/Classes/System/Text/UTF8Encoding.ab
===================================================================
--- /trunk/Include/Classes/System/Text/UTF8Encoding.ab	(revision 411)
+++ /trunk/Include/Classes/System/Text/UTF8Encoding.ab	(revision 411)
@@ -0,0 +1,265 @@
+/*!
+@file	Classes/System/Text/UTF8Encoding.ab
+@brief	UTF8Encodingクラスとそれに関係するクラスなどの宣言・定義
+*/
+
+Namespace System
+Namespace Text
+
+Namespace Detail
+
+Class UTF8Encoder
+	Inherits Encoder
+Protected
+	Override Sub ConvertCore(chars As *WCHAR, charCount As Long, bytes As *Byte, byteCount As Long, flush As Boolean,
+		ByRef bytesUsed As Long, ByRef charsUsed As Long, ByRef completed As Boolean)
+
+		Dim i As Long, j = 0 As Long
+		For i = 0 To ELM(charCount)
+			If chars[i] < &h80 Then
+				'1バイト変換
+				If j + 1 > byteCount Then
+					'バッファ不足
+					Goto *BufferOver
+				End If
+				bytes[j] = chars[i] As Byte
+				j++
+			ElseIf chars[i] < &h800 Then
+				'2バイト変換
+				If j + 2 > byteCount Then
+					Goto *BufferOver
+				End If
+				bytes[j] = ((chars[i] >> 6) Or &hC0) As Byte
+				j++
+				bytes[j] = (chars[i] And &h3F Or &h80) As Byte
+				j++
+			ElseIf _System_IsHighSurrogate(chars[i]) Then
+				If i + 1 >= charCount Then
+					'バッファに貯め込む
+					If flush = False Then
+						buffer = chars[i]
+						Exit Sub
+					End If
+					'ToDo: chars[i + 1]が範囲外になる場合が考慮されていない
+				ElseIf _System_IsLowSurrogate(chars[i + 1]) = False Then
+					'EncoderFallback
+				End If
+				If j + 4 > byteCount Then
+					Goto *BufferOver
+				End If
+				'UTF-16列からUnicodeコードポイントを復元
+				Dim c = (((chars[i] And &h3FF) As DWord << 10) Or (chars[i + 1] And &h3FF)) + &h10000
+				'4バイト変換
+				bytes[j] = ((c >> 18) Or &hf0) As Byte
+				j++
+				bytes[j] = ((c >> 12) And &h3F Or &h80) As Byte
+				j++
+				bytes[j] = ((c >> 6) And &h3F Or &h80) As Byte
+				j++
+				bytes[j] = (c And &h3F Or &h80) As Byte
+				j++
+				i++
+			ElseIf _System_IsLowSurrogate(chars[i]) Then
+				'EncoderFallback
+			Else
+				'3バイト変換
+				If j + 3 > byteCount Then
+					Goto *BufferOver
+				End If
+				bytes[j] = ((chars[i] >> 12) Or &hE0) As Byte
+				j++
+				bytes[j] = ((chars[i] >> 6) And &h3F Or &h80) As Byte
+				j++
+				bytes[j] = (chars[i] And &h3F Or &h80) As Byte
+				j++
+			End If
+		Next
+
+		Exit Sub
+	*BufferOver
+		'バッファ不足
+		Throw New ArgumentException("Buffer is not enough.", "bytes")
+	End Sub
+
+Private
+	buffer As WCHAR
+End Class
+
+Class UTF8Decoder
+	Inherits Decoder
+Protected
+	Override Sub ConvertCore(bytes As *Byte, byteCount As Long, chars As *WCHAR, charCount As Long, flush As Boolean,
+		ByRef bytesUsed As Long, ByRef charsUsed As Long, ByRef completed As Boolean)
+		Dim i As Long, j = 0 As Long
+		For i = 0 To ELM(byteCount)
+			If state = 0 Then
+				If bytes[i] <= &h80 Then
+					'1バイト変換
+					If j = charCount Then Goto *BufferOver
+					chars[j] = bytes[i]
+					j++
+				ElseIf bytes[i] < &hC0 Then
+					'マルチバイトの2バイト目以降
+					'DecoderFallback完成までの暫定
+					If j = charCount Then Goto *BufferOver
+					chars[j] = &hfffd
+					j++
+				ElseIf bytes[i] < &hD0 Then
+					'2バイト文字の始まり
+					last = 2
+					buf = bytes[i] And &h3f
+					state++
+				ElseIf bytes[i] < &hF0 Then
+					'3バイト文字の始まり
+					last = 3
+					buf = bytes[i] And &h1f
+					state++
+				Else
+					'4バイト文字の始まり
+					last = 4
+					buf = bytes[i] And &h0f
+					state++
+				End If
+			Else
+				If &h80 <= bytes[i] And bytes[i] < &hC0 Then
+					'マルチバイト文字の2バイト目以降
+					buf <<= 6
+					buf Or= bytes[i] And &h3F
+					state++
+					If state = last Then '最終バイトに到達
+						If state = 2 And buf >= &h80 Then
+							chars[j] = buf As WCHAR
+							j++
+						ElseIf state = 3 And buf >= &h800 And buf < &hD800 And &hE0000 >= buf Then
+							chars[j] = buf As WCHAR
+							j++
+						ElseIf state = 4 And buf <= &h10ffff Then
+							buf -= &h10000
+							chars[j] = (&hD800 Or (buf >> 10)) As WCHAR
+							j++
+							chars[j] = (&hDC00 Or (buf And &h3FF)) As WCHAR
+							j++
+						Else
+							'DecoderFallback
+							If j = charCount Then Goto *BufferOver
+							chars[j] = &hfffd
+							j++
+						End If
+						state = 0
+					End If
+				Else
+					'3, 4バイト文字の先頭
+					'DecoderFallback
+					If j = charCount Then Goto *BufferOver
+					chars[j] = &hfffd
+					j++
+				End If
+			End If
+		Next
+		Exit Sub
+	*BufferOver
+		'バッファ不足
+		Throw New ArgumentException("Buffer is not enough.", "bytes")
+	End Sub
+
+Private
+	buf As DWord
+	state As Long
+	last As Long
+End Class
+
+End Namespace 'Detail
+
+
+/*!
+@brief UTF-8用のEncoding
+@date 2007/12/21
+@auther Egtra
+*/
+Class UTF8Encoding
+	Inherits Encoding
+Public
+
+	Override Function Clone() As Object
+		Dim c = New UTF8Encoding
+		c.DecoderFallback = This.DecoderFallback
+		c.EncoderFallback = This.EncoderFallback
+		Return c
+	End Function
+
+	Override Function GetDecoder() As Decoder
+		GetDecoder = New Detail.UTF8Decoder
+'		GetDecoder.Fallback = DecoderFallback
+	End Function
+
+	Override Function GetEncoder() As Encoder
+		GetEncoder = New Detail.UTF8Encoder
+'		GetEncoder.Fallback = EncoderFallback
+	End Function
+
+	Override Function GetMaxByteCount(charCount As Long) As Long
+		Return charCount * 3
+		'全てがUTF-8で3バイトになる文字の場合が最大。
+
+		'UTF-8で4バイトになる列は、UTF-16だとサロゲートペアで表現するので、
+		'1単位あたりでは2バイトしか食わないことになる。
+	End Function
+
+	Override Function GetMaxCharCount(byteCount As Long) As Long
+		'全てU+7F以下の文字だけだった場合
+		Return byteCount
+	End Function
+Protected
+	Override Function GetBytesCountCore(s As *WCHAR, n As Long) As Long
+	End Function
+
+	Override Function GetBytesCore(chars As *WCHAR, charCount As Long, bytes As *Byte, byteCount As Long) As Long
+	End Function
+
+	Override Function GetCharsCountCore(s As *Byte, n As Long) As Long
+	End Function
+
+	Override Function GetCharsCore(bytes As *Byte, byteCount As Long, chars As *WCHAR, charCount As Long) As Long
+	End Function
+Public
+	Override Function GetPreamble() As *Byte
+		Return bom
+	End Function
+
+	Override Function GetPreambleLength() As Long
+		Return Len(bom)
+	End Function
+
+	Override Function IsAlwaysNormalized() As Boolean
+		IsAlwaysNormalized = False
+	End Function
+
+	Override Function IsAlwaysNormalized(f As NormalizationForm) As Boolean
+		IsAlwaysNormalized = False
+	End Function
+
+	Override Function BodyName() As String
+		Return "utf-8"
+	End Function
+
+	Override Function HeaderName() As String
+		Return "utf-8"
+	End Function
+
+	Override Function EncodingName() As String
+		Return "UTF-8"
+	End Function
+
+	Override Function WebName() As String
+		Return "utf-8"
+	End Function
+
+	Override Function IsSingleByte() As Boolean
+		Return False
+	End Function
+Private
+	Static bom[2] = [&hEF, &hBB, &hBF] As Byte
+End Class
+
+End Namespace 'Text
+End Namespace 'System
Index: /trunk/Include/Classes/index.ab
===================================================================
--- /trunk/Include/Classes/index.ab	(revision 410)
+++ /trunk/Include/Classes/index.ab	(revision 411)
@@ -75,4 +75,7 @@
 #require "./System/Security/AccessControl/misc.ab"
 #require "./System/Text/StringBuilder.ab"
+#require "./System/Text/Encoding.ab"
+#require "./System/Text/UTF8Encoding.ab"
+#require "./System/Text/DecoderFallback.ab"
 #require "./System/Threading/Thread.ab"
 #require "./System/Threading/WaitHandle.ab"
Index: /trunk/Include/basic/prompt.sbp
===================================================================
--- /trunk/Include/basic/prompt.sbp	(revision 410)
+++ /trunk/Include/basic/prompt.sbp	(revision 411)
@@ -4,8 +4,4 @@
 #ifndef _INC_PROMPT
 #define _INC_PROMPT
-
-#require <api_imm.sbp>
-#require <Classes/System/Math.ab>
-#require <Classes/System/Environment.ab>
 
 Namespace ActiveBasic
@@ -23,4 +19,5 @@
 Function _PromptSys_TextOut(hdc As HDC, x As Long, y As Long, psz As PCSTR, cb As Long) As Long
 	_PromptSys_TextOut = TextOutA(hdc, x, y, psz, cb)
+	If _PromptSys_TextOut = 0 Then Debug
 End Function
 
@@ -65,6 +62,4 @@
 Dim _PromptSys_SectionOfBufferAccess As CRITICAL_SECTION
 
-Dim _System_OSVersionInfo As OSVERSIONINFO
-
 
 'graphic
@@ -86,4 +81,5 @@
 Sub DrawPromptBuffer(hDC As HDC, StartLine As Long, EndLine As Long)
 	Dim i As Long, i2 As Long, i3 As Long
+	Dim ret As Long
 
 	Dim hOldFont = SelectObject(hDC, _PromptSys_hFont) As HFONT
@@ -118,8 +114,8 @@
 			_PromptSys_GetTextExtentPoint32(hDC, _PromptSys_TextLine[i].Text, i3, sz)
 
-			BitBlt(hDC,_
-				sz.cx, i * _PromptSys_FontSize.cy, _
-				rc.right, _PromptSys_FontSize.cy, _
-				_PromptSys_hMemDC, sz.cx, i * _PromptSys_FontSize.cy, SRCCOPY)
+'			BitBlt(hDC,_
+'				sz.cx, i * _PromptSys_FontSize.cy, _
+'				rc.right, _PromptSys_FontSize.cy, _
+'				_PromptSys_hMemDC, sz.cx, i * _PromptSys_FontSize.cy, SRCCOPY)
 
 			While i2 < i3
@@ -128,6 +124,7 @@
 					SetBkMode(hDC, TRANSPARENT)
 				Else
-					SetBkMode(hDC, OPAQUE)
-					SetBkColor(hDC, currentLineCharInfo[i2].BackColor)
+					Debug
+					ret = SetBkMode(hDC, OPAQUE)
+					ret = SetBkColor(hDC, currentLineCharInfo[i2].BackColor)
 				End If
 
@@ -152,9 +149,11 @@
 
 Sub PRINT_ToPrompt(buf As String)
+	OutputDebugString(ToTCStr(Ex"PRINT_ToPrompt " + buf + Ex"\r\n"))
 	EnterCriticalSection(_PromptSys_SectionOfBufferAccess)
+	If buf = "あ" Then Debug
 	With _PromptSys_CurPos
 		Dim hdc = GetDC(_PromptSys_hWnd)
 		Dim hOldFont = SelectObject(hdc, _PromptSys_hFont)
-		Dim StartLine As Long : StartLine = .y
+		Dim StartLine = .y As Long
 		Dim bufLen = buf.Length
 		Dim doubleUnitChar = False As Boolean
@@ -194,9 +193,4 @@
 						_PromptSys_GetTextExtentPoint32(hdc, VarPtr(p[i2]) As *StrChar, charLen, sz)
 						currentLineCharInfo[.x + 1].StartPos = currentLineCharInfo[.x].StartPos + sz.cx
-/*
-						Dim buf[1023] As Char
-						wsprintf(buf, Ex"%d %d\r\n", currentLineCharInfo[.x + 1].StartPos, currentLineCharInfo[.x].StartPos + sz.cx)
-						OutputDebugString(buf)
-*/
 					End If
 				End If
@@ -207,5 +201,7 @@
 
 		'Draw the text buffer added
-		DrawPromptBuffer(hdc, StartLine, .y)
+		'DrawPromptBuffer(hdc, StartLine, .y)
+		InvalidateRect(_PromptSys_hWnd, ByVal 0, TRUE)
+		UpdateWindow(_PromptSys_hWnd)
 		SelectObject(hdc, hOldFont)
 		ReleaseDC(_PromptSys_hWnd, hdc)
@@ -262,4 +258,25 @@
 		.cy = tm.tmHeight
 	End With
+
+	'_PromptSys_hFont initialize
+	Dim lf As LOGFONT
+	With lf
+		.lfHeight = -MulDiv(12, GetDeviceCaps(hdc, LOGPIXELSY), 72)
+		.lfWidth = 0
+		.lfEscapement = 0
+		.lfOrientation = 0
+		.lfWeight = 0
+		.lfItalic = 0
+		.lfUnderline = 0
+		.lfStrikeOut = 0
+		.lfCharSet = SHIFTJIS_CHARSET
+		.lfOutPrecision = OUT_DEFAULT_PRECIS
+		.lfClipPrecision = CLIP_DEFAULT_PRECIS
+		.lfQuality = DEFAULT_QUALITY
+		.lfPitchAndFamily = FIXED_PITCH
+		lstrcpy(.lfFaceName, ToTCStr("ＭＳ 明朝"))
+	End With
+
+	_PromptSys_hFont = CreateFontIndirect(lf)
 
 	ReleaseDC(hwnd, hdc)
@@ -378,5 +395,5 @@
 Function _PromptWnd_GetCompositionStringW(himc As HIMC, ByRef rpsz As PWSTR) As Long
 	Dim size = ImmGetCompositionStringW(himc, GCS_RESULTSTR, 0, 0) 'sizeはバイト単位
-	rpsz = _System_malloc(size) As PWSTR
+	rpsz = GC_malloc(size) As PWSTR
 	If rpsz = 0 Then
 		'Debug
@@ -388,5 +405,5 @@
 Function _PromptWnd_GetCompositionStringA(himc As HIMC, ByRef rpsz As PSTR) As Long
 	Dim size = ImmGetCompositionStringA(himc, GCS_RESULTSTR, 0, 0) 'sizeはバイト単位
-	rpsz = _System_malloc(size) As PSTR
+	rpsz = GC_malloc(size) As PSTR
 	If rpsz = 0 Then
 		'Debug
@@ -423,5 +440,4 @@
 #endif
 		ImmReleaseContext(hwnd, himc)
-		_System_free(str)
 
 		ActiveBasic.Strings.ChrCopy(VarPtr(_PromptSys_InputStr[_PromptSys_InputLen]), tempStr.StrPtr, tempStr.Length As SIZE_T)
@@ -439,6 +455,4 @@
 
 Function PromptMain(dwData As Long) As Long
-	GetVersionEx(_System_OSVersionInfo)
-
 	Dim i As Long
 	'Allocate
@@ -460,25 +474,4 @@
 		.cy = GetSystemMetrics(SM_CYSCREEN)
 	End With
-
-	'_PromptSys_hFont initialize
-	Dim lf As LOGFONT
-	With lf
-		.lfHeight = -16
-		.lfWidth = 0
-		.lfEscapement = 0
-		.lfOrientation = 0
-		.lfWeight = 0
-		.lfItalic = 0
-		.lfUnderline = 0
-		.lfStrikeOut = 0
-		.lfCharSet = SHIFTJIS_CHARSET
-		.lfOutPrecision = OUT_DEFAULT_PRECIS
-		.lfClipPrecision = CLIP_DEFAULT_PRECIS
-		.lfQuality = DEFAULT_QUALITY
-		.lfPitchAndFamily = FIXED_PITCH
-		lstrcpy(.lfFaceName, ToTCStr("ＭＳ 明朝"))
-	End With
-
-	_PromptSys_hFont = CreateFontIndirect(lf)
 
 	'Critical Section
@@ -604,5 +597,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
 
@@ -624,5 +617,5 @@
 	Dim i = _PromptSys_TextLine[y].Length
 	If i < x Then
-		_System_FillChar(VarPtr(_PromptSys_TextLine[y].Text[i]), x - i, &h20 As StrChar) 'Asc(" ")
+		ActiveBasic.Strings.ChrFill(VarPtr(_PromptSys_TextLine[y].Text[i]), x - i, &h20 As StrChar) 'Asc(" ")
 		Dim i2 As Long
 		For i2 = i To ELM(x)
@@ -664,12 +657,12 @@
 		Ellipse(_PromptSys_hMemDC,x-radius,y-radi2,x+radius,y+radi2)
 	Else
-		Dim sw As Long
+		Dim sw As Boolean
 		StartPos *=StartPos
 		EndPos *=EndPos
 
 		If StartPos<0 Or EndPos<0 Then
-			sw=1
+			sw = True
 		Else
-			sw=0
+			sw = False
 		End If
 
Index: /trunk/Include/objidl.sbp
===================================================================
--- /trunk/Include/objidl.sbp	(revision 410)
+++ /trunk/Include/objidl.sbp	(revision 411)
@@ -131,5 +131,26 @@
 End Interface
 
-' IExternalCennection
+/* interface IExternalConnection */
+/* [uuid][local][object] */ 
+
+Const Enum EXTCONN
+	EXTCONN_STRONG = 1
+	EXTCONN_WEAK = 2
+	EXTCONN_CALLABLE = 4
+End Enum
+
+Dim IID_IExternalConnection = [&h00000019, 0, 0, [&hC0, 0, 0, 0, 0, 0, 0, &h46]] As IID
+
+Interface IExternalConnection
+	Inherits IUnknown
+    
+	Function AddConnection(
+		/* [in] */ extconn As DWord,
+		/* [in] */ reserved As DWord) As DWord
+	Function ReleaseConnection( 
+		/* [in] */ extconn As DWord,
+		/* [in] */ reserved As DWord,
+		/* [in] */ fLastReleaseCloses As BOOL) As DWord
+End Interface
 
 Type MULTI_QI
Index: /trunk/Include/system/exception.ab
===================================================================
--- /trunk/Include/system/exception.ab	(revision 410)
+++ /trunk/Include/system/exception.ab	(revision 411)
@@ -28,4 +28,5 @@
 
 	Sub FinishFinally()
+		Imports System.Threading
 		If Thread.CurrentThread().__IsThrowing() Then
 			Throw Thread.CurrentThread().__GetThrowintParamObject()
@@ -34,4 +35,7 @@
 
 	Function ResolveCatchesOverload( ex As Object ) As LONG_PTR
+		OutputDebugString("ResolveCatchesOverload: ")
+		OutputDebugString(ToTCStr(ex.ToString))
+		OutputDebugString(Ex"\r\n")
 		Dim defaultCatchCodePos = 0 As LONG_PTR
 		Dim pos = 0 As Long
@@ -66,6 +70,13 @@
 		Return defaultCatchCodePos
 	End Function
-
+Private
 	Function isCatchable(paramName As String, catchType As System.TypeInfo) As Boolean
+/*		If Not String.IsNullOrEmpty(paramName) Then
+			Dim paramType = _System_TypeBase_Search(paramName)
+			isCatchable = ActiveBasic.Detail.IsBaseOf(catchType, paramType)
+		Else
+			isCatchable = False
+		End If
+/*/
 		isCatchable = False
 		While Not ActiveBasic.IsNothing(catchType)
@@ -77,4 +88,5 @@
 			catchType = catchType.BaseType
 		Wend
+'*/
 	End Function
 End Class
@@ -112,5 +124,5 @@
 
 	Static Function BeginTryScope( catchTable As *LONG_PTR, addressOfFinally As VoidPtr, basePtr As LONG_PTR, stackPtr As LONG_PTR ) As TryLayer
-		Return _System_pobj_AllThreads->GetCurrentException()->_BeginTryScope( catchTable, addressOfFinally, basePtr, stackPtr )
+		Return _System_pobj_AllThreads->GetCurrentException()._BeginTryScope( catchTable, addressOfFinally, basePtr, stackPtr )
 	End Function
 
@@ -127,5 +139,5 @@
 
 			'TODO: 適切なエラー処理
-			MessageBox( NULL, "Catchされていない例外があります", NULL, MB_OK or MB_ICONEXCLAMATION )
+			MessageBox( NULL, ToTCStr(Ex"Catchされていない例外があります\r\n" + ex.ToString), NULL, MB_OK or MB_ICONEXCLAMATION )
 			Debug
 			Return
@@ -133,4 +145,5 @@
 
 		' スレッドへThrow処理を開始したことを通知
+		Imports System.Threading
 		Thread.CurrentThread().__Throw( ex )
 
Index: /trunk/TestCase/SimpleTestCase/EncodingTest.ab
===================================================================
--- /trunk/TestCase/SimpleTestCase/EncodingTest.ab	(revision 411)
+++ /trunk/TestCase/SimpleTestCase/EncodingTest.ab	(revision 411)
@@ -0,0 +1,41 @@
+Imports System.Text
+Imports System.Text.Detail
+
+Namespace EncodingTest
+
+Sub TestMain()
+	'abcαβγアイウ（漢字拡張Bから3文字）
+	Dim chars[ELM(15)] = [
+		&h61, &h62, &h63,
+		&h03b1, &h03b2, &h03b3,
+		&h30a2, &h30a4, &h30a6,
+		&hd840, &hdc00, &hd840, &hdc01, &hd840, &hdc02] As WCHAR
+	Dim utf32bytes[ELM(12)] = [
+		&h61, &h62, &h63,
+		&h03b1, &h03b2, &h03b3,
+		&h30a2, &h30a4, &h30a6,
+		&h20000, &h20001, &h20002] As DWORD
+	Dim utf8bytes[ELM(30)] = [
+		&h61, &h62, &h63,
+		&hce, &hb1, &hce, &hb2, &hce, &hb3,
+		&he3, &h82, &ha2, &he3, &h82, &ha4, &he3, &h82, &ha6,
+		&hf0, &ha0, &h80, &h80, &hf0, &ha0, &h80, &h81, &hf0, &ha0, &h80, &h82] As Byte
+	Dim cp932bytes[ELM(15)] = [
+		&h61, &h62, &h63,
+		&h83, &hbf, &h83, &hc0, &h83, &hc1,
+		&h83, &h41, &h83, &h43, &h83, &h45] As Byte '拡張Bは省略
+
+	Dim utf8 = New UTF8Encoding
+	Dim e = utf8.GetEncoder
+	Dim d = utf8.GetDecoder
+	Dim b[256] As Byte
+	Dim u16[256] As WCHAR
+	e.GetBytes(chars, Len(chars) \ SizeOf (WCHAR), b, Len(b), False)
+	UnitTest("UTF8 Encode", memcmp(b, utf8bytes, Len(utf8bytes)) = 0)
+	d.GetChars(utf8bytes, Len(utf8bytes), u16, Len(u16) \ SizeOf (WCHAR), False)
+	UnitTest("UTF8 Decode", memcmp(u16, chars, Len(chars)) = 0)
+End Sub
+
+End Namespace
+
+EncodingTest.TestMain()
Index: /trunk/TestCase/SimpleTestCase/PathTest.ab
===================================================================
--- /trunk/TestCase/SimpleTestCase/PathTest.ab	(revision 410)
+++ /trunk/TestCase/SimpleTestCase/PathTest.ab	(revision 411)
@@ -39,8 +39,4 @@
 
 End Namespace
-Try
+
 PathTest.TestMain()
-Catch e As System.Exception
-	Debug
-	Print e.ToString()
-End Try
Index: /trunk/TestCase/SimpleTestCase/SimpleTestCase.idx
===================================================================
--- /trunk/TestCase/SimpleTestCase/SimpleTestCase.idx	(revision 410)
+++ /trunk/TestCase/SimpleTestCase/SimpleTestCase.idx	(revision 411)
@@ -32,2 +32,4 @@
 #include "TypeInfoTest.ab"
 _ClearNamespaceImported
+#include "EncodingTest.ab"
+_ClearNamespaceImported
Index: /trunk/TestCase/SimpleTestCase/SimpleTestCase.pj
===================================================================
--- /trunk/TestCase/SimpleTestCase/SimpleTestCase.pj	(revision 410)
+++ /trunk/TestCase/SimpleTestCase/SimpleTestCase.pj	(revision 411)
@@ -23,5 +23,5 @@
 #DEBUG_EXE_PATH=
 
-#RESOURCE=0
+#RESOURCE=SimpleTestCase.rc
 
 #SOURCE
@@ -41,2 +41,3 @@
 ExceptionTest.ab
 TypeInfoTest.ab
+EncodingTest.ab
