Class: WIN32OLE_TYPELIB
- Inherits:
-
Object
- Object
- WIN32OLE_TYPELIB
- Defined in:
- win32ole_typelib.c,
win32ole_typelib.c
Overview
WIN32OLE_TYPELIB
objects represent OLE tyblib information.
Class Method Summary collapse
-
.typelibs ⇒ Object
Returns the array of WIN32OLE_TYPELIB object.
Instance Method Summary collapse
-
#guid ⇒ The guid string.
Returns guid string which specifies type library.
-
#new(typelib[, version1, version2]) ⇒ WIN32OLE_TYPELIB object
constructor
Returns a new WIN32OLE_TYPELIB object.
-
#inspect ⇒ String
Returns the type library name with class name.
-
#library_name ⇒ Object
Returns library name.
-
#major_version ⇒ The type library major version.
Returns the type library major version.
-
#minor_version ⇒ The type library minor version.
Returns the type library minor version.
-
#name ⇒ The type library name
(also: #to_s)
Returns the type library name.
-
#ole_types ⇒ The array of WIN32OLE_TYPE object included the type library.
(also: #ole_classes)
Returns the type library file path.
-
#path ⇒ The type library file path.
Returns the type library file path.
-
#version ⇒ The type library version String object.
Returns the type library version.
-
#visible? ⇒ Boolean
Returns true if the type library information is not hidden.
Constructor Details
#new(typelib[, version1, version2]) ⇒ WIN32OLE_TYPELIB object
Returns a new WIN32OLE_TYPELIB object.
The first argument typelib specifies OLE type library name or GUID or OLE library file. 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)
tlib5 = WIN32OLE_TYPELIB.new("C:\\WINNT\\SYSTEM32\\SHELL32.DLL")
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'
puts tlib5.name # -> 'Microsoft Shell Controls And Automation'
391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 |
# File 'win32ole_typelib.c', line 391
static VALUE
foletypelib_initialize(VALUE self, VALUE args)
{
VALUE found = Qfalse;
VALUE typelib = Qnil;
int len = 0;
OLECHAR * pbuf;
ITypeLib *pTypeLib;
HRESULT hr = S_OK;
len = RARRAY_LEN(args);
if (len < 1 || len > 3) {
rb_raise(rb_eArgError, "wrong number of arguments (%d for 1..3)", len);
}
typelib = rb_ary_entry(args, 0);
SafeStringValue(typelib);
found = oletypelib_search_registry(self, typelib);
if (found == Qfalse) {
found = oletypelib_search_registry2(self, args);
}
if (found == Qfalse) {
pbuf = ole_vstr2wc(typelib);
hr = LoadTypeLibEx(pbuf, REGKIND_NONE, &pTypeLib);
SysFreeString(pbuf);
if (SUCCEEDED(hr)) {
found = Qtrue;
oletypelib_set_member(self, pTypeLib);
}
}
if (found == Qfalse) {
rb_raise(eWIN32OLERuntimeError, "not found type library `%s`",
StringValuePtr(typelib));
}
return self;
}
|
Class Method Details
.typelibs ⇒ Object
Returns the array of WIN32OLE_TYPELIB object.
tlibs = WIN32OLE_TYPELIB.typelibs
145 146 147 148 149 150 151 152 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 183 184 185 186 |
# File 'win32ole_typelib.c', line 145
static VALUE
foletypelib_s_typelibs(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;
HRESULT hr;
ITypeLib *pTypeLib;
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_val2(hguid, StringValuePtr(version))) != Qnil ) {
hr = oletypelib_from_guid(guid, version, &pTypeLib);
if (SUCCEEDED(hr)) {
typelib = create_win32ole_typelib(pTypeLib);
rb_ary_push(typelibs, typelib);
}
}
}
RegCloseKey(hguid);
}
RegCloseKey(htypelib);
return typelibs;
}
|
Instance Method Details
#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}'
440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 |
# File 'win32ole_typelib.c', line 440
static VALUE
foletypelib_guid(VALUE self)
{
ITypeLib *pTypeLib;
OLECHAR bstr[80];
VALUE guid = Qnil;
int len;
TLIBATTR *pTLibAttr;
pTypeLib = itypelib(self);
oletypelib_get_libattr(pTypeLib, &pTLibAttr);
len = StringFromGUID2(&pTLibAttr->guid, bstr, sizeof(bstr)/sizeof(OLECHAR));
if (len > 3) {
guid = ole_wc2vstr(bstr, FALSE);
}
pTypeLib->lpVtbl->ReleaseTLibAttr(pTypeLib, pTLibAttr);
return guid;
}
|
#inspect ⇒ String
Returns the type library name with class name.
tlib = WIN32OLE_TYPELIB.new('Microsoft Excel 9.0 Object Library')
tlib.inspect # => "<#WIN32OLE_TYPELIB:Microsoft Excel 9.0 Object Library>"
821 822 823 824 825 |
# File 'win32ole_typelib.c', line 821
static VALUE
foletypelib_inspect(VALUE self)
{
return default_inspect(self, "WIN32OLE_TYPELIB");
}
|
#library_name ⇒ Object
Returns library name. If the method fails to access library name, WIN32OLERuntimeError is raised.
tlib = WIN32OLE_TYPELIB.new('Microsoft Excel 9.0 Object Library')
tlib.library_name # => Excel
649 650 651 652 653 654 655 656 657 658 659 660 661 662 663 664 665 |
# File 'win32ole_typelib.c', line 649
static VALUE
foletypelib_library_name(VALUE self)
{
HRESULT hr;
ITypeLib *pTypeLib = NULL;
VALUE libname = Qnil;
BSTR bstr;
pTypeLib = itypelib(self);
hr = pTypeLib->lpVtbl->GetDocumentation(pTypeLib, -1,
&bstr, NULL, NULL, NULL);
if (FAILED(hr)) {
ole_raise(hr, eWIN32OLERuntimeError, "failed to get library name");
}
libname = WC2VSTR(bstr);
return libname;
}
|
#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
535 536 537 538 539 540 541 542 543 544 545 546 547 |
# File 'win32ole_typelib.c', line 535
static VALUE
foletypelib_major_version(VALUE self)
{
TLIBATTR *pTLibAttr;
VALUE major;
ITypeLib *pTypeLib;
pTypeLib = itypelib(self);
oletypelib_get_libattr(pTypeLib, &pTLibAttr);
major = INT2NUM(pTLibAttr->wMajorVerNum);
pTypeLib->lpVtbl->ReleaseTLibAttr(pTypeLib, pTLibAttr);
return major;
}
|
#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
558 559 560 561 562 563 564 565 566 567 568 569 |
# File 'win32ole_typelib.c', line 558
static VALUE
foletypelib_minor_version(VALUE self)
{
TLIBATTR *pTLibAttr;
VALUE minor;
ITypeLib *pTypeLib;
pTypeLib = itypelib(self);
oletypelib_get_libattr(pTypeLib, &pTLibAttr);
minor = INT2NUM(pTLibAttr->wMinorVerNum);
pTypeLib->lpVtbl->ReleaseTLibAttr(pTypeLib, pTLibAttr);
return minor;
}
|
#name ⇒ The type library name Also known as: to_s
Returns the type library name.
tlib = WIN32OLE_TYPELIB.new('Microsoft Excel 9.0 Object Library')
name = tlib.name # -> 'Microsoft Excel 9.0 Object Library'
468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 |
# File 'win32ole_typelib.c', line 468
static VALUE
foletypelib_name(VALUE self)
{
ITypeLib *pTypeLib;
HRESULT hr;
BSTR bstr;
VALUE name;
pTypeLib = itypelib(self);
hr = pTypeLib->lpVtbl->GetDocumentation(pTypeLib, -1,
NULL, &bstr, NULL, NULL);
if (FAILED(hr)) {
ole_raise(hr, eWIN32OLERuntimeError, "failed to get name from ITypeLib");
}
name = WC2VSTR(bstr);
return name;
}
|
#ole_types ⇒ The array of WIN32OLE_TYPE object included the type library. Also known as: ole_classes
Returns the type library file path.
tlib = WIN32OLE_TYPELIB.new('Microsoft Excel 9.0 Object Library')
classes = tlib.ole_types.collect{|k| k.name} # -> ['AddIn', 'AddIns' ...]
802 803 804 805 806 807 808 809 810 |
# File 'win32ole_typelib.c', line 802
static VALUE
foletypelib_ole_types(VALUE self)
{
ITypeLib *pTypeLib = NULL;
VALUE classes = rb_ary_new();
pTypeLib = itypelib(self);
ole_types_from_typelib(pTypeLib, classes);
return classes;
}
|
#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'
580 581 582 583 584 585 586 587 588 589 590 591 592 593 594 595 596 597 598 599 600 601 602 603 604 605 |
# File 'win32ole_typelib.c', line 580
static VALUE
foletypelib_path(VALUE self)
{
TLIBATTR *pTLibAttr;
HRESULT hr = S_OK;
BSTR bstr;
LCID lcid = cWIN32OLE_lcid;
VALUE path;
ITypeLib *pTypeLib;
pTypeLib = itypelib(self);
oletypelib_get_libattr(pTypeLib, &pTLibAttr);
hr = QueryPathOfRegTypeLib(&pTLibAttr->guid,
pTLibAttr->wMajorVerNum,
pTLibAttr->wMinorVerNum,
lcid,
&bstr);
if (FAILED(hr)) {
pTypeLib->lpVtbl->ReleaseTLibAttr(pTypeLib, pTLibAttr);
ole_raise(hr, eWIN32OLERuntimeError, "failed to QueryPathOfRegTypeTypeLib");
}
pTypeLib->lpVtbl->ReleaseTLibAttr(pTypeLib, pTLibAttr);
path = WC2VSTR(bstr);
return path;
}
|
#version ⇒ The type library version String object.
Returns the type library version.
tlib = WIN32OLE_TYPELIB.new('Microsoft Excel 9.0 Object Library')
puts tlib.version #-> "1.3"
512 513 514 515 516 517 518 519 520 521 522 523 524 |
# File 'win32ole_typelib.c', line 512
static VALUE
foletypelib_version(VALUE self)
{
TLIBATTR *pTLibAttr;
ITypeLib *pTypeLib;
VALUE version;
pTypeLib = itypelib(self);
oletypelib_get_libattr(pTypeLib, &pTLibAttr);
version = rb_sprintf("%d.%d", pTLibAttr->wMajorVerNum, pTLibAttr->wMinorVerNum);
pTypeLib->lpVtbl->ReleaseTLibAttr(pTypeLib, pTLibAttr);
return version;
}
|
#visible? ⇒ Boolean
Returns true if the type library information is not hidden. If wLibFlags of TLIBATTR is 0 or LIBFLAG_FRESTRICTED or LIBFLAG_FHIDDEN, the method returns false, otherwise, returns true. If the method fails to access the TLIBATTR information, then WIN32OLERuntimeError is raised.
tlib = WIN32OLE_TYPELIB.new('Microsoft Excel 9.0 Object Library')
tlib.visible? # => true
620 621 622 623 624 625 626 627 628 629 630 631 632 633 634 635 636 637 |
# File 'win32ole_typelib.c', line 620
static VALUE
foletypelib_visible(VALUE self)
{
ITypeLib *pTypeLib = NULL;
VALUE visible = Qtrue;
TLIBATTR *pTLibAttr;
pTypeLib = itypelib(self);
oletypelib_get_libattr(pTypeLib, &pTLibAttr);
if ((pTLibAttr->wLibFlags == 0) ||
(pTLibAttr->wLibFlags & LIBFLAG_FRESTRICTED) ||
(pTLibAttr->wLibFlags & LIBFLAG_FHIDDEN)) {
visible = Qfalse;
}
pTypeLib->lpVtbl->ReleaseTLibAttr(pTypeLib, pTLibAttr);
return visible;
}
|