Merge pull request #111 from jacobsantos/feature/idispatch-fix-test

IDispatch test case fix
diff --git a/appveyor.yml b/appveyor.yml
index 4807935..845778d 100644
--- a/appveyor.yml
+++ b/appveyor.yml
@@ -42,7 +42,7 @@
   - choco install mingw
   - SET PATH=c:\tools\mingw64\bin;%PATH%
   # - Download COM Server
-  - ps: Start-FileDownload "https://github.com/go-ole/test-com-server/releases/download/v1.0.1/test-com-server-${env:DOWNLOADPLATFORM}.zip"
+  - ps: Start-FileDownload "https://github.com/go-ole/test-com-server/releases/download/v1.0.2/test-com-server-${env:DOWNLOADPLATFORM}.zip"
   - 7z e test-com-server-%DOWNLOADPLATFORM%.zip -oc:\gopath\src\github.com\go-ole\go-ole > NUL
   - c:\gopath\src\github.com\go-ole\go-ole\build\register-assembly.bat
   # - set
diff --git a/guid.go b/guid.go
index 7b3e33d..609ef0b 100644
--- a/guid.go
+++ b/guid.go
@@ -10,6 +10,9 @@
 	// IID_IDispatch is for IDispatch interfaces.
 	IID_IDispatch = &GUID{0x00020400, 0x0000, 0x0000, [8]byte{0xC0, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x46}}
 
+	// IID_IEnumVariant is for IEnumVariant interfaces
+	IID_IEnumVariant = &GUID{0x00020404, 0x0000, 0x0000, [8]byte{0xC0, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x46}}
+
 	// IID_IConnectionPointContainer is for IConnectionPointContainer interfaces.
 	IID_IConnectionPointContainer = &GUID{0xB196B284, 0xBAB4, 0x101A, [8]byte{0xB6, 0x9C, 0x00, 0xAA, 0x00, 0x34, 0x1D, 0x07}}
 
@@ -83,7 +86,7 @@
 	// CLSID_COMTestScalarClass is for COMTestScalarClass class.
 	//
 	// {865B85C5-0334-4AC6-9EF6-AACEC8FC5E86}
-	CLSID_COMTestScalarClass = &GUID{0x865b85c5, 0x3340, 0x4ac6, [8]byte{0x9e, 0xf6, 0xaa, 0xce, 0xc8, 0xfc, 0x5e, 0x86}}
+	CLSID_COMTestScalarClass = &GUID{0x865b85c5, 0x0334, 0x4ac6, [8]byte{0x9e, 0xf6, 0xaa, 0xce, 0xc8, 0xfc, 0x5e, 0x86}}
 )
 
 // GUID is Windows API specific GUID type.
diff --git a/idispatch_windows.go b/idispatch_windows.go
index d698b1e..10b1ae4 100644
--- a/idispatch_windows.go
+++ b/idispatch_windows.go
@@ -80,10 +80,14 @@
 				}
 			case *bool:
 				vargs[n] = NewVariant(VT_BOOL|VT_BYREF, int64(uintptr(unsafe.Pointer(v.(*bool)))))
-			case byte:
-				vargs[n] = NewVariant(VT_I1, int64(v.(byte)))
-			case *byte:
-				vargs[n] = NewVariant(VT_I1|VT_BYREF, int64(uintptr(unsafe.Pointer(v.(*byte)))))
+			case uint8:
+				vargs[n] = NewVariant(VT_I1, int64(v.(uint8)))
+			case *uint8:
+				vargs[n] = NewVariant(VT_I1|VT_BYREF, int64(uintptr(unsafe.Pointer(v.(*uint8)))))
+			case int8:
+				vargs[n] = NewVariant(VT_I1, int64(v.(int8)))
+			case *int8:
+				vargs[n] = NewVariant(VT_I1|VT_BYREF, int64(uintptr(unsafe.Pointer(v.(*uint8)))))
 			case int16:
 				vargs[n] = NewVariant(VT_I2, int64(v.(int16)))
 			case *int16:
@@ -92,22 +96,30 @@
 				vargs[n] = NewVariant(VT_UI2, int64(v.(uint16)))
 			case *uint16:
 				vargs[n] = NewVariant(VT_UI2|VT_BYREF, int64(uintptr(unsafe.Pointer(v.(*uint16)))))
