Index: trunk/Include/Classes/ActiveBasic/CType/CType.ab
===================================================================
--- trunk/Include/Classes/ActiveBasic/CType/CType.ab	(revision 388)
+++ trunk/Include/Classes/ActiveBasic/CType/CType.ab	(revision 388)
@@ -0,0 +1,238 @@
+/*!
+@file	Classes/ActiveBasic/CType/CType.ab
+@brief	ASCII文字分類関数群
+@author	Egtra
+@date	2007/11/25
+*/
+
+Namespace ActiveBasic
+Namespace CType
+
+Namespace Detail
+
+Function Widen(c As CHAR) As WCHAR
+	Return c As Byte As WCHAR
+End Function
+
+Function Narrow(c As WCHAR) As CHAR
+	Return c As Byte As CHAR
+End Function
+
+End Namespace 'Detail
+
+/*!
+@brief	ASCIIのアルファベットまたは数字かどうか
+@author	Egtra
+@date	2007/11/25
+*/
+Function IsAlnum(c As WCHAR) As Boolean
+	Return IsUpper(c) Or IsLower(c) Or IsDigit(c)
+End Function
+
+/*!
+@brief	ASCIIのアルファベットかどうか
+@author	Egtra
+@date	2007/11/25
+*/
+Function IsAlpha(c As WCHAR) As Boolean
+	Return IsUpper(c) Or IsLower(c)
+End Function
+
+/*!
+@brief	ASCIIの行内に置ける空白文字かどうか
+@author	Egtra
+@date	2007/11/25
+ようするにASCIIでは空白とタブ
+*/
+Function IsBlank(c As WCHAR) As Boolean
+	Return c = &h20 Or c = &h09 'space or tab
+End Function
+
+/*!
+@brief	ASCIIの制御文字かどうか
+@author	Egtra
+@date	2007/11/25
+*/
+Function IsCntrl(c As WCHAR) As Boolean
+	Return c < &h20 Or c = &h7f
+End Function
+
+/*!
+@brief	ASCIIの数字かどうか
+@author	Egtra
+@date	2007/11/25
+*/
+Function IsDigit(c As WCHAR) As Boolean
+	Return (c As DWord Xor &h30) < 10
+End Function
+
+/*!
+@brief	ASCIIの図形文字かどうか
+@author	Egtra
+@date	2007/11/25
+図形文字とは、空白以外の表示文字
+*/
+Function IsGraph(c As WCHAR) As Boolean
+	Return (c As DWord - &h21) < (&h7e - &h21)
+End Function
+
+/*!
+@brief	ASCIIのアルファベッの小文字かどうか
+@author	Egtra
+@date	2007/11/25
+*/
+Function IsLower(c As WCHAR) As Boolean
+	Return c As DWord - &h61 < 26 ' &h61 = Asc("a")
+End Function
+
+Function IsPrint(c As WCHAR) As Boolean
+	Return (c As DWord - &h20) < (&h7e - &h20)
+End Function
+
+/*!
+@brief	ASCIIの区切り数字かどうか
+@author	Egtra
+@date	2007/11/25
+アルファベットでも数字でもない図形文字のこと
+*/
+Function IsPunct(c As WCHAR) As Boolean
+	Return c < &h7f And IsGraph(c) And (Not IsAlnum(c))
+End Function
+
+/*!
+@brief	ASCIIのアルファベットの大文字かどうか
+@author	Egtra
+@date	2007/11/25
+*/
+Function IsUpper(c As WCHAR) As Boolean
+	Return c As DWord - &h41 < 26 ' &h41 = Asc("A")
+End Function
+
+/*!
+@brief	ASCIIの十六進法で記す際に用いられる文字かどうか
+@author	Egtra
+@date	2007/11/25
+*/
+Function IsXDigit(c As WCHAR) As Boolean
+	Return IsDigit(c) Or ((c As DWord And (Not &h20)) - &h41 < 5)
+End Function
+
+/*!
+@brief	ASCIIのアルファベット大文字を小文字にする
+@author	Egtra
+@date	2007/11/25
+*/
+Function ToLower(c As WCHAR) As WCHAR
+	If IsUpper(c) Then
+		Return c Or &h20
+	Else
+		Return c
+	End If
+End Function
+
+/*!
+@brief	ASCIIのアルファベット小文字を大文字にする
+@author	Egtra
+@date	2007/11/25
+*/
+Function ToUpper(c As WCHAR) As WCHAR
+	If IsLower(c) Then
+		Return c And (Not &h20)
+	Else
+		Return c
+	End If
+End Function
+
+/*!
+@overload
+*/
+Function IsAlnum(c As CHAR) As Boolean
+	Return IsAlnum(Detail.Widen(c))
+End Function
+
+/*!
+@overload
+*/
+Function IsAlpha(c As CHAR) As Boolean
+	Return IsAlpha(Detail.Widen(c))
+End Function
+
+/*!
+@overload
+*/
+Function IsBlank(c As CHAR) As Boolean
+	Return IsBlank(Detail.Widen(c))
+End Function
+
+/*!
+@overload
+*/
+Function IsCntrl(c As CHAR) As Boolean
+	Return IsCntrl(Detail.Widen(c))
+End Function
+
+/*!
+@overload
+*/
+Function IsDigit(c As CHAR) As Boolean
+	Return IsDigit(Detail.Widen(c))
+End Function
+
+/*!
+@overload
+*/
+Function IsGraph(c As CHAR) As Boolean
+	Return IsGraph(Detail.Widen(c))
+End Function
+
+/*!
+@overload
+*/
+Function IsLower(c As CHAR) As Boolean
+	Return IsLower(Detail.Widen(c))
+End Function
+
+/*!
+@overload
+*/
+Function IsPrint(c As CHAR) As Boolean
+	Return IsPrint(Detail.Widen(c))
+End Function
+
+/*!
+@overload
+*/
+Function IsPunct(c As CHAR) As Boolean
+	Return IsPunct(Detail.Widen(c))
+End Function
+
+/*!
+@overload
+*/
+Function IsUpper(c As CHAR) As Boolean
+	Return IsUpper(Detail.Widen(c))
+End Function
+
+/*!
+@overload
+*/
+Function IsXDigit(c As CHAR) As Boolean
+	Return IsXDigit(Detail.Widen(c))
+End Function
+
+/*!
+@overload
+*/
+Function ToLower(c As CHAR) As CHAR
+	Return Detail.Narrow(ToLower(Detail.Widen(c)))
+End Function
+
+/*!
+@overload
+*/
+Function ToUpper(c As CHAR) As CHAR
+	Return Detail.Narrow(ToUpper(Detail.Widen(c)))
+End Function
+
+End Namespace
+End Namespace
Index: trunk/Include/Classes/ActiveBasic/Strings/SPrintF.ab
===================================================================
--- trunk/Include/Classes/ActiveBasic/Strings/SPrintF.ab	(revision 387)
+++ trunk/Include/Classes/ActiveBasic/Strings/SPrintF.ab	(revision 388)
@@ -731,4 +731,10 @@
 End Function
 
