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

`WIN32OLE_TYPELIB` objects represent OLE tyblib information.

### Methods

guid major_version minor_version name new ole_classes path to_s typelibs version

### Public Class methods

WIN32OLE_TYPELIB.new(typelib [, version1, version2]) → WIN32OLE_TYPELIB object

Returns a new WIN32OLE_TYPELIB object.

The first argument typelib specifies OLE type library name or GUID. The second argument is major version or version of the type library. The third argument is minor version. The second argument and third argument are optional. If the first argument is type library name, then the second and third argument are ignored.

        tlib1 = WIN32OLE_TYPELIB.new('Microsoft Excel 9.0 Object Library')
        tlib2 = WIN32OLE_TYPELIB.new('{00020813-0000-0000-C000-000000000046}')
        tlib3 = WIN32OLE_TYPELIB.new('{00020813-0000-0000-C000-000000000046}', 1.3)
        tlib4 = WIN32OLE_TYPELIB.new('{00020813-0000-0000-C000-000000000046}', 1, 3)
        puts tlib1.name  # -> 'Microsoft Excel 9.0 Object Library'
        puts tlib2.name  # -> 'Microsoft Excel 9.0 Object Library'
        puts tlib3.name  # -> 'Microsoft Excel 9.0 Object Library'
        puts tlib4.name  # -> 'Microsoft Excel 9.0 Object Library'

[Source]

    /*
     * call-seq:
     *    WIN32OLE_TYPELIB.new(typelib [, version1, version2]) -> WIN32OLE_TYPELIB object
     *
     * Returns a new WIN32OLE_TYPELIB object.
     *
     * The first argument <i>typelib</i>  specifies OLE type library name or GUID.
     * The second argument is major version or version of the type library.
     * The third argument is minor version.
     * The second argument and third argument are optional.
     * If the first argument is type library name, then the second and third argument
     * are ignored.
     *
     *     tlib1 = WIN32OLE_TYPELIB.new('Microsoft Excel 9.0 Object Library')
     *     tlib2 = WIN32OLE_TYPELIB.new('{00020813-0000-0000-C000-000000000046}')
     *     tlib3 = WIN32OLE_TYPELIB.new('{00020813-0000-0000-C000-000000000046}', 1.3)
     *     tlib4 = WIN32OLE_TYPELIB.new('{00020813-0000-0000-C000-000000000046}', 1, 3)
     *     puts tlib1.name  # -> 'Microsoft Excel 9.0 Object Library'
     *     puts tlib2.name  # -> 'Microsoft Excel 9.0 Object Library'
     *     puts tlib3.name  # -> 'Microsoft Excel 9.0 Object Library'
     *     puts tlib4.name  # -> 'Microsoft Excel 9.0 Object Library'
     *
     */
    static VALUE
    foletypelib_initialize(self, args)
        VALUE self;
        VALUE args;
    {
        VALUE found = Qfalse;
        VALUE typelib = Qnil;
        int len = 0;

        len = RARRAY(args)->len;
        if (len < 1 || len > 3) {
            rb_raise(rb_eArgError, "wrong number of arguments (%d for 1..3)", len);
        }

        typelib = rb_ary_entry(args, 0);

        Check_SafeStr(typelib);

        found = oletypelib_search_registry(self, typelib);
        if (found == Qfalse) {
            found = oletypelib_search_registry2(self, args);
        }

        if (found == Qfalse) {
            rb_raise(eWIN32OLE_RUNTIME_ERROR, "not found type library `%s`",
                     StringValuePtr(typelib));
        }
        return self;
    }

       WIN32OLE_TYPELIB.typelibs

Returns the array of WIN32OLE_TYPELIB object.

       tlibs = WIN32OLE_TYPELIB.typelibs

[Source]

    /*
     *  call-seq:
     *
     *     WIN32OLE_TYPELIB.typelibs
     *
     *  Returns the array of WIN32OLE_TYPELIB object.
     *
     *     tlibs = WIN32OLE_TYPELIB.typelibs
     *
     */
    static VALUE
    foletypelib_s_typelibs(self)
        VALUE self;
    {
        HKEY htypelib, hguid;
        DWORD i, j;
        LONG err;
        VALUE guid;
        VALUE version;
        VALUE name = Qnil;
        VALUE typelibs = rb_ary_new();
        VALUE typelib = Qnil;

        err = reg_open_key(HKEY_CLASSES_ROOT, "TypeLib", &htypelib);
        if(err != ERROR_SUCCESS) {
            return typelibs;
        }
        for(i = 0; ; i++) {
            guid = reg_enum_key(htypelib, i);
            if (guid == Qnil)
                break;
            err = reg_open_vkey(htypelib, guid, &hguid);
            if (err != ERROR_SUCCESS)
                continue;
            for(j = 0; ; j++) {
                version = reg_enum_key(hguid, j);
                if (version == Qnil)
                    break;
                if ( (name = reg_get_val(hguid, StringValuePtr(version))) != Qnil ) {
                    typelib = rb_funcall(cWIN32OLE_TYPELIB, rb_intern("allocate"), 0);
                    oletypelib_set_member(typelib, name, guid, version);
                    rb_ary_push(typelibs, typelib);
                }
            }
            RegCloseKey(hguid);
        }
        RegCloseKey(htypelib);
        return typelibs;
    }

### Public Instance methods

WIN32OLE_TYPELIB#guid → The guid string.

Returns guid string which specifies type library.

       tlib = WIN32OLE_TYPELIB.new('Microsoft Excel 9.0 Object Library')
       guid = tlib.guid # -> '{00020813-0000-0000-C000-000000000046}'

[Source]

    /*
     *  call-seq:
     *     WIN32OLE_TYPELIB#guid -> The guid string.
     *
     *  Returns guid string which specifies type library.
     *
     *     tlib = WIN32OLE_TYPELIB.new('Microsoft Excel 9.0 Object Library')
     *     guid = tlib.guid # -> '{00020813-0000-0000-C000-000000000046}'
     */
    static VALUE
    foletypelib_guid(self)
        VALUE self;
    {
        return rb_ivar_get(self, rb_intern("guid"));
    }

WIN32OLE_TYPELIB#major_version → The type library major version.

Returns the type library major version.

       tlib = WIN32OLE_TYPELIB.new('Microsoft Excel 9.0 Object Library')
       puts tlib.major_version # -> 1

[Source]

    /*
     *  call-seq:
     *     WIN32OLE_TYPELIB#major_version -> The type library major version.
     *
     *  Returns the type library major version.
     *
     *     tlib = WIN32OLE_TYPELIB.new('Microsoft Excel 9.0 Object Library')
     *     puts tlib.major_version # -> 1
     */
    static VALUE
    foletypelib_major_version(self)
        VALUE self;
    {
        VALUE ver = rb_ivar_get(self, rb_intern("version"));
        VALUE ary = rb_str_split(ver, ".");
        return rb_Integer(rb_ary_entry(ary, 0));
    }

WIN32OLE_TYPELIB#minor_version → The type library minor version.

Returns the type library minor version.

       tlib = WIN32OLE_TYPELIB.new('Microsoft Excel 9.0 Object Library')
       puts tlib.minor_version # -> 3

[Source]

    /*
     *  call-seq:
     *     WIN32OLE_TYPELIB#minor_version -> The type library minor version.
     *
     *  Returns the type library minor version.
     *
     *     tlib = WIN32OLE_TYPELIB.new('Microsoft Excel 9.0 Object Library')
     *     puts tlib.minor_version # -> 3
     */
    static VALUE
    foletypelib_minor_version(self)
        VALUE self;
    {
        VALUE ver = rb_ivar_get(self, rb_intern("version"));
        VALUE ary = rb_str_split(ver, ".");
        return rb_Integer(rb_ary_entry(ary, 1));
    }

WIN32OLE_TYPELIB#name → The type library name

Returns the type library name.

       tlib = WIN32OLE_TYPELIB.new('Microsoft Excel 9.0 Object Library')
       name = tlib.name # -> 'Microsoft Excel 9.0 Object Library'

