[前][次][番号順一覧][スレッド一覧]

ruby-changes:6440

From: suke <ko1@a...>
Date: Tue, 8 Jul 2008 20:13:27 +0900 (JST)
Subject: [ruby-changes:6440] Ruby:r17956 (trunk): * ext/win32ole/win32ole.c (find_default_source): try to

suke	2008-07-08 20:13:09 +0900 (Tue, 08 Jul 2008)

  New Revision: 17956

  http://svn.ruby-lang.org/cgi-bin/viewvc.cgi?view=rev&revision=17956

  Log:
    * ext/win32ole/win32ole.c (find_default_source): try to
      find COCLASS when WIN32OLE object is not COCLASS. 
    
    * test/win32ole/test_win32ole_event.rb: ditto

  Modified files:
    trunk/ChangeLog
    trunk/ext/win32ole/win32ole.c
    trunk/test/win32ole/test_win32ole_event.rb

Index: ChangeLog
===================================================================
--- ChangeLog	(revision 17955)
+++ ChangeLog	(revision 17956)
@@ -1,3 +1,10 @@
+Tue Jul  8 19:55:40 2008  Masaki Suketa  <masaki.suketa@n...>
+
+	* ext/win32ole/win32ole.c (find_default_source): try to
+	  find COCLASS when WIN32OLE object is not COCLASS. 
+
+	* test/win32ole/test_win32ole_event.rb: ditto
+
 Tue Jul  8 13:44:01 2008  Koichi Sasada  <ko1@a...>
 
 	* lib/debug.rb, lib/profile.rb: fix to use RubyVM.
Index: ext/win32ole/win32ole.c
===================================================================
--- ext/win32ole/win32ole.c	(revision 17955)
+++ ext/win32ole/win32ole.c	(revision 17956)
@@ -118,7 +118,7 @@
 
 #define WC2VSTR(x) ole_wc2vstr((x), TRUE)
 
-#define WIN32OLE_VERSION "1.2.1"
+#define WIN32OLE_VERSION "1.2.2"
 
 typedef HRESULT (STDAPICALLTYPE FNCOCREATEINSTANCEEX)
     (REFCLSID, IUnknown*, DWORD, COSERVERINFO*, DWORD, MULTI_QI*);
@@ -7606,10 +7606,18 @@
 
     IDispatch *pDispatch;
     ITypeInfo *pTypeInfo;
+    ITypeInfo *pTypeInfo2;
+    ITypeInfo *pRefTypeInfo;
+    ITypeLib  *pTypeLib;
     TYPEATTR *pTypeAttr;
-    int i;
+    TYPEATTR *pTypeAttr2;
+    TYPEATTR *pRefTypeAttr;
+    int i, j;
     int iFlags;
-    HREFTYPE hRefType;
+    int flags;
+    HREFTYPE hRefType, href;
+    int count;
+    BOOL found = FALSE;
 
     struct oledata *pole;
 
@@ -7649,6 +7657,73 @@
         OLE_RELEASE(pTypeInfo);
         return hr;
     }
+
+    /*
+     *  if the ole is not COCLASS, then try to find COCLASS which
+     *  has ole as [default] interface.
+     */
+    if (pTypeAttr->typekind != TKIND_COCLASS) {
+        /* 
+         * search coclass
+         */
+        hr = pTypeInfo->lpVtbl->GetContainingTypeLib(pTypeInfo, &pTypeLib, NULL);
+        if (FAILED(hr)) {
+            OLE_RELEASE_TYPEATTR(pTypeInfo, pTypeAttr);
+            OLE_RELEASE(pTypeInfo);
+            return hr;
+        }
+        count = pTypeLib->lpVtbl->GetTypeInfoCount(pTypeLib);
+
+        for (i = 0; i < count && !found; i++) {
+             hr = pTypeLib->lpVtbl->GetTypeInfo(pTypeLib, i, &pTypeInfo2);
+             if (FAILED(hr))
+                 continue;
+             hr = OLE_GET_TYPEATTR(pTypeInfo2, &pTypeAttr2);
+             if (FAILED(hr)) {
+                 OLE_RELEASE(pTypeInfo2);
+                 continue;
+             }
+             if (pTypeAttr2->typekind != TKIND_COCLASS) {
+                 OLE_RELEASE_TYPEATTR(pTypeInfo2, pTypeAttr2);
+                 OLE_RELEASE(pTypeInfo2);
+                 continue;
+             }
+             for (j = 0; j < pTypeAttr2->cImplTypes && !found; j++) {
+                 hr = pTypeInfo2->lpVtbl->GetImplTypeFlags(pTypeInfo2, j, &flags);
+                 if (FAILED(hr))
+                     continue;
+                 if (!(flags & IMPLTYPEFLAG_FDEFAULT)) 
+                     continue;
+                 hr = pTypeInfo2->lpVtbl->GetRefTypeOfImplType(pTypeInfo2, j, &href);
+                 if (FAILED(hr))
+                     continue;
+                 hr = pTypeInfo2->lpVtbl->GetRefTypeInfo(pTypeInfo2, href, &pRefTypeInfo);
+                 if (FAILED(hr)) 
+                     continue;
+                 hr = OLE_GET_TYPEATTR(pRefTypeInfo, &pRefTypeAttr);
+                 if (FAILED(hr))  {
+                     OLE_RELEASE(pRefTypeInfo);
+                     continue;
+                 }
+                 if (IsEqualGUID(&(pTypeAttr->guid), &(pRefTypeAttr->guid))) {
+                     found = TRUE;
+                 }
+                 OLE_RELEASE_TYPEATTR(pRefTypeInfo, pRefTypeAttr);
+                 OLE_RELEASE(pRefTypeInfo);
+             }
+             if (!found) {
+                 OLE_RELEASE_TYPEATTR(pTypeInfo2, pTypeAttr2);
+                 OLE_RELEASE(pTypeInfo2);
+             }
+        }
+        if (found) {
+            OLE_RELEASE_TYPEATTR(pTypeInfo, pTypeAttr);
+            OLE_RELEASE(pTypeInfo);
+            pTypeInfo = pTypeInfo2;
+            pTypeAttr = pTypeAttr2;
+        }
+    }
+
     /* Enumerate all implemented types of the COCLASS */
     for (i = 0; i < pTypeAttr->cImplTypes; i++) {
         hr = pTypeInfo->lpVtbl->GetImplTypeFlags(pTypeInfo, i, &iFlags);
Index: test/win32ole/test_win32ole_event.rb
===================================================================
--- test/win32ole/test_win32ole_event.rb	(revision 17955)
+++ test/win32ole/test_win32ole_event.rb	(revision 17956)
@@ -30,6 +30,20 @@
       @event += event
     end
 
+    def test_s_new_without_itf
+      ev = WIN32OLE_EVENT.new(@ie)
+      ev.on_event {|*args| default_handler(*args)}
+      @ie.navigate("file:///#{@f}")
+      while @ie.busy
+        WIN32OLE_EVENT.new(@ie)
+        GC.start  
+        WIN32OLE_EVENT.message_loop
+        sleep 0.1
+      end
+      assert_match(/BeforeNavigate/, @event)
+      assert_match(/NavigateComplete/, @event)
+    end
+
     def test_on_event
       ev = WIN32OLE_EVENT.new(@ie, 'DWebBrowserEvents')
       ev.on_event {|*args| default_handler(*args)}

--
ML: ruby-changes@q...
Info: http://www.atdot.net/~ko1/quickml/

[前][次][番号順一覧][スレッド一覧]