+/*
+@brief	0からFまでの文字を収めた表
+@author	egtra
+*/
+Dim HexadecimalTable[&h10] = [&h30, &h31, &h32, &h33, &h34, &h35, &h36, &h37, &h38, &h39, &h41, &h42, &h43, &h44, &h45, &h46] As Byte
+
 /*!
 @author	Egtra
@@ -739,5 +745,5 @@
 	Dim x = xq As DWord
 	While x <> 0
-		buf[i] = _System_HexadecimalTable[x And &h0f]
+		buf[i] = HexadecimalTable[x And &h0f]
 		x >>= 4
 		i--
@@ -754,5 +760,5 @@
 	Dim i = MaxSizeLX
 	While x <> 0
-		buf[i] = _System_HexadecimalTable[x And &h0f]
+		buf[i] = HexadecimalTable[x And &h0f]
 		x >>= 4
 		i--
@@ -1270,5 +1276,5 @@
 				s.Append(FormatString(params[i] As String, precision, fieldWidth, flags))
 			Case &h63 'c
-				s.Append(FormatCharacter(params[i] As BoxedStrChar, precision, fieldWidth, flags) As Char)
+				s.Append(FormatCharacter(params[i] As BoxedStrChar, precision, fieldWidth, flags))
 '			Case &h6e 'n
 			Case &h25 '%
Index: trunk/Include/Classes/System/Environment.ab
===================================================================
--- trunk/Include/Classes/System/Environment.ab	(revision 387)
+++ trunk/Include/Classes/System/Environment.ab	(revision 388)
@@ -31,9 +31,8 @@
 	Static Function CurrentDirectory() As String
 		Dim size = GetCurrentDirectory(0, 0)
-		Dim p = _System_malloc(SizeOf (TCHAR) * size) As PCTSTR
+		Dim p = GC_malloc_atomic(SizeOf (TCHAR) * size) As PCTSTR
 		Dim len = GetCurrentDirectory(size, p)
 		If len < size Then
 			CurrentDirectory = New String(p, size As Long)
-			_System_free(p)
 		End If
 	End Function
@@ -92,8 +91,7 @@
 		If Object.ReferenceEquals(sysDir, Nothing) Then
 			Dim size = GetSystemDirectory(0, 0)
-			Dim p = _System_malloc(SizeOf (TCHAR) * size) As PTSTR
+			Dim p = GC_malloc_atomic(SizeOf (TCHAR) * size) As PTSTR
 			Dim len = GetSystemDirectory(p, size)
 			sysDir = New String(p, len As Long)
-			_System_free(p)
 		End If
 		Return sysDir
@@ -145,8 +143,7 @@
 		Dim src = ToTCStr(s)
 		Dim size = ExpandEnvironmentStrings(src, 0, 0)
-		Dim dst = _System_malloc(SizeOf (TCHAR) * size) As PTSTR
+		Dim dst = GC_malloc_atomic(SizeOf (TCHAR) * size) As PTSTR
 		ExpandEnvironmentStrings(src, dst, size)
 		ExpandEnvironmentVariables = New String(dst, size - 1)
-		_System_free(dst)
 	End Function
 
@@ -160,8 +157,7 @@
 		Dim tcsVariable = ToTCStr(variable)
 		Dim size = _System_GetEnvironmentVariable(tcsVariable, 0, 0)
-		Dim p = _System_malloc(SizeOf (TCHAR) * size) As PTSTR
+		Dim p = GC_malloc_atomic(SizeOf (TCHAR) * size) As PTSTR
 		Dim len = _System_GetEnvironmentVariable(tcsVariable, p, size)
 		GetEnvironmentVariable = New String(p, len As Long)
-		_System_free(p)
 	End Function
 
Index: trunk/Include/Classes/System/IO/FileStream.ab
===================================================================
--- trunk/Include/Classes/System/IO/FileStream.ab	(revision 387)
+++ trunk/Include/Classes/System/IO/FileStream.ab	(revision 388)
@@ -1,5 +1,4 @@
 Namespace System
 Namespace IO
-
 
 /* ほんとはmiscに入れるかかファイルを分けたほうがいいかもしれないが一先ず実装 */
@@ -28,6 +27,6 @@
 	fileShare As DWord
 	fileOptions As DWord
-	fileReadOverlapped As OVERLAPPED
-	fileWriteOverlapped As OVERLAPPED
+	
+	offset As QWord 'オーバーラップドIO用
 
 Public
@@ -108,4 +107,5 @@
 		This.fileShare = sh
 		This.fileOptions = op
+		This.offset = 0
 	End Sub
 	Sub FileStream(path As String, mode As FileMode, access As FileAccess, share As FileShare)
@@ -133,10 +133,4 @@
 		This.FileStream(path,mode,access,FileShare.None,FileOptions.None)
 	End Sub
-
-	Sub ~FileStream()
-		This.Flush()
-		This.Close()
-	End Sub
-
 Public
 	Override Function CanRead() As Boolean
@@ -176,5 +170,5 @@
 	Function IsAsync() As Boolean
 		/* ファイルが非同期操作に対応しているかを返す */
-		If This.fileOptions=FILE_FLAG_OVERLAPPED/*FileOptions.Asynchronous*/ Then
+		If This.fileOptions And FILE_FLAG_OVERLAPPED /*FileOptions.Asynchronous*/ Then
 			Return True
 		Else
@@ -187,10 +181,10 @@
 			Dim length As LARGE_INTEGER
 			length.LowPart=GetFileSize(This.handle,VarPtr(length.HighPart) As *DWord)
-			Return MAKEQWORD(length.LowPart,length.HighPart)
+			Return MAKEQWORD(length.LowPart,length.HighPart) As Int64
 		End If
 	End Function
 
 	Function Name() As String
-		Return New String(This.filePath)
+		Return This.filePath
 	End Function
 	
@@ -198,8 +192,5 @@
 		If This.CanSeek() Then
 			If This.IsAsync() Then
-				fileReadOverlapped.Offset=LODWORD(value)
-				fileReadOverlapped.OffsetHigh=HIDWORD(value)
-				fileWriteOverlapped.OffsetHigh=LODWORD(value)
-				fileWriteOverlapped.OffsetHigh=HIDWORD(value)
+				offset = value As QWord
 			Else
 				Dim position As LARGE_INTEGER
@@ -213,10 +204,10 @@
 		If This.CanSeek() Then
 			If This.IsAsync() Then
-				Return MAKEQWORD(fileReadOverlapped.Offset,fileReadOverlapped.OffsetHigh)
+				Return offset As Int64
 			Else
 				Dim position As LARGE_INTEGER
 				ZeroMemory(VarPtr(position),SizeOf(LARGE_INTEGER))
 				position.LowPart=SetFilePointer(This.handle,position.LowPart,VarPtr(position.HighPart) As *DWord,FILE_CURRENT)
