summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorsuke <suke@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2006-04-07 13:16:46 +0000
committersuke <suke@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2006-04-07 13:16:46 +0000
commit11974f3b6d06991e3b82fda99174c7e9719a4eb8 (patch)
tree060d8318cfa9929816576f2b2710667441a9e3cd
parent3b7c8b34889eb4333335e10d04f6e612953b1a09 (diff)
WIN32OLE_TYPELIB.new accepts OLE files.
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@10082 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
-rw-r--r--ChangeLog7
-rw-r--r--ext/win32ole/win32ole.c67
-rw-r--r--test/win32ole/test_win32ole_typelib.rb4
3 files changed, 60 insertions, 18 deletions
diff --git a/ChangeLog b/ChangeLog
index b905ceb474..0d4707f5bf 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -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>
* intern.h (rb_obj_instance_exec, rb_mod_module_exec): add declaration.
diff --git a/ext/win32ole/win32ole.c b/ext/win32ole/win32ole.c
index f19203ad2c..393eef6737 100644
--- a/ext/win32ole/win32ole.c
+++ b/ext/win32ole/win32ole.c
@@ -79,7 +79,7 @@
#define WC2VSTR(x) ole_wc2vstr((x), TRUE)
-#define WIN32OLE_VERSION "0.7.3"
+#define WIN32OLE_VERSION "0.7.4"
typedef HRESULT (STDAPICALLTYPE FNCOCREATEINSTANCEEX)
(REFCLSID, IUnknown*, DWORD, COSERVERINFO*, DWORD, MULTI_QI*);
@@ -3531,40 +3531,47 @@ make_oletypelib_obj(guid, major_version, minor_version)
}
static VALUE
-ole_typelib_from_itypeinfo(pTypeInfo)
- ITypeInfo *pTypeInfo;
-{
- HRESULT hr;
+ole_typelib_from_itypelib(pTypeLib)
ITypeLib *pTypeLib;
+{
TLIBATTR *pTLibAttr;
OLECHAR bstr[80];
- int len;
VALUE guid = Qnil;
VALUE major;
VALUE minor;
- unsigned int index;
-
- 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));
+ HRESULT hr = pTypeLib->lpVtbl->GetLibAttr(pTypeLib, &pTLibAttr);
+ int len = StringFromGUID2(&pTLibAttr->guid, bstr, sizeof(bstr)/sizeof(OLECHAR));
if (len > 3) {
guid = ole_wc2vstr(bstr, FALSE);
}
major = INT2NUM(pTLibAttr->wMajorVerNum);
minor = INT2NUM(pTLibAttr->wMinorVerNum);
pTypeLib->lpVtbl->ReleaseTLibAttr(pTypeLib, pTLibAttr);
- OLE_RELEASE(pTypeLib);
if (guid == Qnil) {
return Qnil;
}
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:
* WIN32OLE#ole_typelib -> The WIN32OLE_TYPELIB object
@@ -4254,7 +4261,8 @@ oletypelib_search_registry(self, typelib)
*
* 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 third argument is minor version.
* 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}')
* 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
@@ -4279,6 +4289,11 @@ foletypelib_initialize(self, args)
VALUE found = Qfalse;
VALUE typelib = Qnil;
int len = 0;
+ OLECHAR * pbuf;
+ ITypeLib *pTypeLib;
+ BSTR bstr;
+ VALUE retval;
+ HRESULT hr = S_OK;
len = RARRAY(args)->len;
if (len < 1 || len > 3) {
@@ -4293,6 +4308,22 @@ foletypelib_initialize(self, args)
if (found == Qfalse) {
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) {
rb_raise(eWIN32OLE_RUNTIME_ERROR, "not found type library `%s`",
diff --git a/test/win32ole/test_win32ole_typelib.rb b/test/win32ole/test_win32ole_typelib.rb
index 0ef805d959..f4ece8abe4 100644
--- a/test/win32ole/test_win32ole_typelib.rb
+++ b/test/win32ole/test_win32ole_typelib.rb
@@ -33,6 +33,10 @@ if defined?(WIN32OLE_TYPELIB)
assert_instance_of(WIN32OLE_TYPELIB, tlib_by_guid)
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) {
WIN32OLE_TYPELIB.new("Non Exist Type Library")
}