-			case int, int32:
-				vargs[n] = NewVariant(VT_I4, int64(v.(int)))
-			case *int, *int32:
-				vargs[n] = NewVariant(VT_I4|VT_BYREF, int64(uintptr(unsafe.Pointer(v.(*int)))))
-			case uint, uint32:
-				vargs[n] = NewVariant(VT_UI4, int64(v.(uint)))
-			case *uint, *uint32:
-				vargs[n] = NewVariant(VT_UI4|VT_BYREF, int64(uintptr(unsafe.Pointer(v.(*uint)))))
+			case int32:
+				vargs[n] = NewVariant(VT_I4, int64(v.(int32)))
+			case *int32:
+				vargs[n] = NewVariant(VT_I4|VT_BYREF, int64(uintptr(unsafe.Pointer(v.(*int32)))))
+			case uint32:
+				vargs[n] = NewVariant(VT_UI4, int64(v.(uint32)))
+			case *uint32:
+				vargs[n] = NewVariant(VT_UI4|VT_BYREF, int64(uintptr(unsafe.Pointer(v.(*uint32)))))
 			case int64:
 				vargs[n] = NewVariant(VT_I8, int64(v.(int64)))
 			case *int64:
 				vargs[n] = NewVariant(VT_I8|VT_BYREF, int64(uintptr(unsafe.Pointer(v.(*int64)))))
 			case uint64:
-				vargs[n] = NewVariant(VT_UI8, v.(int64))
+				vargs[n] = NewVariant(VT_UI8, int64(uintptr(v.(uint64))))
 			case *uint64:
 				vargs[n] = NewVariant(VT_UI8|VT_BYREF, int64(uintptr(unsafe.Pointer(v.(*uint64)))))
+			case int:
+				vargs[n] = NewVariant(VT_I4, int64(v.(int)))
+			case *int:
+				vargs[n] = NewVariant(VT_I4|VT_BYREF, int64(uintptr(unsafe.Pointer(v.(*int)))))
+			case uint:
+				vargs[n] = NewVariant(VT_UI4, int64(v.(uint)))
+			case *uint:
+				vargs[n] = NewVariant(VT_UI4|VT_BYREF, int64(uintptr(unsafe.Pointer(v.(*uint)))))
 			case float32:
 				vargs[n] = NewVariant(VT_R4, *(*int64)(unsafe.Pointer(&vv)))
 			case *float32:
diff --git a/idispatch_windows_test.go b/idispatch_windows_test.go
index 25a136e..1258807 100644
--- a/idispatch_windows_test.go
+++ b/idispatch_windows_test.go
@@ -32,7 +32,7 @@
 	}
 	defer unknown.Release()
 
-	dispatch, err = unknown.QueryInterface(IID_IDispatch)
+	dispatch, err = unknown.QueryInterface(DispatchInterfaceID)
 	if err != nil {
 		t.Error(err)
 		return
@@ -42,24 +42,389 @@
 	callback(t, unknown, dispatch)
 }
 
