Class: WIN32OLE_TYPE

Inherits:
Object
  • Object
show all
Defined in:
win32ole_type.c,
win32ole_type.c

Overview

WIN32OLE_TYPE objects represent OLE type libarary information.

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#new(typelib, ole_class) ⇒ WIN32OLE_TYPE object

Returns a new WIN32OLE_TYPE object. The first argument typelib specifies OLE type library name. The second argument specifies OLE class name.

WIN32OLE_TYPE.new('Microsoft Excel 9.0 Object Library', 'Application')
    # => WIN32OLE_TYPE object of Application class of Excel.


257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
# File 'win32ole_type.c', line 257

static VALUE
foletype_initialize(VALUE self, VALUE typelib, VALUE oleclass)
{
    VALUE file;
    OLECHAR * pbuf;
    ITypeLib *pTypeLib;
    HRESULT hr;

    SafeStringValue(oleclass);
    SafeStringValue(typelib);
    file = typelib_file(typelib);
    if (file == Qnil) {
        file = typelib;
    }
    pbuf = ole_vstr2wc(file);
    hr = LoadTypeLibEx(pbuf, REGKIND_NONE, &pTypeLib);
    if (FAILED(hr))
        ole_raise(hr, eWIN32OLERuntimeError, "failed to LoadTypeLibEx");
    SysFreeString(pbuf);
    if (oleclass_from_typelib(self, pTypeLib, oleclass) == Qfalse) {
        OLE_RELEASE(pTypeLib);
        rb_raise(eWIN32OLERuntimeError, "not found `%s` in `%s`",
                 StringValuePtr(oleclass), StringValuePtr(typelib));
    }
    OLE_RELEASE(pTypeLib);
    return self;
}

Class Method Details

.ole_classes(typelib) ⇒ Object

Returns array of WIN32OLE_TYPE objects defined by the typelib type library. This method will be OBSOLETE. Use WIN32OLE_TYPELIB.new(typelib).ole_classes instead.



114
115
116
117
118
119
120
121
122
123
124
125
126
# File 'win32ole_type.c', line 114

static VALUE
foletype_s_ole_classes(VALUE self, VALUE typelib)
{
    VALUE obj;

    /*
    rb_warn("%s is obsolete; use %s instead.",
            "WIN32OLE_TYPE.ole_classes",
            "WIN32OLE_TYPELIB.new(typelib).ole_types");
    */
    obj = rb_funcall(cWIN32OLE_TYPELIB, rb_intern("new"), 1, typelib);
    return rb_funcall(obj, rb_intern("ole_types"), 0);
}

.progidsObject

Returns array of ProgID.



153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
# File 'win32ole_type.c', line 153

static VALUE
foletype_s_progids(VALUE self)
{
    HKEY hclsids, hclsid;
    DWORD i;
    LONG err;
    VALUE clsid;
    VALUE v = rb_str_new2("");
    VALUE progids = rb_ary_new();

    err = reg_open_key(HKEY_CLASSES_ROOT, "CLSID", &hclsids);
    if(err != ERROR_SUCCESS) {
        return progids;
    }
    for(i = 0; ; i++) {
        clsid = reg_enum_key(hclsids, i);
        if (clsid == Qnil)
            break;
        err = reg_open_vkey(hclsids, clsid, &hclsid);
        if (err != ERROR_SUCCESS)
            continue;
        if ((v = reg_get_val2(hclsid, "ProgID")) != Qnil)
            rb_ary_push(progids, v);
        if ((v = reg_get_val2(hclsid, "VersionIndependentProgID")) != Qnil)
            rb_ary_push(progids, v);
        RegCloseKey(hclsid);
    }
    RegCloseKey(hclsids);
    return progids;
}

.typelibsObject

Returns array of type libraries. This method will be OBSOLETE. Use WIN32OLE_TYPELIB.typelibs.collect{|t| t.name} instead.



136
137
138
139
140
141
142
143
144
145
# File 'win32ole_type.c', line 136

static VALUE
foletype_s_typelibs(VALUE self)
{
    /*
    rb_warn("%s is obsolete. use %s instead.",
            "WIN32OLE_TYPE.typelibs",
            "WIN32OLE_TYPELIB.typelibs.collect{t|t.name}");
    */
    return rb_eval_string("WIN32OLE_TYPELIB.typelibs.collect{|t|t.name}");
}

Instance Method Details

#default_event_sourcesObject

Returns the array of WIN32OLE_TYPE object which is implemented by the WIN32OLE_TYPE object and having IMPLTYPEFLAG_FSOURCE and IMPLTYPEFLAG_FDEFAULT.

tobj = WIN32OLE_TYPE.new('Microsoft Internet Controls', "InternetExplorer")
p tobj.default_event_sources  # => [#<WIN32OLE_TYPE:DWebBrowserEvents2>]


847
848
849
850
851
852
# File 'win32ole_type.c', line 847

static VALUE
foletype_default_event_sources(VALUE self)
{
    ITypeInfo *pTypeInfo = itypeinfo(self);
    return ole_type_impl_ole_types(pTypeInfo, IMPLTYPEFLAG_FSOURCE|IMPLTYPEFLAG_FDEFAULT);
}

#default_ole_typesObject

Returns the array of WIN32OLE_TYPE object which is implemented by the WIN32OLE_TYPE object and having IMPLTYPEFLAG_FDEFAULT.

tobj = WIN32OLE_TYPE.new('Microsoft Internet Controls', "InternetExplorer")
p tobj.default_ole_types
# => [#<WIN32OLE_TYPE:IWebBrowser2>, #<WIN32OLE_TYPE:DWebBrowserEvents2>]


864
865
866
867
868
869
# File 'win32ole_type.c', line 864

static VALUE
foletype_default_ole_types(VALUE self)
{
    ITypeInfo *pTypeInfo = itypeinfo(self);
    return ole_type_impl_ole_types(pTypeInfo, IMPLTYPEFLAG_FDEFAULT);
}

#guidObject

Returns GUID.

tobj = WIN32OLE_TYPE.new('Microsoft Excel 9.0 Object Library', 'Application')
puts tobj.guid  # => {00024500-0000-0000-C000-000000000046}


387
388
389
390
391
392
# File 'win32ole_type.c', line 387

static VALUE
foletype_guid(VALUE self)
{
    ITypeInfo *pTypeInfo = itypeinfo(self);
    return ole_type_guid(pTypeInfo);
}

#helpcontextObject

Returns helpcontext. If helpcontext is not found, then returns nil.

tobj = WIN32OLE_TYPE.new('Microsoft Excel 9.0 Object Library', 'Worksheet')
puts tobj.helpfile # => 131185


659
660
661
662
663
664
# File 'win32ole_type.c', line 659

static VALUE
foletype_helpcontext(VALUE self)
{
    ITypeInfo *pTypeInfo = itypeinfo(self);
    return ole_type_helpcontext(pTypeInfo);
}

#helpfileObject

Returns helpfile path. If helpfile is not found, then returns nil.

tobj = WIN32OLE_TYPE.new('Microsoft Excel 9.0 Object Library', 'Worksheet')
puts tobj.helpfile # => C:\...\VBAXL9.CHM


632
633
634
635
636
637
# File 'win32ole_type.c', line 632

static VALUE
foletype_helpfile(VALUE self)
{
    ITypeInfo *pTypeInfo = itypeinfo(self);
    return ole_type_helpfile(pTypeInfo);
}

#helpstringObject

Returns help string.

tobj = WIN32OLE_TYPE.new('Microsoft Internet Controls', 'IWebBrowser')
puts tobj.helpstring # => Web Browser interface


570
571
572
573
574
575
# File 'win32ole_type.c', line 570

static VALUE
foletype_helpstring(VALUE self)
{
    ITypeInfo *pTypeInfo = itypeinfo(self);
    return ole_type_helpstring(pTypeInfo);
}

#implemented_ole_typesObject

Returns the array of WIN32OLE_TYPE object which is implemented by the WIN32OLE_TYPE object.

tobj = WIN32OLE_TYPE.new('Microsoft Excel 9.0 Object Library', 'Worksheet')
p tobj.implemented_ole_types # => [_Worksheet, DocEvents]


814
815
816
817
818
819
# File 'win32ole_type.c', line 814

static VALUE
foletype_impl_ole_types(VALUE self)
{
    ITypeInfo *pTypeInfo = itypeinfo(self);
    return ole_type_impl_ole_types(pTypeInfo, 0);
}

#inspectString

Returns the type name with class name.

ie = WIN32OLE.new('InternetExplorer.Application')
ie.ole_type.inspect => #<WIN32OLE_TYPE:IWebBrowser2>

Returns:

  • (String)


880
881
882
883
884
# File 'win32ole_type.c', line 880

static VALUE
foletype_inspect(VALUE self)
{
    return default_inspect(self, "WIN32OLE_TYPE");
}

#major_versionObject

Returns major version.

tobj = WIN32OLE_TYPE.new('Microsoft Word 10.0 Object Library', 'Documents')
puts tobj.major_version # => 8


484
485
486
487
488
489
# File 'win32ole_type.c', line 484

static VALUE
foletype_major_version(VALUE self)
{
    ITypeInfo *pTypeInfo = itypeinfo(self);
    return ole_type_major_version(pTypeInfo);
}

#minor_versionObject

Returns minor version.

tobj = WIN32OLE_TYPE.new('Microsoft Word 10.0 Object Library', 'Documents')
puts tobj.minor_version # => 2


513
514
515
516
517
518
# File 'win32ole_type.c', line 513

static VALUE
foletype_minor_version(VALUE self)
{
    ITypeInfo *pTypeInfo = itypeinfo(self);
    return ole_type_minor_version(pTypeInfo);
}

#nameObject Also known as: to_s

Returns OLE type name.

tobj = WIN32OLE_TYPE.new('Microsoft Excel 9.0 Object Library', 'Application')
puts tobj.name  # => Application


293
294
295
296
297
# File 'win32ole_type.c', line 293

static VALUE
foletype_name(VALUE self)
{
    return rb_ivar_get(self, rb_intern("name"));
}

#ole_methodsObject

Returns array of WIN32OLE_METHOD objects which represent OLE method defined in OLE type library.

tobj = WIN32OLE_TYPE.new('Microsoft Excel 9.0 Object Library', 'Worksheet')
methods = tobj.ole_methods.collect{|m|
  m.name
}
# => ['Activate', 'Copy', 'Delete',....]


741
742
743
744
745
746
# File 'win32ole_type.c', line 741

static VALUE
foletype_methods(VALUE self)
{
    ITypeInfo *pTypeInfo = itypeinfo(self);
    return ole_methods_from_typeinfo(pTypeInfo, INVOKE_FUNC | INVOKE_PROPERTYGET | INVOKE_PROPERTYPUT | INVOKE_PROPERTYPUTREF);
}

#ole_typeObject

returns type of OLE class.

tobj = WIN32OLE_TYPE.new('Microsoft Excel 9.0 Object Library', 'Application')
puts tobj.ole_type  # => Class


353
354
355
356
357
358
# File 'win32ole_type.c', line 353

static VALUE
foletype_ole_type(VALUE self)
{
    ITypeInfo *pTypeInfo = itypeinfo(self);
    return ole_ole_type(pTypeInfo);
}

#ole_typelibObject

Returns the WIN32OLE_TYPELIB object which is including the WIN32OLE_TYPE object. If it is not found, then returns nil.