-				Return MAKEQWORD(position.LowPart,position.HighPart)
+				Return MAKEQWORD(position.LowPart,position.HighPart) As Int64
 			End If
 		End If
@@ -257,19 +248,16 @@
 	End Function
 
-	Override Sub Close()
-		This.Dispose()
-	End Sub
-
 /*	CreateObjRef*/
 	
-	Override Sub Dispose()
+	Override Sub Dispose(disposing As Boolean)
+		Flush()
 		CloseHandle(InterlockedExchangePointer(VarPtr(This.handle),NULL))
 	End Sub
 
-	Override Function EndRead(ByRef asyncResult As System.IAsyncResult) As Long
-		'TODO
-	End Function
-
-	Override Sub EndWrite(ByRef asyncResult As System.IAsyncResult)
+	Override Function EndRead(asyncResult As System.IAsyncResult) As Long
+		'TODO
+	End Function
+
+	Override Sub EndWrite(asyncResult As System.IAsyncResult)
 		'TODO
 	End Sub
@@ -298,22 +286,30 @@
 
 	Sub Lock(position As Int64, length As Int64)
+		If position < 0 Then
+			Throw New ArgumentOutOfRangeException("FileStream.Lock: An argument is negative value.", New System.Int64(position), "position")
+		ElseIf length < 0 Then
+			Throw New ArgumentOutOfRangeException("FileStream.Lock: An argument is negative value.", New System.Int64(length), "length")
+		End If
+		LockFile(handle, LODWORD(position As QWord), HIDWORD(position As QWord),
+			LODWORD(length As QWord), HIDWORD(length As QWord))
 	End Sub
 
 	Override Function Read( buffer As *Byte, offset As Long, count As Long) As Long
 		If This.CanRead() Then
-			Dim ret As DWord
-			If This.IsAsync() Then
-				ReadFile(This.handle,VarPtr(buffer[offset]),count,VarPtr(ret),This.fileReadOverlapped)
-				While This.fileReadOverlapped.Internal=STATUS_PENDING
-				Wend
-				fileReadOverlapped.Offset+=LODWORD(ret)
-				fileReadOverlapped.OffsetHigh+=HIDWORD(ret)
-				fileWriteOverlapped.Offset+=LODWORD(ret)
-				fileWriteOverlapped.OffsetHigh+=HIDWORD(ret)
-				Return ret
-			Else
-				ReadFile(This.handle,VarPtr(buffer[offset]),count,VarPtr(ret),ByVal NULL)
-				Return ret
-			End If
+			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)
+				If ret = FALSE Then
+					If GetLastError() = ERROR_IO_PENDING Then
+						GetOverlappedResult(This.handle, overlapped, readBytes, TRUE)
+					End If
+				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
@@ -326,18 +322,9 @@
 				Select Case origin
 					Case SeekOrigin.Begin
-						fileReadOverlapped.Offset=LODWORD(offset)
-						fileReadOverlapped.OffsetHigh=HIDWORD(offset)
-						fileWriteOverlapped.OffsetHigh=LODWORD(offset)
-						fileWriteOverlapped.OffsetHigh=HIDWORD(offset)
+						This.offset = offset
 					Case SeekOrigin.Current
-						fileReadOverlapped.Offset+=LODWORD(offset)
-						fileReadOverlapped.OffsetHigh+=HIDWORD(offset)
-						fileWriteOverlapped.Offset+=LODWORD(offset)
-						fileWriteOverlapped.OffsetHigh+=HIDWORD(offset)
+						This.offset += offset
 					Case SeekOrigin.End
-						fileReadOverlapped.Offset=LODWORD(This.Length()+offset)
-						fileReadOverlapped.OffsetHigh=HIDWORD(This.Length()+offset)
-						fileWriteOverlapped.Offset=LODWORD(This.Length()+offset)
-						fileWriteOverlapped.OffsetHigh=HIDWORD(This.Length()+offset)
+						This.offset = This.Length + offset
 				End Select
 			Else
@@ -379,19 +366,29 @@
 
 	Sub Unlock(position As Int64, length As Int64)
-	End Sub
+		If position < 0 Then
+			Throw New ArgumentOutOfRangeException("FileStream.Lock: An argument is negative value.", New System.Int64(position), "position")
+		ElseIf length < 0 Then
+			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),
+			LODWORD(length As QWord), HIDWORD(length As QWord))
+	End Sub
+
 
 	Override Sub Write(buffer As *Byte, offset As Long, count As Long)
 		If This.CanWrite() Then
-			Dim ret As DWord
-			If This.IsAsync() Then
-				WriteFile(This.handle,VarPtr(buffer[offset]),count,VarPtr(ret),This.fileWriteOverlapped)
-				While This.fileReadOverlapped.Internal=STATUS_PENDING
-				Wend
-				This.fileReadOverlapped.Offset+=LODWORD(ret)
-				This.fileReadOverlapped.OffsetHigh+=HIDWORD(ret)
-				This.fileWriteOverlapped.Offset+=LODWORD(ret)
-				This.fileWriteOverlapped.OffsetHigh+=HIDWORD(ret)
-			Else
-				WriteFile(This.handle,VarPtr(buffer[offset]),count,VarPtr(ret),ByVal NULL)
+			Dim writeBytes As DWord
+			If This.IsAsync() Then
+				Dim overlapped As OVERLAPPED
+				SetQWord(VarPtr(overlapped.Offset), offset)
+				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
+				End If
+				offset += writeBytes
+			Else
+				WriteFile(This.handle, VarPtr(buffer[offset]), count, VarPtr(writeBytes), ByVal NULL)
 			End If
 		End If
Index: trunk/Include/Classes/System/IO/Path.ab
===================================================================
--- trunk/Include/Classes/System/IO/Path.ab	(revision 387)
+++ trunk/Include/Classes/System/IO/Path.ab	(revision 388)
@@ -10,8 +10,8 @@
 Class Path
 Public
-	Static AltDirectorySeparatorChar = &H2F As Char '/
-	Static DirectorySeparatorChar = &H5C As Char    '\
-	Static PathSeparator = &H3B As Char             ';
-	Static VolumeSeparatorChar = &H3A As Char       ':
+	Static AltDirectorySeparatorChar = &H2F As StrChar '/
+	Static DirectorySeparatorChar = &H5C As StrChar    '\
+	Static PathSeparator = &H3B As StrChar             ';
+	Static VolumeSeparatorChar = &H3A As StrChar       ':
 
 	Static Function GetFileName(path As String) As String
@@ -121,9 +121,9 @@
 
 	Static Function Combine(path1 As String, path2 As String) As String
-		If path1.LastIndexOf(Chr$(VolumeSeparatorChar)) And path1.Length = 2 Then
+		If path1.LastIndexOf(VolumeSeparatorChar) And path1.Length = 2 Then
 			Return path1 + path2
 		End If
 
-		If path1.LastIndexOf(Chr$(DirectorySeparatorChar), ELM(path1.Length), 1) = -1 Then
+		If path1.LastIndexOf(DirectorySeparatorChar, ELM(path1.Length), 1) = -1 Then
 			Return path1 + Chr$(DirectorySeparatorChar) + path2
 		Else
@@ -133,14 +133,17 @@
 
 Private
-	Static Function getExtensionPosition(ByRef path As String) As Long
+	Static Function getExtensionPosition(path As String) As Long
 		Dim lastSepPos = getLastSeparatorPosision(path) As Long
-		getExtensionPosition = path.LastIndexOf(".", ELM(path.Length), path.Length - lastSepPos)
+		If lastSepPos = -1 Then 
+			lastSepPos = 0
+		End If
+		getExtensionPosition = path.LastIndexOf(Asc("."), ELM(path.Length), path.Length - lastSepPos)
 	End Function
 
-	Static Function getLastSeparatorPosision(ByRef path As String) As Long
-		Dim lastSepPos = path.LastIndexOf(Chr$(DirectorySeparatorChar)) As Long
+	Static Function getLastSeparatorPosision(path As String) As Long
+		Dim lastSepPos = path.LastIndexOf(DirectorySeparatorChar) As Long
 		If lastSepPos <> -1 Then Return lastSepPos
 
-		lastSepPos = path.LastIndexOf(Chr$(VolumeSeparatorChar))
+		lastSepPos = path.LastIndexOf(VolumeSeparatorChar)
 		Return lastSepPos
 	End Function
Index: trunk/Include/Classes/System/IO/Stream.ab
===================================================================
--- trunk/Include/Classes/System/IO/Stream.ab	(revision 387)
+++ trunk/Include/Classes/System/IO/Stream.ab	(revision 388)
@@ -10,5 +10,5 @@
 Public
 	Virtual Sub ~Stream()
-		This.Close()
+		This.Dispose(False)
 	End Sub
 Public
@@ -49,6 +49,10 @@
 	End Function
 	Virtual Sub Close()
-		This.Dispose()
+		Dispose(True)
 	End Sub
+	Virtual Sub Dispose()
+		Dispose(True)
+	End Sub
+	Virtual Sub Dispose(disposing As Boolean): 	End Sub
 	Virtual Function EndRead(ByRef asyncResult As System.IAsyncResult) As Long:	End Function
 	Virtual Sub EndWrite(ByRef asyncResult As System.IAsyncResult):	End Sub
Index: trunk/Include/Classes/System/Runtime/InteropServices/GCHandle.ab
===================================================================
--- trunk/Include/Classes/System/Runtime/InteropServices/GCHandle.ab	(revision 387)
+++ trunk/Include/Classes/System/Runtime/InteropServices/GCHandle.ab	(revision 388)
@@ -36,4 +36,7 @@
 
 	Static Function FromIntPtr(ip As LONG_PTR) As GCHandle
+		If ip = 0 Then
+			Throw New InvalidOperationException("GCHandle.FromIntPtr: ip is 0.")
+		End If
 		FromIntPtr = New GCHandle
 		FromIntPtr.handle = ip As VoidPtr
Index: trunk/Include/Classes/System/String.ab
===================================================================
--- trunk/Include/Classes/System/String.ab	(revision 387)
+++ trunk/Include/Classes/System/String.ab	(revision 388)
@@ -61,5 +61,5 @@
 		Sub String(initStr As PCWSTR, start As Long, length As Long)
 			If start < 0 Or length Or start + length < 0 Then
-				'Throw New ArgumentOutOfRangeException
+				Throw New ArgumentOutOfRangeException("String constractor: One or more arguments are out of range value.", "start or length or both")
 			End If
 			validPointerCheck(initStr + start, length)
@@ -78,6 +78,6 @@
 
 		Sub String(initStr As PCSTR, start As Long, length As Long)
-			If start < 0 Or length Or start + length < 0 Then
-				'Throw New ArgumentOutOfRangeException
+			If start < 0 Or length < 0 Then
+				Throw New ArgumentOutOfRangeException("String constructor: One or more arguments are out of range value.", "start or length or both")
 			End If
 			validPointerCheck(initStr + start, length)
@@ -97,5 +97,5 @@
 		End Sub
 
-		Sub String(sb As System.Text.StringBuilder)
+		Sub String(sb As Text.StringBuilder)
 			Chars = StrPtr(sb)
 			m_Length = sb.Length
@@ -246,8 +246,7 @@
 
 		Function CompareTo(y As Object) As Long
-			Dim s = y As String
-	'		If y is not String Then
-	'			Throw New ArgumentException
-	'		End If
+			If Not Object.Equals(This.GetType(), y.GetType()) Then
+				Throw New ArgumentException("String.CompareTo: An argument is out of range value.", "y")
+			End If
 			Return CompareTo(y As String)
 		End Function
@@ -348,7 +347,10 @@
 		Const Function Contains(s As String) As Boolean
 			If Object.ReferenceEquals(s, Nothing) Then
-				'Throw New ArgumentNullException
-			End If
-			Return IndexOf(s, 0, m_Length) >= 0
+				Throw New ArgumentNullException("String.Contains: An argument is out of range value.", "s")
+			ElseIf s = "" Then
+				Return True
+			Else
+				Return IndexOf(s, 0, m_Length) >= 0
+			End If
 		End Function
 
@@ -385,6 +387,5 @@
 			rangeCheck(startIndex, count)
 			If Object.ReferenceEquals(s, Nothing) Then
-				'Throw New ArgumentNullException
-				Debug
+				Throw New ArgumentNullException("String.IndexOf: An argument is out of range value.", "s")
 			End If
 
@@ -405,4 +406,34 @@
 		End Function
 
+		Const Function LastIndexOf(c As StrChar) As Long
+			Return lastIndexOf(c, m_Length - 1, m_Length)
+		End Function
+
+		Const Function LastIndexOf(c As StrChar, start As Long) As Long
+			rangeCheck(start)
+			Return lastIndexOf(c, start, start + 1)
+		End Function
+
+		Const Function LastIndexOf(c As StrChar, start As Long, count As Long) As Long
+			rangeCheck(start)
+			Dim lastFindPos = start - (count - 1)
+			If Not (m_Length > lastFindPos And lastFindPos >= 0) Then
+				Throw New ArgumentOutOfRangeException("String.LastIndexOf: An argument is out of range value.", "count")
+			End If
+			Return lastIndexOf(c, start, count)
+		End Function
+	Private
+		Const Function lastIndexOf(c As StrChar, start As Long, count As Long) As Long
+			Dim lastFindPos = start - (count - 1)
+			Dim i As Long
+			For i = start To lastFindPos Step -1
+				If Chars[i] = c Then
+					Return i
+				End If
+			Next
+			Return -1
+		End Function
+
+	Public
 		Const Function LastIndexOf(s As String) As Long
 			Return LastIndexOf(s, m_Length - 1, m_Length)