-func wrapGoOLETestCOMServer(t *testing.T, callback func(*testing.T, *IUnknown, *IDispatch)) {
+func wrapGoOLETestCOMServerEcho(t *testing.T, callback func(*testing.T, *IUnknown, *IDispatch)) {
 	wrapCOMExecute(t, func(t *testing.T) {
 		wrapDispatch(t, CLSID_COMEchoTestObject, IID_IUnknown, IID_ICOMEchoTestObject, callback)
 	})
 }
 
+func wrapGoOLETestCOMServerScalar(t *testing.T, callback func(*testing.T, *IUnknown, *IDispatch)) {
+	wrapCOMExecute(t, func(t *testing.T) {
+		wrapDispatch(t, CLSID_COMTestScalarClass, IID_IUnknown, IID_ICOMTestTypes, callback)
+	})
+}
+
+func TestIDispatch_goolecomserver_stringfield(t *testing.T) {
+	wrapGoOLETestCOMServerScalar(t, func(t *testing.T, unknown *IUnknown, idispatch *IDispatch) {
+		method := "StringField"
+		expected := "Test String"
+		_, err := idispatch.PutProperty(method, expected)
+		if err != nil {
+			t.Error(err)
+			return
+		}
+		variant, err := idispatch.GetProperty(method)
+		if err != nil {
+			t.Error(err)
+			return
+		}
+		defer variant.Clear()
+		actual, passed := variant.Value().(string)
+		if !passed {
+			t.Errorf("%s() did not convert to %s, variant is %s with %v value", method, "string", variant.VT, variant.Val)
+			return
+		}
+		if actual != expected {
+			t.Errorf("%s() expected %v did not match %v", method, expected, actual)
+		}
+	})
+}
+
+func TestIDispatch_goolecomserver_int8field(t *testing.T) {
+	wrapGoOLETestCOMServerScalar(t, func(t *testing.T, unknown *IUnknown, idispatch *IDispatch) {
+		method := "Int8Field"
+		expected := int8(2)
+		_, err := idispatch.PutProperty(method, expected)
+		if err != nil {
+			t.Error(err)
+			return
+		}
+		variant, err := idispatch.GetProperty(method)
+		if err != nil {
+			t.Error(err)
+			return
+		}
+		defer variant.Clear()
+		actual, passed := variant.Value().(int8)
+		if !passed {
+			t.Errorf("%s() did not convert to %s, variant is %s with %v value", method, "int8", variant.VT, variant.Val)
+			return
+		}
+		if actual != expected {
+			t.Errorf("%s() expected %v did not match %v", method, expected, actual)
+		}
+	})
+}
+
+func TestIDispatch_goolecomserver_uint8field(t *testing.T) {
+	wrapGoOLETestCOMServerScalar(t, func(t *testing.T, unknown *IUnknown, idispatch *IDispatch) {
+		method := "UInt8Field"
+		expected := uint8(4)
+		_, err := idispatch.PutProperty(method, expected)
+		if err != nil {
+			t.Error(err)
+			return
+		}
+		variant, err := idispatch.GetProperty(method)
+		if err != nil {
+			t.Error(err)
+			return
+		}
+		defer variant.Clear()
+		actual, passed := variant.Value().(uint8)
+		if !passed {
+			t.Errorf("%s() did not convert to %s, variant is %s with %v value", method, "uint8", variant.VT, variant.Val)
+			return
+		}
+		if actual != expected {
+			t.Errorf("%s() expected %v did not match %v", method, expected, actual)
+		}
+	})
+}
+
+func TestIDispatch_goolecomserver_int16field(t *testing.T) {
+	wrapGoOLETestCOMServerScalar(t, func(t *testing.T, unknown *IUnknown, idispatch *IDispatch) {
+		method := "Int16Field"
+		expected := int16(4)
+		_, err := idispatch.PutProperty(method, expected)
+		if err != nil {
+			t.Error(err)
+			return
+		}
+		variant, err := idispatch.GetProperty(method)
+		if err != nil {
+			t.Error(err)
+			return
+		}
+		defer variant.Clear()
+		actual, passed := variant.Value().(int16)
+		if !passed {
+			t.Errorf("%s() did not convert to %s, variant is %s with %v value", method, "int16", variant.VT, variant.Val)
+			return
+		}
+		if actual != expected {
+			t.Errorf("%s() expected %v did not match %v", method, expected, actual)
+		}
+	})
+}
+
+func TestIDispatch_goolecomserver_uint16field(t *testing.T) {
+	wrapGoOLETestCOMServerScalar(t, func(t *testing.T, unknown *IUnknown, idispatch *IDispatch) {
+		method := "UInt16Field"
+		expected := uint16(4)
+		_, err := idispatch.PutProperty(method, expected)
+		if err != nil {
+			t.Error(err)
+			return
+		}
+		variant, err := idispatch.GetProperty(method)
+		if err != nil {
+			t.Error(err)
+			return
+		}
+		defer variant.Clear()
+		actual, passed := variant.Value().(uint16)
+		if !passed {
+			t.Errorf("%s() did not convert to %s, variant is %s with %v value", method, "uint16", variant.VT, variant.Val)
+			return
+		}
+		if actual != expected {
+			t.Errorf("%s() expected %v did not match %v", method, expected, actual)
+		}
+	})
+}
+
+func TestIDispatch_goolecomserver_int32field(t *testing.T) {
+	wrapGoOLETestCOMServerScalar(t, func(t *testing.T, unknown *IUnknown, idispatch *IDispatch) {
+		method := "Int32Field"
+		expected := int32(8)
+		_, err := idispatch.PutProperty(method, expected)
+		if err != nil {
+			t.Error(err)
+			return
+		}
+		variant, err := idispatch.GetProperty(method)
+		if err != nil {
+			t.Error(err)
+			return
+		}
+		defer variant.Clear()
+		actual, passed := variant.Value().(int32)
+		if !passed {
+			t.Errorf("%s() did not convert to %s, variant is %s with %v value", method, "int32", variant.VT, variant.Val)
+			return
+		}
+		if actual != expected {
+			t.Errorf("%s() expected %v did not match %v", method, expected, actual)
+		}
+	})
+}
+
+func TestIDispatch_goolecomserver_uint32field(t *testing.T) {
+	wrapGoOLETestCOMServerScalar(t, func(t *testing.T, unknown *IUnknown, idispatch *IDispatch) {
+		method := "UInt32Field"
+		expected := uint32(16)
+		_, err := idispatch.PutProperty(method, expected)
+		if err != nil {
+			t.Error(err)
+			return
+		}
+		variant, err := idispatch.GetProperty(method)
+		if err != nil {
+			t.Error(err)
+			return
+		}
+		defer variant.Clear()
+		actual, passed := variant.Value().(uint32)
+		if !passed {
+			t.Errorf("%s() did not convert to %s, variant is %s with %v value", method, "uint32", variant.VT, variant.Val)
+			return
+		}
+		if actual != expected {
+			t.Errorf("%s() expected %v did not match %v", method, expected, actual)
+		}
+	})
+}
+
+func TestIDispatch_goolecomserver_int64field(t *testing.T) {
+	wrapGoOLETestCOMServerScalar(t, func(t *testing.T, unknown *IUnknown, idispatch *IDispatch) {
+		method := "Int64Field"
+		expected := int64(32)
+		_, err := idispatch.PutProperty(method, expected)
+		if err != nil {
+			t.Error(err)
+			return
+		}
+		variant, err := idispatch.GetProperty(method)
+		if err != nil {
+			t.Error(err)
+			return
+		}
+		defer variant.Clear()
+		actual, passed := variant.Value().(int64)
+		if !passed {
+			t.Errorf("%s() did not convert to %s, variant is %s with %v value", method, "int64", variant.VT, variant.Val)
+			return
+		}
+		if actual != expected {
+			t.Errorf("%s() expected %v did not match %v", method, expected, actual)
+		}
+	})
+}
+
+func TestIDispatch_goolecomserver_uint64field(t *testing.T) {
+	wrapGoOLETestCOMServerScalar(t, func(t *testing.T, unknown *IUnknown, idispatch *IDispatch) {
+		method := "UInt64Field"
+		expected := uint64(64)
+		_, err := idispatch.PutProperty(method, expected)
+		if err != nil {
+			t.Error(err)
+			return
+		}
+		variant, err := idispatch.GetProperty(method)
+		if err != nil {
+			t.Error(err)
+			return
+		}
+		defer variant.Clear()
+		actual, passed := variant.Value().(uint64)
+		if !passed {
+			t.Errorf("%s() did not convert to %s, variant is %s with %v value", method, "uint64", variant.VT, variant.Val)
+			return
+		}
+		if actual != expected {
+			t.Errorf("%s() expected %v did not match %v", method, expected, actual)
+		}
+	})
+}
+
+func TestIDispatch_goolecomserver_booleanfield_true(t *testing.T) {
+	wrapGoOLETestCOMServerScalar(t, func(t *testing.T, unknown *IUnknown, idispatch *IDispatch) {
+		method := "BooleanField"
+		expected := true
+		_, err := idispatch.PutProperty(method, expected)
+		if err != nil {
+			t.Error(err)
+			return
+		}
+		variant, err := idispatch.GetProperty(method)
+		if err != nil {
+			t.Error(err)
+			return
+		}
+		defer variant.Clear()
+		actual, passed := variant.Value().(bool)
+		if !passed {
+			t.Errorf("%s() did not convert to %s, variant is %s with %v value", method, "bool", variant.VT, variant.Val)
+			return
+		}
+		if actual != expected {
+			t.Errorf("%s() expected %v did not match %v", method, expected, actual)
+		}
+	})
+}
+
+func TestIDispatch_goolecomserver_booleanfield_false(t *testing.T) {
+	wrapGoOLETestCOMServerScalar(t, func(t *testing.T, unknown *IUnknown, idispatch *IDispatch) {
+		method := "BooleanField"
+		expected := false
+		_, err := idispatch.PutProperty(method, expected)
+		if err != nil {
+			t.Error(err)
+			return
+		}
+		variant, err := idispatch.GetProperty(method)
+		if err != nil {
+			t.Error(err)
+			return
+		}
+		defer variant.Clear()
+		actual, passed := variant.Value().(bool)
+		if !passed {
+			t.Errorf("%s() did not convert to %s, variant is %s with %v value", method, "bool", variant.VT, variant.Val)
+			return
+		}
+		if actual != expected {
+			t.Errorf("%s() expected %v did not match %v", method, expected, actual)
+		}
+	})
+}
+
+func TestIDispatch_goolecomserver_float32field(t *testing.T) {
+	wrapGoOLETestCOMServerScalar(t, func(t *testing.T, unknown *IUnknown, idispatch *IDispatch) {
+		method := "Float32Field"
+		expected := float32(2.2)
+		_, err := idispatch.PutProperty(method, expected)
+		if err != nil {
+			t.Error(err)
+		}
+		variant, err := idispatch.GetProperty(method)
+		if err != nil {
+			t.Error(err)
+			return
+		}
+		defer variant.Clear()
+		actual, passed := variant.Value().(float32)
+		if !passed {
+			t.Errorf("%s() did not convert to %s, variant is %s with %v value", method, "float32", variant.VT, variant.Val)
+			return
+		}
+		if actual != expected {
+			t.Errorf("%s() expected %v did not match %v", method, expected, actual)
+		}
+	})
+}
+
+func TestIDispatch_goolecomserver_float64field(t *testing.T) {
+	wrapGoOLETestCOMServerScalar(t, func(t *testing.T, unknown *IUnknown, idispatch *IDispatch) {
+		method := "Float64Field"
+		expected := float64(4.4)
+		_, err := idispatch.PutProperty(method, expected)
+		if err != nil {
+			t.Error(err)
+		}
+		variant, err := idispatch.GetProperty(method)
+		if err != nil {
+			t.Error(err)
+			return
+		}
+		defer variant.Clear()
+		actual, passed := variant.Value().(float64)
+		if !passed {
+			t.Errorf("%s() did not convert to %s, variant is %s with %v value", method, "float64", variant.VT, variant.Val)
+			return
+		}
+		if actual != expected {
+			t.Errorf("%s() expected %v did not match %v", method, expected, actual)
+		}
+	})
+}
+
 func TestIDispatch_goolecomserver_echostring(t *testing.T) {
-	wrapGoOLETestCOMServer(t, func(t *testing.T, unknown *IUnknown, idispatch *IDispatch) {
+	wrapGoOLETestCOMServerEcho(t, func(t *testing.T, unknown *IUnknown, idispatch *IDispatch) {
 		method := "EchoString"
 		expected := "Test String"
 		variant, err := idispatch.CallMethod(method, expected)
 		if err != nil {
 			t.Error(err)
+			return
 		}
-		variant.Clear()
+		defer variant.Clear()
 		actual, passed := variant.Value().(string)
 		if !passed {
 			t.Errorf("%s() did not convert to %s, variant is %s with %v value", method, "string", variant.VT, variant.Val)
+			return
+		}
+		if actual != expected {
+			t.Errorf("%s() expected %v did not match %v", method, expected, actual)
+		}
+	})
+}
+
+func TestIDispatch_goolecomserver_echoboolean(t *testing.T) {
+	wrapGoOLETestCOMServerEcho(t, func(t *testing.T, unknown *IUnknown, idispatch *IDispatch) {
+		method := "EchoBoolean"
+		expected := true
+		variant, err := idispatch.CallMethod(method, expected)
+		if err != nil {
+			t.Error(err)
+			return
+		}
+		defer variant.Clear()
+		actual, passed := variant.Value().(bool)
+		if !passed {
+			t.Errorf("%s() did not convert to %s, variant is %s with %v value", method, "bool", variant.VT, variant.Val)
+			return
 		}
 		if actual != expected {
 			t.Errorf("%s() expected %v did not match %v", method, expected, actual)
@@ -68,17 +433,19 @@
 }
 
 func TestIDispatch_goolecomserver_echoint8(t *testing.T) {
-	wrapGoOLETestCOMServer(t, func(t *testing.T, unknown *IUnknown, idispatch *IDispatch) {
+	wrapGoOLETestCOMServerEcho(t, func(t *testing.T, unknown *IUnknown, idispatch *IDispatch) {
 		method := "EchoInt8"
 		expected := int8(1)
 		variant, err := idispatch.CallMethod(method, expected)
 		if err != nil {
 			t.Error(err)
+			return
 		}
-		variant.Clear()
+		defer variant.Clear()
 		actual, passed := variant.Value().(int8)
 		if !passed {
 			t.Errorf("%s() did not convert to %s, variant is %s with %v value", method, "int8", variant.VT, variant.Val)
+			return
 		}
 		if actual != expected {
 			t.Errorf("%s() expected %v did not match %v", method, expected, actual)
@@ -87,17 +454,19 @@
 }
 
 func TestIDispatch_goolecomserver_echouint8(t *testing.T) {
-	wrapGoOLETestCOMServer(t, func(t *testing.T, unknown *IUnknown, idispatch *IDispatch) {
+	wrapGoOLETestCOMServerEcho(t, func(t *testing.T, unknown *IUnknown, idispatch *IDispatch) {
 		method := "EchoUInt8"
 		expected := uint8(1)
 		variant, err := idispatch.CallMethod(method, expected)
 		if err != nil {
 			t.Error(err)
+			return
 		}
-		variant.Clear()
+		defer variant.Clear()
 		actual, passed := variant.Value().(uint8)
 		if !passed {
 			t.Errorf("%s() did not convert to %s, variant is %s with %v value", method, "uint8", variant.VT, variant.Val)
+			return
 		}
 		if actual != expected {
 			t.Errorf("%s() expected %v did not match %v", method, expected, actual)
@@ -106,17 +475,19 @@
 }
 
 func TestIDispatch_goolecomserver_echoint16(t *testing.T) {
-	wrapGoOLETestCOMServer(t, func(t *testing.T, unknown *IUnknown, idispatch *IDispatch) {
+	wrapGoOLETestCOMServerEcho(t, func(t *testing.T, unknown *IUnknown, idispatch *IDispatch) {
 		method := "EchoInt16"
 		expected := int16(1)
 		variant, err := idispatch.CallMethod(method, expected)
 		if err != nil {
 			t.Error(err)
+			return
 		}
-		variant.Clear()
+		defer variant.Clear()
 		actual, passed := variant.Value().(int16)
 		if !passed {
 			t.Errorf("%s() did not convert to %s, variant is %s with %v value", method, "int16", variant.VT, variant.Val)
+			return
 		}
 		if actual != expected {
 			t.Errorf("%s() expected %v did not match %v", method, expected, actual)
@@ -125,17 +496,19 @@
 }
 
 func TestIDispatch_goolecomserver_echouint16(t *testing.T) {
-	wrapGoOLETestCOMServer(t, func(t *testing.T, unknown *IUnknown, idispatch *IDispatch) {
+	wrapGoOLETestCOMServerEcho(t, func(t *testing.T, unknown *IUnknown, idispatch *IDispatch) {
 		method := "EchoUInt16"
 		expected := uint16(1)
 		variant, err := idispatch.CallMethod(method, expected)
 		if err != nil {
 			t.Error(err)
+			return
 		}
-		variant.Clear()
+		defer variant.Clear()
 		actual, passed := variant.Value().(uint16)
 		if !passed {
 			t.Errorf("%s() did not convert to %s, variant is %s with %v value", method, "uint16", variant.VT, variant.Val)
+			return
 		}
 		if actual != expected {
 			t.Errorf("%s() expected %v did not match %v", method, expected, actual)
@@ -144,71 +517,61 @@
 }
 
 func TestIDispatch_goolecomserver_echoint32(t *testing.T) {
-	wrapGoOLETestCOMServer(t, func(t *testing.T, unknown *IUnknown, idispatch *IDispatch) {
+	wrapGoOLETestCOMServerEcho(t, func(t *testing.T, unknown *IUnknown, idispatch *IDispatch) {
 		method := "EchoInt32"
 		expected := int32(2)
 		variant, err := idispatch.CallMethod(method, expected)
 		if err != nil {
 			t.Error(err)
+			return
 		}
-		variant.Clear()
+		defer variant.Clear()
 		actual, passed := variant.Value().(int32)
-		if passed {
-			if actual != expected {
-				t.Errorf("%s() expected %v did not match %v", method, expected, actual)
-			}
-		}
-
-		actualInt, passed := variant.Value().(int)
-		if passed {
-			if actualInt != int(expected) {
-				t.Errorf("%s() expected %v did not match %v", method, expected, actualInt)
-			}
-		} else {
+		if !passed {
 			t.Errorf("%s() did not convert to %s, variant is %s with %v value", method, "int32", variant.VT, variant.Val)
+			return
+		}
+		if actual != expected {
+			t.Errorf("%s() expected %v did not match %v", method, expected, actual)
 		}
 	})
 }
 
 func TestIDispatch_goolecomserver_echouint32(t *testing.T) {
-	wrapGoOLETestCOMServer(t, func(t *testing.T, unknown *IUnknown, idispatch *IDispatch) {
+	wrapGoOLETestCOMServerEcho(t, func(t *testing.T, unknown *IUnknown, idispatch *IDispatch) {
 		method := "EchoUInt32"
 		expected := uint32(4)
 		variant, err := idispatch.CallMethod(method, expected)
 		if err != nil {
 			t.Error(err)
+			return
 		}
-		variant.Clear()
+		defer variant.Clear()
 		actual, passed := variant.Value().(uint32)
-		if passed {
-			if actual != expected {
-				t.Errorf("%s() expected %v did not match %v", method, expected, actual)
-			}
-		}
-
-		actualUInt, passed := variant.Value().(uint)
-		if passed {
-			if actualUInt != uint(expected) {
-				t.Errorf("%s() expected %v did not match %v", method, expected, actualUInt)
-			}
-		} else {
+		if !passed {
 			t.Errorf("%s() did not convert to %s, variant is %s with %v value", method, "uint32", variant.VT, variant.Val)
+			return
+		}
+		if actual != expected {
+			t.Errorf("%s() expected %v did not match %v", method, expected, actual)
 		}
 	})
 }
 
 func TestIDispatch_goolecomserver_echoint64(t *testing.T) {
-	wrapGoOLETestCOMServer(t, func(t *testing.T, unknown *IUnknown, idispatch *IDispatch) {
+	wrapGoOLETestCOMServerEcho(t, func(t *testing.T, unknown *IUnknown, idispatch *IDispatch) {
 		method := "EchoInt64"
 		expected := int64(1)
 		variant, err := idispatch.CallMethod(method, expected)
 		if err != nil {
 			t.Error(err)
+			return
 		}
-		variant.Clear()
+		defer variant.Clear()
 		actual, passed := variant.Value().(int64)
 		if !passed {
 			t.Errorf("%s() did not convert to %s, variant is %s with %v value", method, "int64", variant.VT, variant.Val)
+			return
 		}
 		if actual != expected {
 			t.Errorf("%s() expected %v did not match %v", method, expected, actual)
@@ -217,17 +580,19 @@
 }
 
 func TestIDispatch_goolecomserver_echouint64(t *testing.T) {
-	wrapGoOLETestCOMServer(t, func(t *testing.T, unknown *IUnknown, idispatch *IDispatch) {
+	wrapGoOLETestCOMServerEcho(t, func(t *testing.T, unknown *IUnknown, idispatch *IDispatch) {
 		method := "EchoUInt64"
 		expected := uint64(1)
 		variant, err := idispatch.CallMethod(method, expected)
 		if err != nil {
 			t.Error(err)
+			return
 		}
-		variant.Clear()
+		defer variant.Clear()
 		actual, passed := variant.Value().(uint64)
 		if !passed {
 			t.Errorf("%s() did not convert to %s, variant is %s with %v value", method, "uint64", variant.VT, variant.Val)
+			return
 		}
 		if actual != expected {
 			t.Errorf("%s() expected %v did not match %v", method, expected, actual)
@@ -236,17 +601,19 @@
 }
 
 func TestIDispatch_goolecomserver_echofloat32(t *testing.T) {
-	wrapGoOLETestCOMServer(t, func(t *testing.T, unknown *IUnknown, idispatch *IDispatch) {
+	wrapGoOLETestCOMServerEcho(t, func(t *testing.T, unknown *IUnknown, idispatch *IDispatch) {
 		method := "EchoFloat32"
 		expected := float32(2.2)
 		variant, err := idispatch.CallMethod(method, expected)
 		if err != nil {
 			t.Error(err)
+			return
 		}
-		variant.Clear()
+		defer variant.Clear()
 		actual, passed := variant.Value().(float32)
 		if !passed {
 			t.Errorf("%s() did not convert to %s, variant is %s with %v value", method, "float32", variant.VT, variant.Val)
+			return
 		}
 		if actual != expected {
 			t.Errorf("%s() expected %v did not match %v", method, expected, actual)
@@ -255,17 +622,19 @@
 }
 
 func TestIDispatch_goolecomserver_echofloat64(t *testing.T) {
-	wrapGoOLETestCOMServer(t, func(t *testing.T, unknown *IUnknown, idispatch *IDispatch) {
+	wrapGoOLETestCOMServerEcho(t, func(t *testing.T, unknown *IUnknown, idispatch *IDispatch) {
 		method := "EchoFloat64"
 		expected := float64(2.2)
 		variant, err := idispatch.CallMethod(method, expected)
 		if err != nil {
 			t.Error(err)
+			return
 		}
-		variant.Clear()
+		defer variant.Clear()
 		actual, passed := variant.Value().(float64)
 		if !passed {
 			t.Errorf("%s() did not convert to %s, variant is %s with %v value", method, "float64", variant.VT, variant.Val)
+			return
 		}
 		if actual != expected {
 			t.Errorf("%s() expected %v did not match %v", method, expected, actual)
diff --git a/ienumvariant_test.go b/ienumvariant_test.go
index 8e3a977..e476249 100644
--- a/ienumvariant_test.go
+++ b/ienumvariant_test.go
@@ -9,7 +9,6 @@
 	var classID *GUID
 
 	IID_ISWbemLocator := &GUID{0x76a6415b, 0xcb41, 0x11d1, [8]byte{0x8b, 0x02, 0x00, 0x60, 0x08, 0x06, 0xd9, 0xb6}}
-	IID_IEnumVariant := &GUID{0x00020404, 0x0000, 0x0000, [8]byte{0xC0, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x46}}
 
 	err = CoInitialize(0)
 	if err != nil {
diff --git a/variant.go b/variant.go
index 62b47fb..598bf26 100644
--- a/variant.go
+++ b/variant.go
@@ -64,22 +64,24 @@
 		return uint16(v.Val)
 	case VT_I4:
 		return int32(v.Val)
-	case VT_UINT:
-		return uint32(v.Val)
-	case VT_INT_PTR:
-		return uintptr(v.Val) // TODO
-	case VT_UINT_PTR:
-		return uintptr(v.Val)
 	case VT_UI4:
 		return uint32(v.Val)
 	case VT_I8:
 		return int64(v.Val)
 	case VT_UI8:
 		return uint64(v.Val)
+	case VT_INT:
+		return int(v.Val)
+	case VT_UINT:
+		return uint(v.Val)
+	case VT_INT_PTR:
+		return uintptr(v.Val) // TODO
+	case VT_UINT_PTR:
+		return uintptr(v.Val)
 	case VT_R4:
-		return float32(v.Val)
+		return *(*float32)(unsafe.Pointer(&v.Val))
 	case VT_R8:
-		return float64(v.Val)
+		return *(*float64)(unsafe.Pointer(&v.Val))
 	case VT_BSTR:
 		return v.ToString()
 	case VT_DATE: