ruby-changes:6369
From: suke <ko1@a...>
Date: Sat, 5 Jul 2008 10:01:16 +0900 (JST)
Subject: [ruby-changes:6369] Ruby:r17885 (trunk): * ext/win32ole/win32ole.c: add WIN32OLE#ole_respond_to?
suke 2008-07-05 10:01:01 +0900 (Sat, 05 Jul 2008) New Revision: 17885 Modified files: trunk/ChangeLog trunk/ext/win32ole/win32ole.c trunk/test/win32ole/test_win32ole.rb Log: * ext/win32ole/win32ole.c: add WIN32OLE#ole_respond_to? * test/win32ole/test_win32ole.rb: ditto. http://svn.ruby-lang.org/cgi-bin/viewvc.cgi?view=rev&revision=17885 Index: ChangeLog =================================================================== --- ChangeLog (revision 17884) +++ ChangeLog (revision 17885) @@ -1,3 +1,9 @@ +Sat Jul 5 09:55:44 2008 Masaki Suketa <masaki.suketa@n...> + + * ext/win32ole/win32ole.c: add WIN32OLE#ole_respond_to? + + * test/win32ole/test_win32ole.rb: ditto. + Sat Jul 5 08:48:05 2008 Tanaka Akira <akr@f...> * re.c (unescape_nonascii): add has_property argument not to Index: ext/win32ole/win32ole.c =================================================================== --- ext/win32ole/win32ole.c (revision 17884) +++ ext/win32ole/win32ole.c (revision 17885) @@ -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_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 @@ 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 @@ 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()); Index: test/win32ole/test_win32ole.rb =================================================================== --- test/win32ole/test_win32ole.rb (revision 17884) +++ test/win32ole/test_win32ole.rb (revision 17885) @@ -246,6 +246,16 @@ assert_instance_of(WIN32OLE, shell2) end + def test_ole_respond_to + fso = WIN32OLE.new('Scripting.FileSystemObject') + assert(fso.ole_respond_to?('getFolder')) + assert(fso.ole_respond_to?('GETFOLDER')) + assert(!fso.ole_respond_to?('XXXXX')) + assert_raise(TypeError) { + assert_raise(fso.ole_respond_to?(1)) + } + end + def test_s_const_load assert(!defined?(CONST1::SsfWINDOWS)) shell=WIN32OLE.new('Shell.Application') -- ML: ruby-changes@q... Info: http://www.atdot.net/~ko1/quickml/