@@ -413,21 +444,19 @@
 		End Function
 
-		Const Function LastIndexOf(s As String, startIndex As Long, count As Long) As Long
+		Const Function LastIndexOf(s As String, start As Long, count As Long) As Long
 			If Object.ReferenceEquals(s, Nothing) Then
-				'Throw New ArgumentNullException
-				Debug
-			End If
-
-			If startIndex < 0 Or startIndex > m_Length - 1 Or _
-				count < 0 Or count > startIndex + 2 Then
-				'Throw New ArgumentOutOfRangeException
-				Debug
-			End If
-			Dim length = s.Length
+				Throw New ArgumentNullException("String.LastIndexOf: An argument is out of range value.", "s")
+			End If
+
+			If start < 0 Or start > m_Length - 1 Or _
+				count < 0 Or count > start + 2 Then
+				Throw New ArgumentOutOfRangeException("String.LastIndexOf: One or more arguments are out of range value.", "start or count or both")
+			End If
+			Dim length = s.m_Length
 			If length > m_Length Then Return -1
-			If length = 0 Then Return startIndex
+			If length = 0 Then Return start
 
 			Dim i As Long, j As Long
-			For i = startIndex To  startIndex - count + 1 Step -1
+			For i = start To  start - count + 1 Step -1
 				For j = length - 1 To 0 Step -1
 					If Chars[i + j] = s[j] Then
@@ -450,5 +479,5 @@
 
 		Const Function Insert(startIndex As Long, text As String) As String
-			Dim sb = New System.Text.StringBuilder(This)
+			Dim sb = New Text.StringBuilder(This)
 			sb.Insert(startIndex, text)
 			Return sb.ToString
@@ -471,5 +500,5 @@
 
 		Const Function Remove(startIndex As Long, count As Long) As String
-			Dim sb = New System.Text.StringBuilder(This)
+			Dim sb = New Text.StringBuilder(This)
 			sb.Remove(startIndex, count)
 			Remove = sb.ToString
@@ -486,5 +515,5 @@
 
 		Const Function Replace(oldChar As StrChar, newChar As StrChar) As String
-			Dim sb = New System.Text.StringBuilder(This)
+			Dim sb = New Text.StringBuilder(This)
 			sb.Replace(oldChar, newChar)
 			Replace = sb.ToString
@@ -492,5 +521,5 @@
 
 		Const Function Replace(oldStr As String, newStr As String) As String
-			Dim sb = New System.Text.StringBuilder(This)
+			Dim sb = New Text.StringBuilder(This)
 			sb.Replace(oldStr, newStr)
 			Return sb.ToString
@@ -498,9 +527,9 @@
 
 		Const Function ToLower() As String
-			Dim sb = New System.Text.StringBuilder(m_Length)
+			Dim sb = New Text.StringBuilder(m_Length)
 			sb.Length = m_Length
 			Dim i As Long
 			For i = 0 To ELM(m_Length)
-				sb[i] = _System_ASCII_ToLower(Chars[i])
+				sb[i] = ActiveBasic.CType.ToLower(Chars[i])
 			Next
 			Return sb.ToString
@@ -508,9 +537,9 @@
 
 		Const Function ToUpper() As String
-			Dim sb = New System.Text.StringBuilder(m_Length)
+			Dim sb = New Text.StringBuilder(m_Length)
 			sb.Length = m_Length
 			Dim i As Long
 			For i = 0 To ELM(m_Length)
-				sb[i] = _System_ASCII_ToUpper(Chars[i])
+				sb[i] = ActiveBasic.CType.ToUpper(Chars[i])
 			Next
 			Return sb.ToString
@@ -539,5 +568,5 @@
 			Dim size = m_Length
 #endif
-			Return _System_GetHashFromWordArray(Chars As *Word, size) Xor size
+			Return _System_GetHashFromWordArray(Chars As *Word, size) Xor m_Length
 		End Function
 
@@ -548,10 +577,10 @@
 		Function PadLeft(total As Long, c As StrChar) As String
 			If total < 0 Then
-				'Throw New ArgumentException
+				Throw New ArgumentOutOfRangeException("String.PadLeft: An arguments is out of range value.", "total")
 			End If
 			If total >= m_Length Then
 				Return This
 			End If
-			Dim sb = New System.Text.StringBuilder(total)
+			Dim sb = New Text.StringBuilder(total)
 			sb.Append(c, total - m_Length)
 			sb.Append(This)
@@ -565,10 +594,10 @@
 		Function PadRight(total As Long, c As StrChar) As String
 			If total < 0 Then
-				'Throw New ArgumentException
+				Throw New ArgumentOutOfRangeException("String.PadRight: An arguments is out of range value.", "total")
 			End If
 			If total >= m_Length Then
 				Return This
 			End If
-			Dim sb = New System.Text.StringBuilder(total)
+			Dim sb = New Text.StringBuilder(total)
 			sb.Append(This)
 			sb.Append(c, total - m_Length)
@@ -596,5 +625,5 @@
 		Const Sub rangeCheck(index As Long)
 			If index < 0 Or index > m_Length Then
-				Debug 'ArgumentOutOfRangeException
+				Throw New ArgumentOutOfRangeException("String: An arguments is out of range value.", "index")
 			End If
 		End Sub
@@ -602,5 +631,5 @@
 		Const Sub rangeCheck(start As Long, length As Long)
 			If start < 0 Or start > This.m_Length Or length < 0 Then
-				Debug 'ArgumentOutOfRangeException
+				Throw New ArgumentOutOfRangeException("String: One or more arguments are out of range value.", "start or length or both")
 			End If
 		End Sub
Index: trunk/Include/Classes/System/Text/StringBuilder.ab
===================================================================
--- trunk/Include/Classes/System/Text/StringBuilder.ab	(revision 387)
+++ trunk/Include/Classes/System/Text/StringBuilder.ab	(revision 388)
@@ -128,8 +128,8 @@
 				Return This
 			Else
-				Throw New ArgumentNullException("StringBuilder.Append: An argument was null", "s")
+				Throw New ArgumentNullException("StringBuilder.Append: An argument is null", "s")
 			End If
 		ElseIf startIndex < 0 Or count < 0 Then
-			Throw New ArgumentOutOfRangeException("StringBuilder.Append: One or more arguments have out of range value.", "startIndex or count or both")
+			Throw New ArgumentOutOfRangeException("StringBuilder.Append: One or more arguments are out of range value.", "startIndex or count or both")
 		End If
 		appendCore(s, startIndex, count)
@@ -169,7 +169,7 @@
 	Const Sub CopyTo(sourceIndex As Long, ByRef dest[] As StrChar, destIndex As Long, count As Long)
 		If dest = 0 Then
-			Throw New ArgumentNullException("StringBuilder.CopyTo: An argument was null", "sourceIndex")
+			Throw New ArgumentNullException("StringBuilder.CopyTo: An argument is null", "sourceIndex")
 		ElseIf size < sourceIndex + count Or sourceIndex < 0 Or destIndex < 0 Or count < 0 Then
-			Throw New ArgumentOutOfRangeException("StringBuilder.CopyTo: One or more arguments have out of range value.", "startIndex or count or both")
+			Throw New ArgumentOutOfRangeException("StringBuilder.CopyTo: One or more arguments are out of range value.", "startIndex or count or both")
 		End If
 
@@ -179,5 +179,5 @@
 	Function EnsureCapacity(c As Long) As Long
 		If c < 0 Or c > MaxCapacity Then
-			Throw New ArgumentOutOfRangeException("StringBuilder.Append: An argument was out of range value.", "c")
+			Throw New ArgumentOutOfRangeException("StringBuilder.Append: An argument is out of range value.", "c")
 		ElseIf c > Capacity Then
 			Dim p = GC_malloc_atomic((c + 1) * SizeOf (StrChar)) As *StrChar
@@ -291,5 +291,5 @@
 		rangeCheck(index)
 		If n < 0 Then
-			Throw New ArgumentOutOfRangeException("StringBuilder.Insert: An argument was out of range value.", "n")
+			Throw New ArgumentOutOfRangeException("StringBuilder.Insert: An argument is out of range value.", "n")
 		End If
 		Dim len = x.Length
@@ -310,7 +310,7 @@
 		rangeCheck(i)
 		If x = 0 Then
-			Throw New ArgumentNullException("StringBuilder.Insert: An argument was null", "x")
+			Throw New ArgumentNullException("StringBuilder.Insert: An argument is null", "x")
 		ElseIf index < 0 Or count < 0 Then
-			Throw New ArgumentOutOfRangeException("StringBuilder.Append: One or more arguments have out of range value.", "index or count or both")
+			Throw New ArgumentOutOfRangeException("StringBuilder.Append: One or more arguments are out of range value.", "index or count or both")
 		End If
 
@@ -381,5 +381,5 @@
 	Sub replaceCore(oldStr As String, newStr As String, start As Long, count As Long)
 		If ActiveBasic.IsNothing(oldStr) Then
-			Throw New ArgumentNullException("StringBuilder.Replace: An argument was null", "oldStr")
+			Throw New ArgumentNullException("StringBuilder.Replace: An argument is null", "oldStr")
 		ElseIf oldStr.Length = 0 Then
 			Throw New ArgumentException("StringBuilder.Replace: The argument 'oldStr' is empty string. ", "oldStr")
@@ -428,5 +428,5 @@
 	Sub Capacity(c As Long)
 		If c < size Or c > MaxCapacity Then 'sizeとの比較でcが負の場合も対応
-			Throw New ArgumentOutOfRangeException("StringBuilder.Append: An argument have out of range value.", "c")
+			Throw New ArgumentOutOfRangeException("StringBuilder.Capacity: An argument is out of range value.", "c")
 		End If
 		EnsureCapacity(c)
@@ -435,5 +435,5 @@
 	Const Function Chars(i As Long) As StrChar
 		If i >= Length Or i < 0 Then
-			Throw New IndexOutOfRangeException("StringBuilder.Chars: The index argument 'i' have out of range value.")
+			Throw New IndexOutOfRangeException("StringBuilder.Chars: The index argument 'i' is out of range value.")
 		End If
 		Return chars[i]
@@ -442,5 +442,5 @@
 	Sub Chars(i As Long, c As StrChar)
 		If i >= Length Or i < 0 Then
-			Throw New ArgumentOutOfRangeException("StringBuilder.Chars: An argument have out of range value.", "i")
+			Throw New ArgumentOutOfRangeException("StringBuilder.Chars: An argument is out of range value.", "i")
 		End If
 		chars[i] = c
@@ -474,5 +474,5 @@
 	Sub initialize(capacity As Long, maxCapacity = LONG_MAX As Long)
 		If capacity < 0 Or maxCapacity < 1 Or maxCapacity < capacity Then
-			Throw New ArgumentOutOfRangeException("StringBuilder constructor: One or more arguments have out of range value.", "capacity or maxCapacity or both")
+			Throw New ArgumentOutOfRangeException("StringBuilder constructor: One or more arguments are out of range value.", "capacity or maxCapacity or both")
 		End If
 
@@ -506,5 +506,5 @@
 	Sub rangeCheck(index As Long)
 		If index < 0 Or index > size Then
-			Throw New ArgumentOutOfRangeException("StringBuilder: Index argument has out of range value.")
+			Throw New ArgumentOutOfRangeException("StringBuilder: Index argument is out of range value.")
 		End If
 	End Sub
@@ -517,5 +517,5 @@
 		'length < 0は判定に入っていないことに注意
 		If startIndex < 0 Or count < 0 Or startIndex + count > length Then
-			Throw New ArgumentOutOfRangeException("StringBuilder: One or more arguments have out of range value.", "startIndex or count or both")
+			Throw New ArgumentOutOfRangeException("StringBuilder: One or more arguments are out of range value.", "startIndex or count or both")
 		End If
 	End Sub
Index: trunk/Include/Classes/System/Threading/WaitHandle.ab
===================================================================
--- trunk/Include/Classes/System/Threading/WaitHandle.ab	(revision 387)
+++ trunk/Include/Classes/System/Threading/WaitHandle.ab	(revision 388)
@@ -38,5 +38,5 @@
 	End Sub
 
-	Override Sub Dispose()
+	Virtual Sub Dispose()
 		Dim hDisposing = InterlockedExchangePointer(h, 0)
 		If hDisposing <> 0 Then
@@ -49,5 +49,5 @@
 	End Function
 
-	Function WaitOne(millisecondsTimeout As Long, exitContext As BOOL) As Boolean
+	Function WaitOne(millisecondsTimeout As Long, exitContext As Boolean) As Boolean
 		Return WaitHandle.AfterWait(WaitForSingleObject(h, millisecondsTimeout As DWord), 1)
 	End Function
@@ -80,10 +80,8 @@
 
 Public
-	Static Function SignalAndWait(toSignal As WaitHandle, toWaitOn As WaitHandle, millisecondsTimeout As Long, exitContext As BOOL) As Boolean
+	Static Function SignalAndWait(toSignal As WaitHandle, toWaitOn As WaitHandle, millisecondsTimeout As Long, exitContext As Boolean) As Boolean
 		Dim pSignalObjectAndWait = GetProcAddress(GetModuleHandle("Kernel32.dll"), "SignalObjectAndWait") As Detail.PFNSignalObjectAndWait
 		If pSignalObjectAndWait = 0 Then
