diff options
author | suke <suke@b2dd03c8-39d4-4d8f-98ff-823fe69b080e> | 2008-07-05 01:01:01 +0000 |
---|---|---|
committer | suke <suke@b2dd03c8-39d4-4d8f-98ff-823fe69b080e> | 2008-07-05 01:01:01 +0000 |
commit | 1890ae7aa957f75c7aeb64e4213c1a58c65b80d0 (patch) | |
tree | 591b617e616066028bd1ab2fdfe27c106200ae82 /ext | |
parent | 1a32af4e7a1527ebe6b4b1205c522fa9ebd56344 (diff) | |
download | ruby-1890ae7aa957f75c7aeb64e4213c1a58c65b80d0.tar.gz |
* ext/win32ole/win32ole.c: add WIN32OLE#ole_respond_to?
* test/win32ole/test_win32ole.rb: ditto.
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@17885 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
Diffstat (limited to 'ext')
-rw-r--r-- | ext/win32ole/win32ole.c | 30 |
1 files changed, 29 insertions, 1 deletions
diff --git a/ext/win32ole/win32ole.c b/ext/win32ole/win32ole.c index a972c8bc68..606c496b1c 100644 --- a/ext/win32ole/win32ole.c +++ b/ext/win32ole/win32ole.c @@ -118,7 +118,7 @@ #define WC2VSTR(x) ole_wc2vstr((x), TRUE) -#define WIN32OLE_VERSION "1.1.9" +#define WIN32OLE_VERSION "1.2.0" typedef HRESULT (STDAPICALLTYPE FNCOCREATEINSTANCEEX) (REFCLSID, IUnknown*, DWORD, COSERVERINFO*, DWORD, MULTI_QI*); @@ -368,6 +368,7 @@ static VALUE ole_typelib_from_itypelib(ITypeLib *pTypeLib); static VALUE ole_typelib_from_itypeinfo(ITypeInfo *pTypeInfo); static VALUE fole_typelib(VALUE self); static VALUE fole_query_interface(VALUE self, VALUE str_iid); +static VALUE fole_respond_to(VALUE self, VALUE method); static HRESULT ole_docinfo_from_type(ITypeInfo *pTypeInfo, BSTR *name, BSTR *helpstr, DWORD *helpcontext, BSTR *helpfile); static VALUE ole_usertype2val(ITypeInfo *pTypeInfo, TYPEDESC *pTypeDesc, VALUE typedetails); static VALUE ole_ptrtype2val(ITypeInfo *pTypeInfo, TYPEDESC *pTypeDesc, VALUE typedetails); @@ -4374,6 +4375,32 @@ fole_query_interface(VALUE self, VALUE str_iid) return create_win32ole_object(cWIN32OLE, pDispatch, 0, 0); } +/* + * call-seq: + * WIN32OLE#ole_respond_to?(method) -> true or false + * + * Returns true when OLE object has OLE method, otherwise returns false. + * + * ie = WIN32OLE.new('InternetExplorer.Application') + * ie.ole_respond_to?("gohome") => true + */ +static VALUE +fole_respond_to(VALUE self, VALUE method) +{ + struct oledata *pole; + BSTR wcmdname; + DISPID DispID; + HRESULT hr; + rb_secure(4); + Check_SafeStr(method); + OLEData_Get_Struct(self, pole); + wcmdname = ole_vstr2wc(method); + hr = pole->pDispatch->lpVtbl->GetIDsOfNames( pole->pDispatch, &IID_NULL, + &wcmdname, 1, cWIN32OLE_lcid, &DispID); + SysFreeString(wcmdname); + return SUCCEEDED(hr) ? Qtrue : Qfalse; +} + static HRESULT ole_docinfo_from_type(ITypeInfo *pTypeInfo, BSTR *name, BSTR *helpstr, DWORD *helpcontext, BSTR *helpfile) { @@ -8331,6 +8358,7 @@ Init_win32ole() rb_define_alias(cWIN32OLE, "ole_obj_help", "ole_type"); rb_define_method(cWIN32OLE, "ole_typelib", fole_typelib, 0); rb_define_method(cWIN32OLE, "ole_query_interface", fole_query_interface, 1); + rb_define_method(cWIN32OLE, "ole_respond_to?", fole_respond_to, 1); rb_define_const(cWIN32OLE, "VERSION", rb_str_new2(WIN32OLE_VERSION)); rb_define_const(cWIN32OLE, "ARGV", rb_ary_new()); |