tobj = WIN32OLE_TYPE.new('Microsoft Excel 9.0 Object Library', 'Worksheet')
puts tobj.ole_typelib # => 'Microsoft Excel 9.0 Object Library'


757
758
759
760
761
762
# File 'win32ole_type.c', line 757

static VALUE
foletype_ole_typelib(VALUE self)
{
    ITypeInfo *pTypeInfo = itypeinfo(self);
    return ole_typelib_from_itypeinfo(pTypeInfo);
}

#progidObject

Returns ProgID if it exists. If not found, then returns nil.

tobj = WIN32OLE_TYPE.new('Microsoft Excel 9.0 Object Library', 'Application')
puts tobj.progid  # =>   Excel.Application.9


421
422
423
424
425
426
# File 'win32ole_type.c', line 421

static VALUE
foletype_progid(VALUE self)
{
    ITypeInfo *pTypeInfo = itypeinfo(self);
    return ole_type_progid(pTypeInfo);
}

#source_ole_typesObject

Returns the array of WIN32OLE_TYPE object which is implemented by the WIN32OLE_TYPE object and having IMPLTYPEFLAG_FSOURCE.

tobj = WIN32OLE_TYPE.new('Microsoft Internet Controls', "InternetExplorer")
p tobj.source_ole_types
# => [#<WIN32OLE_TYPE:DWebBrowserEvents2>, #<WIN32OLE_TYPE:DWebBrowserEvents>]


831
832
833
834
835
836
# File 'win32ole_type.c', line 831

static VALUE
foletype_source_ole_types(VALUE self)
{
    ITypeInfo *pTypeInfo = itypeinfo(self);
    return ole_type_impl_ole_types(pTypeInfo, IMPLTYPEFLAG_FSOURCE);
}

#src_typeObject

Returns source class when the OLE class is ‘Alias’.

tobj =  WIN32OLE_TYPE.new('Microsoft Office 9.0 Object Library', 'MsoRGBType')
puts tobj.src_type # => I4


604
605
606
607
608
609
# File 'win32ole_type.c', line 604

static VALUE
foletype_src_type(VALUE self)
{
    ITypeInfo *pTypeInfo = itypeinfo(self);
    return ole_type_src_type(pTypeInfo);
}

#typekindObject

Returns number which represents type.

tobj = WIN32OLE_TYPE.new('Microsoft Word 10.0 Object Library', 'Documents')
puts tobj.typekind # => 4


543
544
545
546
547
548
# File 'win32ole_type.c', line 543

static VALUE
foletype_typekind(VALUE self)
{
    ITypeInfo *pTypeInfo = itypeinfo(self);
    return ole_type_typekind(pTypeInfo);
}

#variablesObject

Returns array of WIN32OLE_VARIABLE objects which represent variables defined in OLE class.

tobj = WIN32OLE_TYPE.new('Microsoft Excel 9.0 Object Library', 'XlSheetType')
vars = tobj.variables
vars.each do |v|
  puts "#{v.name} = #{v.value}"
end

The result of above sample script is follows:
  xlChart = -4109
  xlDialogSheet = -4116
  xlExcel4IntlMacroSheet = 4
  xlExcel4MacroSheet = 3
  xlWorksheet = -4167


722
723
724
725
726
727
# File 'win32ole_type.c', line 722

static VALUE
foletype_variables(VALUE self)
{
    ITypeInfo *pTypeInfo = itypeinfo(self);
    return ole_variables(pTypeInfo);
}

#visible?(# = > true or false) ⇒ Boolean

Returns true if the OLE class is public.

tobj = WIN32OLE_TYPE.new('Microsoft Excel 9.0 Object Library', 'Application')
puts tobj.visible  # => true

Returns:

  • (Boolean)


455
456
457
458
459
460
# File 'win32ole_type.c', line 455

static VALUE
foletype_visible(VALUE self)
{
    ITypeInfo *pTypeInfo = itypeinfo(self);
    return ole_type_visible(pTypeInfo);
}