-			' PlatformNotSupportedException
-			Debug
-			ExitThread(-1)
+			Throw New PlatformNotSupportedException("WaitHandle.SignalAndWait: This platform doesn't supoort this operation.")
 		End If
 		Return WaitHandle.AfterWait(pSignalObjectAndWait(toSignal.Handle, toWaitOn.Handle, millisecondsTimeout As DWord, FALSE), 1)
Index: trunk/Include/Classes/System/Windows/Forms/Application.ab
===================================================================
--- trunk/Include/Classes/System/Windows/Forms/Application.ab	(revision 387)
+++ trunk/Include/Classes/System/Windows/Forms/Application.ab	(revision 388)
@@ -27,6 +27,9 @@
 		Return System.IO.Path.GetDirectoryName( ExecutablePath )
 	End Function
+
+	Static Sub ExitThread()
+		PostQuitMessage(0)
+	End Sub
 End Class
-
 	
 End Namespace
Index: trunk/Include/Classes/System/Windows/Forms/Control.ab
===================================================================
--- trunk/Include/Classes/System/Windows/Forms/Control.ab	(revision 387)
+++ trunk/Include/Classes/System/Windows/Forms/Control.ab	(revision 388)
@@ -4,4 +4,5 @@
 #define __SYSTEM_WINDOWS_FORMS_CONTROL_AB__
 
+/*
 #require <Classes/System/Windows/Forms/misc.ab>
 #require <Classes/System/Windows/Forms/CreateParams.ab>
@@ -11,12 +12,14 @@
 #require <Classes/System/Math.ab>
 #require <Classes/System/Threading/WaitHandle.ab>
+*/
 #require <Classes/System/Drawing/Color.ab>
 #require <Classes/System/Drawing/Point.ab>
 #require <Classes/System/Drawing/Size.ab>
 #require <Classes/System/Drawing/Rectangle.ab>
+/*
 #require <Classes/System/Runtime/InteropServices/GCHandle.ab>
 #require <Classes/ActiveBasic/Windows/WindowHandle.sbp>
 #require <Classes/ActiveBasic/Strings/Strings.ab>
-
+*/
 Namespace System
 Namespace Windows
@@ -143,21 +146,21 @@
 		End If
 	End Function
-
+/* BoundsSpecifiedが使用不能なのでコメントアウト
 	Sub Bounds(r As Rectangle)
 		SetBoundsCore(r.X, r.Y, r.Width, r.Height, BoundsSpecified.All)
 	End Sub
-
+*/
 	Const Function Location() As Point
 		Return Bounds.Location
 	End Function
-
+/*
 	Sub Location(p As Point)
 		SetBoundsCore(p.X, p.Y, 0, 0, BoundsSpecified.Location)
 	End Sub
-
+*/
 	Const Function Size() As Size
 		Return Bounds.Size
 	End Function
-
+/*
 	Sub Size(s As Size)
 		SetBoundsCore(0, 0, s.Width, s.Height, BoundsSpecified.Size)
@@ -171,41 +174,41 @@
 		Return ClientRectangle.Size
 	End Function
-
+*/
 	Const Function Left() As Long
 		Dim b = Bounds
 		Return b.Left
 	End Function
-
+/*
 	Sub Left(l As Long)
 		SetBoundsCore(l, 0, 0, 0, BoundsSpecified.X)
 	End Sub
-
+*/
 	Const Function Top() As Long
 		Dim b = Bounds
 		Return b.Top
 	End Function
-
+/*
 	Sub Top(t As Long)
 		SetBoundsCore(0, t, 0, 0, BoundsSpecified.Y)
 	End Sub
-
+*/
 	Const Function Width() As Long
 		Dim b = Bounds
 		Return b.Width
 	End Function
-
+/*
 	Sub Width(w As Long)
 		SetBoundsCore(0, 0, w, 0, BoundsSpecified.Width)
 	End Sub
-
+*/
 	Const Function Height() As Long
 		Dim b = Bounds
 		Return b.Height
 	End Function
-
+/*
 	Sub Height(h As Long)
 		SetBoundsCore(0, 0, 0, h, BoundsSpecified.Height)
 	End Sub
-
+*/
 	Const Function Right() As Long
 		Dim b = Bounds
@@ -273,32 +276,37 @@
 
 	Sub Control()
-		Debug
 		Dim sz = DefaultSize()
-		Control("", 100, 100, sz.Width, sz.Height)
+		init(Nothing, "", 100, 100, sz.Width, sz.Height)
 	End Sub
 
 	Sub Control(text As String)
 		Dim sz = DefaultSize()
-		Control(text, 100, 100, sz.Width, sz.Height)
+		init(Nothing, text, 100, 100, sz.Width, sz.Height)
 	End Sub
 
 	Sub Control(parent As Control, text As String)
 		Dim sz = DefaultSize()
-		Control(parent, text, 100, 100, sz.Width, sz.Height)
+		init(parent, text, 100, 100, sz.Width, sz.Height)
 	End Sub
 
 	Sub Control(text As String, left As Long, top As Long, width As Long, height As Long)
-		This.text = text
-		bkColor = DefaultBackColor
+		init(Nothing, text, left, top, width, height)
 	End Sub
 
 	Sub Control(parent As Control, text As String, left As Long, top As Long, width As Long, height As Long)
+		init(parent, text, left, top, width, height)
+	End Sub
+
+Private
+
+	Sub init(parent As Control, text As String, left As Long, top As Long, width As Long, height As Long)
 		This.parent = parent
-		Control(text, left, top, width, height)
-	End Sub
+'		CreateControl()
+	End Sub
+	
 
 	'---------------------------------------------------------------------------
 	' Destractor
-
+Public
 	Virtual Sub ~Control()
 		If Not Object.ReferenceEquals(wnd, Nothing) Then
@@ -398,6 +406,5 @@
 
 	Virtual Function DefaultSize() As Size
-		Dim s As Size(300, 300)
-		Return s
+		Return New Size(300, 300)
 	End Function
 
@@ -411,12 +418,15 @@
 	' Protected Methods
 	Virtual Sub CreateHandle()
+		Debug
+		If Not Object.ReferenceEquals(wnd, Nothing) Then
+			If wnd.HWnd <> 0 Then
+				Exit Sub
+			End If
+		End If
+		
 		Dim createParams = CreateParams()
 		Dim gch = System.Runtime.InteropServices.GCHandle.Alloc(This)
 		TlsSetValue(tlsIndex, System.Runtime.InteropServices.GCHandle.ToIntPtr(gch) As VoidPtr)
 		With createParams
-			Dim hwndParent = 0 As HWND
-			If Not Object.ReferenceEquals(parent, Nothing) Then
-				hwndParent = parent.Handle
-			End If
 			Dim pText As PCTSTR
 			If String.IsNullOrEmpty(text) Then
@@ -427,15 +437,17 @@
 
 			If CreateWindowEx(.ExStyle, atom As ULONG_PTR As PCSTR, pText, .Style, _
-				CW_USEDEFAULT, CW_USEDEFAULT, CW_USEDEFAULT, CW_USEDEFAULT, _
-				hwndParent, 0, hInstance, 0) = 0 Then
+				.X, .Y, .Width, .Height, _
+				.Parent, 0, hInstance, 0) = 0 Then
 				' Error
 				Dim buf[1023] As TCHAR
 				wsprintf(buf, ToTCStr(Ex"Control: CreateWindowEx failed. Error code: &h%08X\r\n"), GetLastError())
 				OutputDebugString(buf)
+
+				gch.Free()
 '				Debug
 				ExitThread(0)
 			End If
 		End With
-		gch.Free()
+		
 	End Sub
 
@@ -475,4 +487,8 @@
 				Case WM_DESTROY
 					OnHandleDestroyed(System.EventArgs.Empty)
+
+				Case WM_LBUTTONDOWN
+					Goto *ButtonDown
+*ButtonDown
 				Case Else
 					DefWndProc(m)
@@ -521,5 +537,5 @@
 	End Sub
 
-	Virtual Sub OnPaintBackground(e As PaintEventArgs) : End Sub
+'	Virtual Sub OnPaintBackground(e As PaintEventArgs) : End Sub
 	Virtual Sub OnEnabledChanged(e As System.EventArgs) : End Sub
 	Virtual Sub OnBackColorChanged(e As System.EventArgs) : End Sub
@@ -582,4 +598,9 @@
 			.Style = WS_OVERLAPPEDWINDOW
 			.ExStyle = WS_EX_APPWINDOW
+			.Caption = String.Empty
+			.X = 0
+			.Y = 0
+			.Width = 0
+			.Height = 0
 		End With
 	End Sub
@@ -608,4 +629,7 @@
 			rThis.wnd = New ActiveBasic.Windows.WindowHandle(hwnd)
 			SetWindowLongPtr(hwnd, GWLP_THIS, gchValue)
+		ElseIf msg = WM_NCDESTROY Then
+			Dim gch = System.Runtime.InteropServices.GCHandle.FromIntPtr(GetWindowLongPtr(hwnd, GWLP_THIS))
+			 gch.Free()
 		End If
 
Index: trunk/Include/Classes/System/Windows/Forms/Message.ab
===================================================================
--- trunk/Include/Classes/System/Windows/Forms/Message.ab	(revision 387)
+++ trunk/Include/Classes/System/Windows/Forms/Message.ab	(revision 388)
@@ -4,5 +4,5 @@
 #define __SYSTEM_WINDOWS_FORMS_MESSAGE_AB__
 
-#require <windows.sbp>
+'#require <windows.sbp>
 
 Namespace System
@@ -65,9 +65,9 @@
 	End Function
 
-	Const Function Operator ==(x As Message) As BOOL
+	Const Function Operator ==(x As Message) As Boolean
 		Return Equals(x)
 	End Function
 
-	Const Function Operator <>(x As Message) As BOOL
+	Const Function Operator <>(x As Message) As Boolean
 		Return Not Equals(x)
 	End Function
Index: trunk/Include/Classes/System/Windows/Forms/MessageBox.ab
===================================================================
--- trunk/Include/Classes/System/Windows/Forms/MessageBox.ab	(revision 387)
+++ trunk/Include/Classes/System/Windows/Forms/MessageBox.ab	(revision 388)
@@ -1,6 +1,6 @@
 'Classes/System/Windows/Forms/MessageBox.ab
 
-#require <Classes/System/Windows/Forms/misc.ab>
-#require <Classes/ActiveBasic/Windows/Windows.ab>
+'#require <Classes/System/Windows/Forms/misc.ab>
+'#require <Classes/ActiveBasic/Windows/Windows.ab>
 
 Namespace System
Index: trunk/Include/Classes/System/Windows/Forms/PaintEventArgs.ab
===================================================================
--- trunk/Include/Classes/System/Windows/Forms/PaintEventArgs.ab	(revision 387)
+++ trunk/Include/Classes/System/Windows/Forms/PaintEventArgs.ab	(revision 388)
@@ -3,6 +3,4 @@
 #ifndef __SYSTEM_WINDOWS_FORMS_PAINTEVENTARGS_AB__
 #define __SYSTEM_WINDOWS_FORMS_PAINTEVENTARGS_AB__
-
-#require <Classes/System/misc.ab>
 
 Namespace System
Index: trunk/Include/Classes/System/Windows/Forms/misc.ab
===================================================================
--- trunk/Include/Classes/System/Windows/Forms/misc.ab	(revision 387)
+++ trunk/Include/Classes/System/Windows/Forms/misc.ab	(revision 388)
@@ -9,7 +9,9 @@
 
 Interface IWin32Window
-	/*Const*/ Function Handle() As HWND
+	Function Handle() As HWND
 End Interface
 
+TypeDef BoundsSpecified = Long
+/*
 Enum BoundsSpecified
 	None = &h0
@@ -22,5 +24,7 @@
 	All = BoundsSpecified.Location Or BoundsSpecified.Size
 End Enum
-
+*/
+
+/*
 Enum Keys
 	LButton = VK_LBUTTON
@@ -208,4 +212,36 @@
 End Enum
 
+Enum MouseButtons
+	None = 0
+	Left = &h00100000
+	Right = &h00200000
+	Middle = &h00400000
+	XButton1 = &h00800000
+	XButton2 = &h01000000
+End Enum
+*/
+
+TypeDef DialogResult = DWord
+TypeDef MouseButtons = DWord
+
+Class MouseEventArgs
+	Inherits System.EventArgs
+Public
+
+	Sub MouseEventArgs(button As MouseButtons, clicks As Long, x As Long, y As Long, delta As Long)
+		MouseButton = button
+		Clicks = clicks
+		X = x
+		Y = y
+		Delta = delta
+	End Sub
+
+	Const MouseButton As MouseButtons
+	Const Clicks As Long
+	Const X As Long
+	Const Y As Long
+	Const Delta As Long
+End Class
+
 End Namespace 'Forms
 End Namespace 'Widnows
Index: trunk/Include/Classes/index.ab
===================================================================
--- trunk/Include/Classes/index.ab	(revision 387)
+++ trunk/Include/Classes/index.ab	(revision 388)
@@ -2,4 +2,5 @@
 #require "./ActiveBasic/Core/InterfaceInfo.ab"
 #require "./ActiveBasic/Core/TypeInfo.ab"
+#require "./ActiveBasic/CType/CType.ab"
 #require "./ActiveBasic/Math/Math.ab"
 #require "./ActiveBasic/Strings/SPrintF.ab"
