mirror of
https://github.com/ruby/ruby.git
synced 2022-11-09 12:17:21 -05:00
WIN32OLE_TYPELIB.new accepts OLE files.
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@10082 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
This commit is contained in:
parent
3b7c8b3488
commit
11974f3b6d
3 changed files with 60 additions and 18 deletions
|
@ -1,3 +1,10 @@
|
||||||
|
Fri Apr 7 22:11:30 2006 Masaki Suketa <masaki.suketa@nifty.ne.jp>
|
||||||
|
|
||||||
|
* ext/win32ole/win32ole.c(foletypelib_initialize): WIN32OLE_TYPELIB.new
|
||||||
|
accepts OLE file.
|
||||||
|
|
||||||
|
* test/win32ole/test_win32ole_typelib.rb(test_initialize): ditto.
|
||||||
|
|
||||||
Thu Apr 6 16:43:06 2006 Hidetoshi NAGAI <nagai@ai.kyutech.ac.jp>
|
Thu Apr 6 16:43:06 2006 Hidetoshi NAGAI <nagai@ai.kyutech.ac.jp>
|
||||||
|
|
||||||
* intern.h (rb_obj_instance_exec, rb_mod_module_exec): add declaration.
|
* intern.h (rb_obj_instance_exec, rb_mod_module_exec): add declaration.
|
||||||
|
|
|
@ -79,7 +79,7 @@
|
||||||
|
|
||||||
#define WC2VSTR(x) ole_wc2vstr((x), TRUE)
|
#define WC2VSTR(x) ole_wc2vstr((x), TRUE)
|
||||||
|
|
||||||
#define WIN32OLE_VERSION "0.7.3"
|
#define WIN32OLE_VERSION "0.7.4"
|
||||||
|
|
||||||
typedef HRESULT (STDAPICALLTYPE FNCOCREATEINSTANCEEX)
|
typedef HRESULT (STDAPICALLTYPE FNCOCREATEINSTANCEEX)
|
||||||
(REFCLSID, IUnknown*, DWORD, COSERVERINFO*, DWORD, MULTI_QI*);
|
(REFCLSID, IUnknown*, DWORD, COSERVERINFO*, DWORD, MULTI_QI*);
|
||||||
|
@ -3531,40 +3531,47 @@ make_oletypelib_obj(guid, major_version, minor_version)
|
||||||
}
|
}
|
||||||
|
|
||||||
static VALUE
|
static VALUE
|
||||||
ole_typelib_from_itypeinfo(pTypeInfo)
|
ole_typelib_from_itypelib(pTypeLib)
|
||||||
ITypeInfo *pTypeInfo;
|
|
||||||
{
|
|
||||||
HRESULT hr;
|
|
||||||
ITypeLib *pTypeLib;
|
ITypeLib *pTypeLib;
|
||||||
|
{
|
||||||
TLIBATTR *pTLibAttr;
|
TLIBATTR *pTLibAttr;
|
||||||
OLECHAR bstr[80];
|
OLECHAR bstr[80];
|
||||||
int len;
|
|
||||||
VALUE guid = Qnil;
|
VALUE guid = Qnil;
|
||||||
VALUE major;
|
VALUE major;
|
||||||
VALUE minor;
|
VALUE minor;
|
||||||
unsigned int index;
|
HRESULT hr = pTypeLib->lpVtbl->GetLibAttr(pTypeLib, &pTLibAttr);
|
||||||
|
int len = StringFromGUID2(&pTLibAttr->guid, bstr, sizeof(bstr)/sizeof(OLECHAR));
|
||||||
hr = pTypeInfo->lpVtbl->GetContainingTypeLib(pTypeInfo, &pTypeLib, &index);
|
|
||||||
if(FAILED(hr)) {
|
|
||||||
return Qnil;
|
|
||||||
}
|
|
||||||
|
|
||||||
hr = pTypeLib->lpVtbl->GetLibAttr(pTypeLib, &pTLibAttr);
|
|
||||||
|
|
||||||
len = StringFromGUID2(&pTLibAttr->guid, bstr, sizeof(bstr)/sizeof(OLECHAR));
|
|
||||||
if (len > 3) {
|
if (len > 3) {
|
||||||
guid = ole_wc2vstr(bstr, FALSE);
|
guid = ole_wc2vstr(bstr, FALSE);
|
||||||
}
|
}
|
||||||
major = INT2NUM(pTLibAttr->wMajorVerNum);
|
major = INT2NUM(pTLibAttr->wMajorVerNum);
|
||||||
minor = INT2NUM(pTLibAttr->wMinorVerNum);
|
minor = INT2NUM(pTLibAttr->wMinorVerNum);
|
||||||
pTypeLib->lpVtbl->ReleaseTLibAttr(pTypeLib, pTLibAttr);
|
pTypeLib->lpVtbl->ReleaseTLibAttr(pTypeLib, pTLibAttr);
|
||||||
OLE_RELEASE(pTypeLib);
|
|
||||||
if (guid == Qnil) {
|
if (guid == Qnil) {
|
||||||
return Qnil;
|
return Qnil;
|
||||||
}
|
}
|
||||||
return make_oletypelib_obj(guid, major, minor);
|
return make_oletypelib_obj(guid, major, minor);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
static VALUE
|
||||||
|
ole_typelib_from_itypeinfo(pTypeInfo)
|
||||||
|
ITypeInfo *pTypeInfo;
|
||||||
|
{
|
||||||
|
HRESULT hr;
|
||||||
|
ITypeLib *pTypeLib;
|
||||||
|
unsigned int index;
|
||||||
|
VALUE retval = Qnil;
|
||||||
|
|
||||||
|
hr = pTypeInfo->lpVtbl->GetContainingTypeLib(pTypeInfo, &pTypeLib, &index);
|
||||||
|
if(FAILED(hr)) {
|
||||||
|
return Qnil;
|
||||||
|
}
|
||||||
|
retval = ole_typelib_from_itypelib(pTypeLib);
|
||||||
|
OLE_RELEASE(pTypeLib);
|
||||||
|
return retval;
|
||||||
|
}
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* call-seq:
|
* call-seq:
|
||||||
* WIN32OLE#ole_typelib -> The WIN32OLE_TYPELIB object
|
* WIN32OLE#ole_typelib -> The WIN32OLE_TYPELIB object
|
||||||
|
@ -4254,7 +4261,8 @@ oletypelib_search_registry(self, typelib)
|
||||||
*
|
*
|
||||||
* Returns a new WIN32OLE_TYPELIB object.
|
* Returns a new WIN32OLE_TYPELIB object.
|
||||||
*
|
*
|
||||||
* The first argument <i>typelib</i> specifies OLE type library name or GUID.
|
* The first argument <i>typelib</i> specifies OLE type library name or GUID or
|
||||||
|
* OLE library file.
|
||||||
* The second argument is major version or version of the type library.
|
* The second argument is major version or version of the type library.
|
||||||
* The third argument is minor version.
|
* The third argument is minor version.
|
||||||
* The second argument and third argument are optional.
|
* The second argument and third argument are optional.
|
||||||
|
@ -4265,10 +4273,12 @@ oletypelib_search_registry(self, typelib)
|
||||||
* tlib2 = WIN32OLE_TYPELIB.new('{00020813-0000-0000-C000-000000000046}')
|
* tlib2 = WIN32OLE_TYPELIB.new('{00020813-0000-0000-C000-000000000046}')
|
||||||
* tlib3 = WIN32OLE_TYPELIB.new('{00020813-0000-0000-C000-000000000046}', 1.3)
|
* tlib3 = WIN32OLE_TYPELIB.new('{00020813-0000-0000-C000-000000000046}', 1.3)
|
||||||
* tlib4 = 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 tlib1.name # -> 'Microsoft Excel 9.0 Object Library'
|
||||||
* puts tlib2.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 tlib3.name # -> 'Microsoft Excel 9.0 Object Library'
|
||||||
* puts tlib4.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
|
static VALUE
|
||||||
|
@ -4279,6 +4289,11 @@ foletypelib_initialize(self, args)
|
||||||
VALUE found = Qfalse;
|
VALUE found = Qfalse;
|
||||||
VALUE typelib = Qnil;
|
VALUE typelib = Qnil;
|
||||||
int len = 0;
|
int len = 0;
|
||||||
|
OLECHAR * pbuf;
|
||||||
|
ITypeLib *pTypeLib;
|
||||||
|
BSTR bstr;
|
||||||
|
VALUE retval;
|
||||||
|
HRESULT hr = S_OK;
|
||||||
|
|
||||||
len = RARRAY(args)->len;
|
len = RARRAY(args)->len;
|
||||||
if (len < 1 || len > 3) {
|
if (len < 1 || len > 3) {
|
||||||
|
@ -4293,6 +4308,22 @@ foletypelib_initialize(self, args)
|
||||||
if (found == Qfalse) {
|
if (found == Qfalse) {
|
||||||
found = oletypelib_search_registry2(self, args);
|
found = oletypelib_search_registry2(self, args);
|
||||||
}
|
}
|
||||||
|
if (found == Qfalse) {
|
||||||
|
pbuf = ole_mb2wc(StringValuePtr(typelib), -1);
|
||||||
|
hr = LoadTypeLibEx(pbuf, REGKIND_NONE, &pTypeLib);
|
||||||
|
SysFreeString(pbuf);
|
||||||
|
if (SUCCEEDED(hr)) {
|
||||||
|
retval = ole_typelib_from_itypelib(pTypeLib);
|
||||||
|
OLE_RELEASE(pTypeLib);
|
||||||
|
if (retval != Qnil) {
|
||||||
|
found = Qtrue;
|
||||||
|
oletypelib_set_member(self,
|
||||||
|
rb_ivar_get(retval, rb_intern("name")),
|
||||||
|
rb_ivar_get(retval, rb_intern("guid")),
|
||||||
|
rb_ivar_get(retval, rb_intern("version")));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
if (found == Qfalse) {
|
if (found == Qfalse) {
|
||||||
rb_raise(eWIN32OLE_RUNTIME_ERROR, "not found type library `%s`",
|
rb_raise(eWIN32OLE_RUNTIME_ERROR, "not found type library `%s`",
|
||||||
|
|
|
@ -33,6 +33,10 @@ if defined?(WIN32OLE_TYPELIB)
|
||||||
assert_instance_of(WIN32OLE_TYPELIB, tlib_by_guid)
|
assert_instance_of(WIN32OLE_TYPELIB, tlib_by_guid)
|
||||||
assert_equal("Microsoft Shell Controls And Automation" , tlib_by_guid.name)
|
assert_equal("Microsoft Shell Controls And Automation" , tlib_by_guid.name)
|
||||||
|
|
||||||
|
path = tlib.path
|
||||||
|
tlib_by_path = WIN32OLE_TYPELIB.new(path)
|
||||||
|
assert_equal("Microsoft Shell Controls And Automation" , tlib_by_path.name)
|
||||||
|
|
||||||
assert_raise(WIN32OLERuntimeError) {
|
assert_raise(WIN32OLERuntimeError) {
|
||||||
WIN32OLE_TYPELIB.new("Non Exist Type Library")
|
WIN32OLE_TYPELIB.new("Non Exist Type Library")
|
||||||
}
|
}
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue