Class | WIN32OLE_TYPE
In: | win32ole/win32ole.c
Parent: | Object

`WIN32OLE_TYPE` objects represent OLE type libarary information.

### Methods

guid helpcontext helpfile helpstring major_version minor_version name new ole_classes ole_methods ole_type progid progids src_type to_s typekind typelibs variables visible?

### Public Class methods

WIN32OLE_TYPE.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.

[Source]

    /*
     *  call-seq:
     *     WIN32OLE_TYPE.new(typelib, ole_class) -> WIN32OLE_TYPE object
     *
     *  Returns a new WIN32OLE_TYPE object.
     *  The first argument <i>typelib</i> 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.
     */
    static VALUE
    foletype_initialize(self, typelib, oleclass)
        VALUE self;
        VALUE typelib;
        VALUE oleclass;
    {
        VALUE file;
        OLECHAR * pbuf;
        ITypeLib *pTypeLib;
        HRESULT hr;

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

WIN32OLE_TYPE.ole_classes(typelib)

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

[Source]

    /*
     *   call-seq:
     *      WIN32OLE_TYPE.ole_classes(typelib)
     *
     *   Returns array of WIN32OLE_TYPE objects defined by the <i>typelib</i> type library.
     */
    static VALUE
    foletype_s_ole_classes(self, typelib)
        VALUE self;
        VALUE typelib;
    {
        VALUE file, classes;
        OLECHAR * pbuf;
        ITypeLib *pTypeLib;
        HRESULT hr;

        rb_secure(4);
        classes = rb_ary_new();
        if(TYPE(typelib) == T_STRING) {
            file = typelib_file(typelib);
            if (file == Qnil) {
                file = typelib;
            }
            pbuf = ole_mb2wc(StringValuePtr(file), -1);
            hr = LoadTypeLibEx(pbuf, REGKIND_NONE, &pTypeLib);
            if (FAILED(hr))
              ole_raise(hr, eWIN32OLE_RUNTIME_ERROR, "failed to LoadTypeLibEx");
            SysFreeString(pbuf);
            ole_classes_from_typelib(pTypeLib, classes);
            OLE_RELEASE(pTypeLib);
        } else {
            rb_raise(rb_eTypeError, "1st argument should be TypeLib string");
        }
        return classes;
    }

WIN32OLE_TYPE.progids

Returns array of ProgID.

[Source]

    /*
     *  call-seq:
     *     WIN32OLE_TYPE.progids
     *
     *  Returns array of ProgID.
     */
    static VALUE
    foletype_s_progids(self)
        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_val(hclsid, "ProgID")) != Qnil)
                rb_ary_push(progids, v);
            if ((v = reg_get_val(hclsid, "VersionIndependentProgID")) != Qnil)
                rb_ary_push(progids, v);
            RegCloseKey(hclsid);
        }
        RegCloseKey(hclsids);
        return progids;
    }

WIN32OLE_TYPE.typelibs

Returns array of type libraries.

[Source]

    /*
     *  call-seq:
     *     WIN32OLE_TYPE.typelibs
     *
     *  Returns array of type libraries.
     *
     */
    static VALUE
    foletype_s_typelibs(self)
        VALUE self;
    {
        HKEY htypelib, hclsid;
        double fversion;
        DWORD i, j;
        LONG err;
        VALUE clsid;
        VALUE ver;
        VALUE v = Qnil;
        VALUE typelibs = rb_ary_new();

        err = reg_open_key(HKEY_CLASSES_ROOT, "TypeLib", &htypelib);
        if(err != ERROR_SUCCESS) {
            return typelibs;
        }
        for(i = 0; ; i++) {
            clsid = reg_enum_key(htypelib, i);
            if (clsid == Qnil)
                break;
            err = reg_open_vkey(htypelib, clsid, &hclsid);
            if (err != ERROR_SUCCESS)
                continue;
            fversion = 0;
            for(j = 0; ; j++) {
                ver = reg_enum_key(hclsid, j);
                if (ver == Qnil)
                    break;
                if (fversion > atof(StringValuePtr(ver)))
                    continue;
                fversion = atof(StringValuePtr(ver));
                if ( (v = reg_get_val(hclsid, StringValuePtr(ver))) != Qnil ) {
                    rb_ary_push(typelibs, v);
                }
            }
            RegCloseKey(hclsid);
        }
        RegCloseKey(htypelib);
        return typelibs;
    }

### Public Instance methods

WIN32OLE_TYPE#guid #=> GUID

Returns GUID.

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

[Source]

    /*
     *  call-seq:
     *     WIN32OLE_TYPE#guid  #=> GUID
     *
     *  Returns GUID.
     *    tobj = WIN32OLE_TYPE.new('Microsoft Excel 9.0 Object Library', 'Application')
     *    puts tobj.guid  # => {00024500-0000-0000-C000-000000000046}
     */
    static VALUE
    foletype_guid(self)
        VALUE self;
    {
        struct oletypedata *ptype;
        Data_Get_Struct(self, struct oletypedata, ptype);
        return ole_type_guid(ptype->pTypeInfo);
    }

WIN32OLE_TYPE#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

[Source]

    /*
     *  call-seq:
     *     WIN32OLE_TYPE#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
     */
    static VALUE
    foletype_helpcontext(self)
        VALUE self;
    {
        struct oletypedata *ptype;
        Data_Get_Struct(self, struct oletypedata, ptype);
        return ole_type_helpcontext(ptype->pTypeInfo);
    }

WIN32OLE_TYPE#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

[Source]

    /*
     *  call-seq:
     *     WIN32OLE_TYPE#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
     *
     */
    static VALUE
    foletype_helpfile(self)
        VALUE self;
    {
        struct oletypedata *ptype;
        Data_Get_Struct(self, struct oletypedata, ptype);
        return ole_type_helpfile(ptype->pTypeInfo);
    }

WIN32OLE_TYPE#helpstring #=> help string.

Returns help string.

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

[Source]

    /*
     *  call-seq:
     *    WIN32OLE_TYPE#helpstring #=> help string.
     *
     *  Returns help string.
     *    tobj = WIN32OLE_TYPE.new('Microsoft Internet Controls', 'IWebBrowser')
     *    puts tobj.helpstring # => Web Browser interface
     */
    static VALUE
    foletype_helpstring(self)
        VALUE self;
    {
        struct oletypedata *ptype;
        Data_Get_Struct(self, struct oletypedata, ptype);
        return ole_type_helpstring(ptype->pTypeInfo);
    }

WIN32OLE_TYPE#major_version

Returns major version.

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

[Source]

    /*
     *  call-seq:
     *     WIN32OLE_TYPE#major_version
     *
     *  Returns major version.
     *     tobj = WIN32OLE_TYPE.new('Microsoft Word 10.0 Object Library', 'Documents')
     *     puts tobj.major_version # => 8
     */
    static VALUE
    foletype_major_version(self)
        VALUE self;
    {
        struct oletypedata *ptype;
        Data_Get_Struct(self, struct oletypedata, ptype);
        return ole_type_major_version(ptype->pTypeInfo);
    }

WIN32OLE_TYPE#minor_version #=> OLE minor version

Returns minor version.

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

[Source]

    /*
     *  call-seq:
     *    WIN32OLE_TYPE#minor_version #=> OLE minor version
     *
     *  Returns minor version.
     *     tobj = WIN32OLE_TYPE.new('Microsoft Word 10.0 Object Library', 'Documents')
     *     puts tobj.minor_version # => 2
     */
    static VALUE
    foletype_minor_version(self)
        VALUE self;
    {
        struct oletypedata *ptype;
        Data_Get_Struct(self, struct oletypedata, ptype);
        return ole_type_minor_version(ptype->pTypeInfo);
    }

WIN32OLE_TYPE#name #=> OLE type name

Returns OLE type name.

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

[Source]

    /*
     * call-seq:
     *    WIN32OLE_TYPE#name #=> OLE type name
     *
     * Returns OLE type name.
     *    tobj = WIN32OLE_TYPE.new('Microsoft Excel 9.0 Object Library', 'Application')
     *    puts tobj.name  # => Application
     */
    static VALUE
    foletype_name(self)
        VALUE self;
    {
        return rb_ivar_get(self, rb_intern("name"));
    }

WIN32OLE_TYPE#ole_methods # the array of WIN32OLE_METHOD objects.

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',....]

[Source]

    /*
     *  call-seq:
     *     WIN32OLE_TYPE#ole_methods # the array of WIN32OLE_METHOD objects.
     *
     *  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',....]
     */
    static VALUE
    foletype_methods(argc, argv, self)
        int argc;
        VALUE *argv;
        VALUE self;
    {
        struct oletypedata *ptype;
        Data_Get_Struct(self, struct oletypedata, ptype);
        return ole_methods_from_typeinfo(ptype->pTypeInfo, INVOKE_FUNC | INVOKE_PROPERTYGET | INVOKE_PROPERTYPUT | INVOKE_PROPERTYPUTREF);
    }

WIN32OLE_TYPE#ole_type #=> OLE type string.

returns type of OLE class.

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

[Source]

    /*
     *  call-seq:
     *     WIN32OLE_TYPE#ole_type #=> OLE type string.
     *
     *  returns type of OLE class.
     *    tobj = WIN32OLE_TYPE.new('Microsoft Excel 9.0 Object Library', 'Application')
     *    puts tobj.ole_type  # => Class
     */
    static VALUE
    foletype_ole_type(self)
        VALUE self;
    {
        struct oletypedata *ptype;
        Data_Get_Struct(self, struct oletypedata, ptype);
        return ole_ole_type(ptype->pTypeInfo);
    }

WIN32OLE_TYPE#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

[Source]

    /*
     * call-seq:
     *    WIN32OLE_TYPE#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
     */
    static VALUE
    foletype_progid(self)
        VALUE self;
    {
        struct oletypedata *ptype;
        Data_Get_Struct(self, struct oletypedata, ptype);
        return ole_type_progid(ptype->pTypeInfo);
    }

WIN32OLE_TYPE#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

[Source]

    /*
     *  call-seq:
     *     WIN32OLE_TYPE#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
     *
     */
    static VALUE
    foletype_src_type(self)
        VALUE self;
    {
        struct oletypedata *ptype;
        Data_Get_Struct(self, struct oletypedata, ptype);
        return ole_type_src_type(ptype->pTypeInfo);
    }

to_s()

Alias for name

WIN32OLE_TYPE#typekind #=> number of type.

Returns number which represents type.

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

[Source]

    /*
     *  call-seq:
     *    WIN32OLE_TYPE#typekind #=> number of type.
     *
     *  Returns number which represents type.
     *    tobj = WIN32OLE_TYPE.new('Microsoft Word 10.0 Object Library', 'Documents')
     *    puts tobj.typekind # => 4
     *
     */
    static VALUE
    foletype_typekind(self)
        VALUE self;
    {
        struct oletypedata *ptype;
        Data_Get_Struct(self, struct oletypedata, ptype);
        return ole_type_typekind(ptype->pTypeInfo);
    }

WIN32OLE_TYPE#variables

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

[Source]

    /*
     *  call-seq:
     *     WIN32OLE_TYPE#variables
     *
     *  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
     *
     */
    static VALUE
    foletype_variables(self)
        VALUE self;
    {
        struct oletypedata *ptype;
        Data_Get_Struct(self, struct oletypedata, ptype);
        return ole_variables(ptype->pTypeInfo);
    }

WIN32OLE_TYPE#visible #=> true or false

Returns true if the OLE class is public.

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

[Source]

    /*
     *  call-seq:
     *    WIN32OLE_TYPE#visible  #=> true or false
     *
     *  Returns true if the OLE class is public.
     *    tobj = WIN32OLE_TYPE.new('Microsoft Excel 9.0 Object Library', 'Application')
     *    puts tobj.visible  # => true
     */
    static VALUE
    foletype_visible(self)
        VALUE self;
    {
        struct oletypedata *ptype;
        Data_Get_Struct(self, struct oletypedata, ptype);
        return ole_type_visible(ptype->pTypeInfo);
    }

[Validate]