8 static void olevariant_free(
void *ptr);
9 static size_t olevariant_size(
const void *ptr);
11 static void ole_val2variant_err(
VALUE val, VARIANT *
var);
12 static void ole_set_byref(VARIANT *
realvar, VARIANT *
var, VARTYPE vt);
13 static VALUE folevariant_s_allocate(
VALUE klass);
15 static void check_type_val2variant(
VALUE val);
17 static LONG *ary2safe_array_index(
int ary_size,
VALUE *ary, SAFEARRAY *psa);
18 static void unlock_safe_array(SAFEARRAY *psa);
19 static SAFEARRAY *get_locked_safe_array(
VALUE val);
28 {
NULL, olevariant_free, olevariant_size,},
33 olevariant_free(
void *ptr)
37 VariantClear(&(pvar->
var));
42 olevariant_size(
const void *ptr)
48 ole_val2olevariantdata(VALUE val, VARTYPE vt, struct olevariantdata *pvar)
56 SAFEARRAY *psa = SafeArrayCreateVector(VT_UI1, 0, len);
60 hr = SafeArrayAccessData(psa, &pdest);
63 SafeArrayUnaccessData(psa);
64 V_VT(&(pvar->
realvar)) = (vt & ~VT_BYREF);
69 V_ARRAY(&(pvar->
realvar)) = psa;
71 V_VT(&(pvar->
var)) = vt;
72 V_ARRAYREF(&(pvar->
var)) = &(V_ARRAY(&(pvar->
realvar)));
74 hr = VariantCopy(&(pvar->
var), &(pvar->
realvar));
78 SafeArrayDestroy(psa);
80 }
else if (vt & VT_ARRAY) {
82 V_VT(&(pvar->
var)) = vt;
84 V_ARRAYREF(&(pvar->
var)) = &(V_ARRAY(&(pvar->
realvar)));
90 V_VT(&(pvar->
var)) = vt;
91 V_ARRAYREF(&(pvar->
var)) = &(V_ARRAY(&(pvar->
realvar)));
93 hr = VariantCopy(&(pvar->
var), &(pvar->
realvar));
97 #if (_MSC_VER >= 1300) || defined(__CYGWIN__) || defined(__MINGW32__) 98 }
else if ( (vt & ~VT_BYREF) == VT_I8 || (vt & ~VT_BYREF) == VT_UI8) {
101 V_VT(&(pvar->
var)) = vt;
103 ole_set_byref(&(pvar->
realvar), &(pvar->
var), vt);
106 }
else if ( (vt & ~VT_BYREF) == VT_ERROR) {
109 ole_set_byref(&(pvar->
realvar), &(pvar->
var), vt);
111 hr = VariantCopy(&(pvar->
var), &(pvar->
realvar));
115 V_VT(&(pvar->
var)) = vt;
116 if (vt == (VT_BYREF | VT_VARIANT)) {
117 ole_set_byref(&(pvar->
realvar), &(pvar->
var), vt);
119 V_VT(&(pvar->
realvar)) = vt & ~VT_BYREF;
121 ole_set_byref(&(pvar->
realvar), &(pvar->
var), vt);
126 if (vt == (VT_BYREF | VT_VARIANT)) {
127 ole_set_byref(&(pvar->
realvar), &(pvar->
var), vt);
128 }
else if (vt & VT_BYREF) {
129 if ( (vt & ~VT_BYREF) != V_VT(&(pvar->
realvar))) {
134 ole_set_byref(&(pvar->
realvar), &(pvar->
var), vt);
137 if (vt == V_VT(&(pvar->
realvar))) {
138 hr = VariantCopy(&(pvar->
var), &(pvar->
realvar));
140 hr = VariantChangeTypeEx(&(pvar->
var), &(pvar->
realvar),
156 v = folevariant_value(v);
161 V_VT(var) = VT_ERROR;
170 ole_set_byref(VARIANT *
realvar, VARIANT *var, VARTYPE vt)
173 if (vt == (VT_VARIANT|VT_BYREF)) {
176 if (V_VT(realvar) != (vt & ~VT_BYREF)) {
179 switch(vt & ~VT_BYREF) {
184 V_UI1REF(var) = &V_UI1(realvar);
187 V_I2REF(var) = &V_I2(realvar);
193 V_I4REF(var) = &V_I4(realvar);
196 V_UI4REF(var) = &V_UI4(realvar);
199 V_R4REF(var) = &V_R4(realvar);
202 V_R8REF(var) = &V_R8(realvar);
205 #if (_MSC_VER >= 1300) || defined(__CYGWIN__) || defined(__MINGW32__) 208 V_I8REF(var) = &V_I8(realvar);
213 V_UI8REF(var) = &V_UI8(realvar);
226 V_CYREF(var) = &V_CY(realvar);
229 V_DATEREF(var) = &V_DATE(realvar);
232 V_BSTRREF(var) = &V_BSTR(realvar);
235 V_DISPATCHREF(var) = &V_DISPATCH(realvar);
238 V_ERRORREF(var) = &V_ERROR(realvar);
241 V_BOOLREF(var) = &V_BOOL(realvar);
244 V_UNKNOWNREF(var) = &V_UNKNOWN(realvar);
247 V_ARRAYREF(var) = &V_ARRAY(realvar);
257 folevariant_s_allocate(
VALUE klass)
263 VariantInit(&(pvar->
var));
290 SAFEARRAYBOUND *psab =
NULL;
291 SAFEARRAY *psa =
NULL;
298 vt = (vt | VT_ARRAY);
300 obj = folevariant_s_allocate(klass);
305 psab =
ALLOC_N(SAFEARRAYBOUND, dim);
311 for (i = 0; i < dim; i++) {
316 psa = SafeArrayCreate((VARTYPE)(vt & VT_TYPEMASK), dim, psab);
318 if (psab)
free(psab);
322 V_VT(&(pvar->
var)) = vt;
324 V_VT(&(pvar->
realvar)) = (vt & ~VT_BYREF);
325 V_ARRAY(&(pvar->
realvar)) = psa;
326 V_ARRAYREF(&(pvar->
var)) = &(V_ARRAY(&(pvar->
realvar)));
328 V_ARRAY(&(pvar->
var)) = psa;
330 if (psab)
free(psab);
335 check_type_val2variant(
VALUE val)
346 for(i = 0; i <
len; i++) {
348 check_type_val2variant(elem);
402 folevariant_initialize(
VALUE self,
VALUE args)
416 check_type_val2variant(val);
424 if ((vt & VT_TYPEMASK) == VT_RECORD) {
427 ole_val2olevariantdata(val, vt, pvar);
433 get_locked_safe_array(
VALUE val)
436 SAFEARRAY *psa =
NULL;
439 if (!(V_VT(&(pvar->
var)) & VT_ARRAY)) {
442 psa = V_ISBYREF(&(pvar->
var)) ? *V_ARRAYREF(&(pvar->
var)) : V_ARRAY(&(pvar->var));
446 hr = SafeArrayLock(psa);
454 ary2safe_array_index(
int ary_size,
VALUE *ary, SAFEARRAY *psa)
459 dim = SafeArrayGetDim(psa);
460 if (dim != ary_size) {
467 for (i = 0; i < dim; i++) {
474 unlock_safe_array(SAFEARRAY *psa)
477 hr = SafeArrayUnlock(psa);
514 if (!V_ISARRAY(&(pvar->
var))) {
516 "`[]' is not available for this variant type object");
518 psa = get_locked_safe_array(
self);
523 pid = ary2safe_array_index(argc, argv, psa);
525 VariantInit(&variant);
526 V_VT(&variant) = (V_VT(&(pvar->
var)) & ~VT_ARRAY) | VT_BYREF;
527 hr = SafeArrayPtrOfIndex(psa, pid, &V_BYREF(&variant));
533 unlock_safe_array(psa);
560 folevariant_ary_aset(
int argc,
VALUE *argv,
VALUE self)
571 if (!V_ISARRAY(&(pvar->
var))) {
573 "`[]' is not available for this variant type object");
575 psa = get_locked_safe_array(
self);
580 pid = ary2safe_array_index(argc-1, argv, psa);
583 vt = (V_VT(&(pvar->
var)) & ~VT_ARRAY);
585 if ((V_VT(&var) == VT_DISPATCH && V_DISPATCH(&var) ==
NULL) ||
586 (V_VT(&var) == VT_UNKNOWN && V_UNKNOWN(&var) ==
NULL)) {
589 hr = SafeArrayPutElement(psa, pid, p);
594 unlock_safe_array(psa);
609 folevariant_value(
VALUE self)
619 vt = V_VT(&(pvar->
var));
621 if ((vt & ~VT_BYREF) == (VT_UI1|VT_ARRAY)) {
623 psa = *V_ARRAYREF(&(pvar->
var));
625 psa = V_ARRAY(&(pvar->
var));
630 dim = SafeArrayGetDim(psa);
648 folevariant_vartype(
VALUE self)
675 vt = V_VT(&(pvar->
var));
676 if (V_ISARRAY(&(pvar->
var)) && ((vt & ~VT_BYREF) != (VT_UI1|VT_ARRAY) || !
RB_TYPE_P(val,
T_STRING))) {
678 "`value=' is not available for this variant type object");
680 ole_val2olevariantdata(val, vt, pvar);
689 VariantCopy(var, &(pvar->
var));
VALUE eWIN32OLERuntimeError
VALUE rb_ary_entry(VALUE ary, long offset)
#define RUBY_TYPED_FREE_IMMEDIATELY
VOID * val2variant_ptr(VALUE val, VARIANT *var, VARTYPE vt)
void rb_define_singleton_method(VALUE obj, const char *name, VALUE(*func)(ANYARGS), int argc)
Defines a singleton method for obj.
void rb_raise(VALUE exc, const char *fmt,...)
void ole_variant2variant(VALUE val, VARIANT *var)
#define TypedData_Get_Struct(obj, type, data_type, sval)
VALUE rb_funcall(VALUE, ID, int,...)
Calls a method.
void rb_define_alloc_func(VALUE, rb_alloc_func_t)
void ole_initialize(void)
VALUE rb_inspect(VALUE)
Convenient wrapper of Object::inspect.
void Init_win32ole_variant(void)
const char * rb_obj_classname(VALUE)
#define RB_TYPE_P(obj, type)
VALUE rb_obj_is_kind_of(VALUE, VALUE)
call-seq: obj.is_a?(class) -> true or false obj.kind_of?(class) -> true or false
void ole_raise(HRESULT hr, VALUE ecs, const char *fmt,...)
RUBY_EXTERN VALUE rb_cObject
VALUE rb_define_class(const char *name, VALUE super)
Defines a top-level class.
void rb_define_const(VALUE, const char *, VALUE)
void ole_val2variant_ex(VALUE val, VARIANT *var, VARTYPE vt)
VALUE ole_variant2val(VARIANT *pvar)
register unsigned int len
typedef HRESULT(STDAPICALLTYPE FNCOCREATEINSTANCEEX)(REFCLSID
#define TypedData_Make_Struct(klass, type, data_type, sval)
HRESULT ole_val_ary2variant_ary(VALUE val, VARIANT *var, VARTYPE vt)
RUBY_EXTERN VALUE rb_cTime
void rb_define_method(VALUE klass, const char *name, VALUE(*func)(ANYARGS), int argc)
void ole_val2variant(VALUE val, VARIANT *var)