[Source]

    /*
     *  call-seq:
     *     WIN32OLE_TYPELIB#name -> The type library name
     *
     *  Returns the type library name.
     *
     *     tlib = WIN32OLE_TYPELIB.new('Microsoft Excel 9.0 Object Library')
     *     name = tlib.name # -> 'Microsoft Excel 9.0 Object Library'
     */
    static VALUE
    foletypelib_name(self)
        VALUE self;
    {
        return rb_ivar_get(self, rb_intern("name"));
    }

WIN32OLE_TYPELIB#ole_classes → The array of WIN32OLE_TYPE object included the type library.

Returns the type library file path.

       tlib = WIN32OLE_TYPELIB.new('Microsoft Excel 9.0 Object Library')
       classes = tlib.ole_classes.collect{|k| k.name} # -> ['AddIn', 'AddIns' ...]

[Source]

    /*
     *  call-seq:
     *     WIN32OLE_TYPELIB#ole_classes -> The array of WIN32OLE_TYPE object included the type library.
     *
     *  Returns the type library file path.
     *
     *     tlib = WIN32OLE_TYPELIB.new('Microsoft Excel 9.0 Object Library')
     *     classes = tlib.ole_classes.collect{|k| k.name} # -> ['AddIn', 'AddIns' ...]
     */
    static VALUE
    foletypelib_ole_classes(self)
        VALUE self;
    {
        OLECHAR * pbuf;
        HRESULT hr;
        ITypeLib *pTypeLib;
        VALUE path = Qnil;
        VALUE classes = rb_ary_new();
        path = rb_funcall(self, rb_intern("path"), 0);
        if (path != Qnil) {
            pbuf = ole_mb2wc(StringValuePtr(path), -1);
            hr = LoadTypeLibEx(pbuf, REGKIND_NONE, &pTypeLib);
            SysFreeString(pbuf);
            if (FAILED(hr))
                ole_raise(hr, eWIN32OLE_RUNTIME_ERROR, "failed to LoadTypeLibEx from `%s'",
                          StringValuePtr(path));
            ole_classes_from_typelib(pTypeLib, classes);
            OLE_RELEASE(pTypeLib);
        } else {
            rb_raise(eWIN32OLE_RUNTIME_ERROR, "failed to get type library path");
        }
        return classes;
    }

WIN32OLE_TYPELIB#path → The type library file path.

Returns the type library file path.

       tlib = WIN32OLE_TYPELIB.new('Microsoft Excel 9.0 Object Library')
       puts tlib.path #-> 'C:\...\EXCEL9.OLB'

[Source]

    /*
     *  call-seq:
     *     WIN32OLE_TYPELIB#path -> The type library file path.
     *
     *  Returns the type library file path.
     *
     *     tlib = WIN32OLE_TYPELIB.new('Microsoft Excel 9.0 Object Library')
     *     puts tlib.path #-> 'C:\...\EXCEL9.OLB'
     */
    static VALUE
    foletypelib_path(self)
        VALUE self;
    {
        VALUE guid = rb_ivar_get(self, rb_intern("guid"));
        VALUE version = rb_ivar_get(self, rb_intern("version"));
        return oletypelib_path(guid, version);
    }

to_s()

Alias for name

WIN32OLE_TYPELIB#version → The type library version.

Returns the type library version.

       tlib = WIN32OLE_TYPELIB.new('Microsoft Excel 9.0 Object Library')
       puts tlib.version #-> 1.3

[Source]

    /*
     *  call-seq:
     *     WIN32OLE_TYPELIB#version -> The type library version.
     *
     *  Returns the type library version.
     *
     *     tlib = WIN32OLE_TYPELIB.new('Microsoft Excel 9.0 Object Library')
     *     puts tlib.version #-> 1.3
     */
    static VALUE
    foletypelib_version(self)
        VALUE self;
    {
        VALUE ver = rb_ivar_get(self, rb_intern("version"));
        return rb_Float(ver);
    }

[Validate]