123456789_123456789_123456789_123456789_123456789_

Class: WIN32OLE::Type

Relationships & Source Files
Inherits: Object
Defined in: ext/win32ole/win32ole_type.c,
ext/win32ole/win32ole_type.c

Overview

Type objects represent OLE type library information.

Class Method Summary

Instance Attribute Summary

Instance Method Summary

Constructor Details

.new(typelib, ole_class) ⇒ Type

Returns a new 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.
[ GitHub ]

  
# File 'ext/win32ole/win32ole_type.c', line 260

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)

Returns array of Type objects defined by the typelib type library.

This method will be OBSOLETE. Use WIN32OLE::TypeLib.new(typelib).ole_classes instead.

[ GitHub ]

  
# File 'ext/win32ole/win32ole_type.c', line 116

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);
}

.progids

Returns array of ProgID.

[ GitHub ]

  
# File 'ext/win32ole/win32ole_type.c', line 157

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;
}

.typelibs

Returns array of type libraries.

This method will be OBSOLETE. Use WIN32OLE::TypeLib.typelibs.collect{|t| t.name} instead.

[ GitHub ]

  
# File 'ext/win32ole/win32ole_type.c', line 140

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 Attribute Details

#visible?(#=> true or false) (readonly)

Returns true if the OLE class is public.

tobj = WIN32OLE::Type.new('Microsoft Excel 9.0 Object Library', 'Application')
puts tobj.visible  # => true
[ GitHub ]

  
# File 'ext/win32ole/win32ole_type.c', line 458

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

Instance Method Details

#default_event_sources

Returns the array of Type object which is implemented by the 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>]
[ GitHub ]

  
# File 'ext/win32ole/win32ole_type.c', line 850

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_types

Returns the array of Type object which is implemented by the 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>]
[ GitHub ]

  
# File 'ext/win32ole/win32ole_type.c', line 867

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

#guid(#=> GUID)

Returns GUID.

tobj = WIN32OLE::Type.new('Microsoft Excel 9.0 Object Library', 'Application')
puts tobj.guid  # => {00024500-0000-0000-C000-000000000046}
[ GitHub ]

  
# File 'ext/win32ole/win32ole_type.c', line 390

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

#helpcontext

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
[ GitHub ]

  
# File 'ext/win32ole/win32ole_type.c', line 662

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

#helpfile

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
[ GitHub ]

  
# File 'ext/win32ole/win32ole_type.c', line 635

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

#helpstring(#=> help string.)

Returns help string.

tobj = WIN32OLE::Type.new('Microsoft Internet Controls', 'IWebBrowser')
puts tobj.helpstring # => Web Browser interface
[ GitHub ]

  
# File 'ext/win32ole/win32ole_type.c', line 573

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

#implemented_ole_types

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

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

  
# File 'ext/win32ole/win32ole_type.c', line 817

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>
[ GitHub ]

  
# File 'ext/win32ole/win32ole_type.c', line 883

static VALUE
foletype_inspect(VALUE self)
{
    return default_inspect(self, "WIN32OLE::Type");
}

#major_version

Returns major version.

tobj = WIN32OLE::Type.new('Microsoft Word 10.0 Object Library', 'Documents')
puts tobj.major_version # => 8
[ GitHub ]

  
# File 'ext/win32ole/win32ole_type.c', line 487

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

#minor_version(#=> OLE minor version)

Returns minor version.

tobj = WIN32OLE::Type.new('Microsoft Word 10.0 Object Library', 'Documents')
puts tobj.minor_version # => 2
[ GitHub ]

  
# File 'ext/win32ole/win32ole_type.c', line 516

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

#to_s(#=> OLE type name) #name(#=> OLE type name)

Alias for #to_s.

#progid(#=> ProgID)

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
[ GitHub ]

  
# File 'ext/win32ole/win32ole_type.c', line 424

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

#source_ole_types

Returns the array of Type object which is implemented by the 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>]
[ GitHub ]

  
# File 'ext/win32ole/win32ole_type.c', line 834

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

#src_type(#=> OLE source class)

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
[ GitHub ]

  
# File 'ext/win32ole/win32ole_type.c', line 607

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

#to_s(#=> OLE type name) Also known as: #name

Returns OLE type name.

tobj = WIN32OLE::Type.new('Microsoft Excel 9.0 Object Library', 'Application')
puts tobj.name  # => Application
[ GitHub ]

  
# File 'ext/win32ole/win32ole_type.c', line 296

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

#typekind(#=> number of type.)

Returns number which represents type.

tobj = WIN32OLE::Type.new('Microsoft Word 10.0 Object Library', 'Documents')
puts tobj.typekind # => 4
[ GitHub ]

  
# File 'ext/win32ole/win32ole_type.c', line 546

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

#variables

Returns array of 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
[ GitHub ]

  
# File 'ext/win32ole/win32ole_type.c', line 725

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