summaryrefslogtreecommitdiff
path: root/ext
diff options
context:
space:
mode:
authorsuke <suke@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2006-03-19 00:56:59 +0000
committersuke <suke@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2006-03-19 00:56:59 +0000
commit6c0256933be0dd43356fb80b4824cfbb70dc4e88 (patch)
tree2d2e3c3841c69a875c11f41d77cdd7819834b97c /ext
parent597cfafb88f31e58e50aa9da327e4e165322b39c (diff)
change behavior of converting OLE Variant object with VT_ARRAY|VT_UI1
and Ruby String object. git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@10039 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
Diffstat (limited to 'ext')
-rw-r--r--ext/win32ole/tests/testOLEVARIANT.rb19
-rw-r--r--ext/win32ole/win32ole.c41
2 files changed, 57 insertions, 3 deletions
diff --git a/ext/win32ole/tests/testOLEVARIANT.rb b/ext/win32ole/tests/testOLEVARIANT.rb
index d94eede2da..247ceb1f86 100644
--- a/ext/win32ole/tests/testOLEVARIANT.rb
+++ b/ext/win32ole/tests/testOLEVARIANT.rb
@@ -76,4 +76,23 @@ class TestWIN32OLE_VARIANT < Test::Unit::TestCase
assert_equal([1.2, 2.3], obj.value)
end
+ def test_create_vt_array_str2ui1array
+ obj = WIN32OLE_VARIANT.new("ABC", WIN32OLE::VARIANT::VT_ARRAY|WIN32OLE::VARIANT::VT_UI1)
+ assert_equal("ABC", obj.value)
+
+ obj = WIN32OLE_VARIANT.new([65, 0].pack("C*"), WIN32OLE::VARIANT::VT_ARRAY|WIN32OLE::VARIANT::VT_UI1)
+ assert_equal([65, 0].pack("C*"), obj.value)
+
+ end
+ def test_create_vt_array_int
+ obj = WIN32OLE_VARIANT.new([65, 0], WIN32OLE::VARIANT::VT_ARRAY|WIN32OLE::VARIANT::VT_UI1)
+ assert_equal([65, 0].pack("C*"), obj.value)
+
+ obj = WIN32OLE_VARIANT.new([65, 0])
+ assert_equal([65, 0], obj.value)
+
+ obj = WIN32OLE_VARIANT.new([65, 0], WIN32OLE::VARIANT::VT_I2|WIN32OLE::VARIANT::VT_ARRAY)
+ assert_equal([65, 0], obj.value)
+ end
+
end
diff --git a/ext/win32ole/win32ole.c b/ext/win32ole/win32ole.c
index 0cab89bdce..e3912bcdad 100644
--- a/ext/win32ole/win32ole.c
+++ b/ext/win32ole/win32ole.c
@@ -79,7 +79,7 @@
#define WC2VSTR(x) ole_wc2vstr((x), TRUE)
-#define WIN32OLE_VERSION "0.7.1"
+#define WIN32OLE_VERSION "0.7.2"
typedef HRESULT (STDAPICALLTYPE FNCOCREATEINSTANCEEX)
(REFCLSID, IUnknown*, DWORD, COSERVERINFO*, DWORD, MULTI_QI*);
@@ -1124,12 +1124,30 @@ ole_val2olevariantdata(val, vtype, pvar)
{
HRESULT hr = S_OK;
VARIANT var;
- if (vtype & VT_ARRAY) {
+
+ if (((vtype & ~VT_BYREF) == (VT_ARRAY | VT_UI1)) && TYPE(val) == T_STRING) {
+ long len = RSTRING(val)->len;
+ char *pdest = NULL;
+ SAFEARRAY *psa = SafeArrayCreateVector(VT_UI1, 0, len);
+ if (!psa) {
+ rb_raise(rb_eRuntimeError, "fail to SafeArrayCreateVector");
+ }
+ hr = SafeArrayAccessData(psa, (void **)&pdest);
+ if (SUCCEEDED(hr)) {
+ memcpy(pdest, RSTRING(val)->ptr, len);
+ SafeArrayUnaccessData(psa);
+ V_VT(&(pvar->realvar)) = vtype;
+ V_ARRAY(&(pvar->realvar)) = psa;
+ hr = VariantCopy(&(pvar->var), &(pvar->realvar));
+ } else {
+ if (psa)
+ SafeArrayDestroy(psa);
+ }
+ } else if (vtype & VT_ARRAY) {
VALUE val1;
long dim = 0;
int i = 0;
- HRESULT hr;
SAFEARRAYBOUND *psab = NULL;
SAFEARRAY *psa = NULL;
long *pub, *pid;
@@ -7105,8 +7123,25 @@ folevariant_value(self)
{
struct olevariantdata *pvar;
VALUE val = Qnil;
+ VARTYPE vt;
Data_Get_Struct(self, struct olevariantdata, pvar);
+
val = ole_variant2val(&(pvar->var));
+ vt = V_VT(&(pvar->var));
+
+ if ((vt & ~VT_BYREF) == (VT_UI1|VT_ARRAY)) {
+ SAFEARRAY *psa;
+ if (vt & VT_BYREF) {
+ psa = *V_ARRAYREF(&(pvar->var));
+ } else {
+ psa = V_ARRAY(&(pvar->var));
+ }
+ int dim = SafeArrayGetDim(psa);
+ if (dim == 1) {
+ VALUE args = rb_ary_new3(1, rb_str_new2("C*"));
+ val = rb_apply(val, rb_intern("pack"), args);
+ }
+ }
return val;
}