類別 WIN32OLE::Typelib
公開類別方法
new(typelib [, version1, version2]) → WIN32OLE_TYPELIB 物件 按一下以切換來源
傳回新的 WIN32OLE_TYPELIB 物件。
第一個引數 typelib 指定 OLE 類別庫名稱或 GUID 或 OLE 程式庫檔案。第二個引數是類別庫的主要版本或版本。第三個引數是次要版本。第二個引數和第三個引數是選用的。如果第一個引數是類別庫名稱,則會略過第二個和第三個引數。
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'
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); rb_check_arity(len, 1, 3); 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; }
typelibs() 按一下以切換來源
WIN32OLE_TYPELIB.typelibs
傳回 WIN32OLE_TYPELIB 物件陣列。
tlibs = WIN32OLE_TYPELIB.typelibs
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; }
公開執行個體方法
WIN32OLE_TYPELIB#guid → GUID 字串。 按一下以切換來源
傳回指定類別庫的 GUID 字串。
tlib = WIN32OLE_TYPELIB.new('Microsoft Excel 9.0 Object Library') guid = tlib.guid # -> '{00020813-0000-0000-C000-000000000046}'
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; }
WIN32OLE_TYPELIB#inspect → 字串 按一下以切換來源
傳回類別庫名稱和類別名稱。
tlib = WIN32OLE_TYPELIB.new('Microsoft Excel 9.0 Object Library') tlib.inspect # => "<#WIN32OLE_TYPELIB:Microsoft Excel 9.0 Object Library>"
static VALUE foletypelib_inspect(VALUE self) { return default_inspect(self, "WIN32OLE_TYPELIB"); }
WIN32OLE_TYPELIB#library_name 按一下以切換來源
傳回程式庫名稱。如果方法無法存取程式庫名稱,則會引發 WIN32OLERuntimeError
。
tlib = WIN32OLE_TYPELIB.new('Microsoft Excel 9.0 Object Library') tlib.library_name # => Excel
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; }
WIN32OLE_TYPELIB#major_version → 類別庫主要版本。 按一下以切換來源
傳回類別庫主要版本。
tlib = WIN32OLE_TYPELIB.new('Microsoft Excel 9.0 Object Library') puts tlib.major_version # -> 1
static VALUE foletypelib_major_version(VALUE self) { TLIBATTR *pTLibAttr; VALUE major; ITypeLib *pTypeLib; pTypeLib = itypelib(self); oletypelib_get_libattr(pTypeLib, &pTLibAttr); major = RB_INT2NUM(pTLibAttr->wMajorVerNum); pTypeLib->lpVtbl->ReleaseTLibAttr(pTypeLib, pTLibAttr); return major; }
WIN32OLE_TYPELIB#minor_version → 類別庫次要版本。 按一下以切換來源
傳回類別庫次要版本。
tlib = WIN32OLE_TYPELIB.new('Microsoft Excel 9.0 Object Library') puts tlib.minor_version # -> 3
static VALUE foletypelib_minor_version(VALUE self) { TLIBATTR *pTLibAttr; VALUE minor; ITypeLib *pTypeLib; pTypeLib = itypelib(self); oletypelib_get_libattr(pTypeLib, &pTLibAttr); minor = RB_INT2NUM(pTLibAttr->wMinorVerNum); pTypeLib->lpVtbl->ReleaseTLibAttr(pTypeLib, pTLibAttr); return minor; }
WIN32OLE_TYPELIB#name → 類別庫名稱 按一下以切換來源
傳回類別庫名稱。
tlib = WIN32OLE_TYPELIB.new('Microsoft Excel 9.0 Object Library') name = tlib.name # -> 'Microsoft Excel 9.0 Object Library'
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; }
別名為: to_s
WIN32OLE_TYPELIB#ole_types → 包含類別庫的 WIN32OLE_TYPE 物件陣列。
傳回類別庫檔案路徑。
tlib = WIN32OLE_TYPELIB.new('Microsoft Excel 9.0 Object Library') classes = tlib.ole_types.collect{|k| k.name} # -> ['AddIn', 'AddIns' ...]
別名:ole_types
WIN32OLE_TYPELIB#ole_types → 包含類型庫的 WIN32OLE_TYPE 物件陣列。 按一下以切換來源
傳回類別庫檔案路徑。
tlib = WIN32OLE_TYPELIB.new('Microsoft Excel 9.0 Object Library') classes = tlib.ole_types.collect{|k| k.name} # -> ['AddIn', 'AddIns' ...]
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; }
別名:ole_classes
WIN32OLE_TYPELIB#path → 類型庫檔案路徑。 按一下以切換來源
傳回類別庫檔案路徑。
tlib = WIN32OLE_TYPELIB.new('Microsoft Excel 9.0 Object Library') puts tlib.path #-> 'C:\...\EXCEL9.OLB'
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; }
WIN32OLE_TYPELIB#name → 類型庫名稱
傳回類別庫名稱。
tlib = WIN32OLE_TYPELIB.new('Microsoft Excel 9.0 Object Library') name = tlib.name # -> 'Microsoft Excel 9.0 Object Library'
別名:name
WIN32OLE_TYPELIB#version → 類型庫版本字串物件。 按一下以切換來源
傳回類型庫版本。
tlib = WIN32OLE_TYPELIB.new('Microsoft Excel 9.0 Object Library') puts tlib.version #-> "1.3"
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; }
WIN32OLE_TYPELIB#visible? 按一下以切換來源
如果類型庫資訊未隱藏,傳回 true。如果 TLIBATTR 的 wLibFlags 為 0 或 LIBFLAG_FRESTRICTED 或 LIBFLAG_FHIDDEN,方法會傳回 false,否則會傳回 true。如果方法無法存取 TLIBATTR 資訊,則會引發 WIN32OLERuntimeError
。
tlib = WIN32OLE_TYPELIB.new('Microsoft Excel 9.0 Object Library') tlib.visible? # => true
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; }