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

ruby-changes:1750

From: ko1@a...
Date: 23 Aug 2007 20:14:16 +0900
Subject: [ruby-changes:1750] suke - Ruby:r13241 (trunk): * ext/win32ole/win32ole.c (reg_get_value): use RegQueryValueEx instead

suke	2007-08-23 20:14:03 +0900 (Thu, 23 Aug 2007)

  New Revision: 13241

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

  Log:
    * ext/win32ole/win32ole.c (reg_get_value): use RegQueryValueEx instead
      of RegQueryValueEx.
    
    * ext/win32ole/win32ole.c (typelib_file_from_clsid): fix the bug
      that the function always returns Qnil.
    
    * test/win32ole/test_win32ole_type.rb (test_initialize): add some test.
    


  http://svn.ruby-lang.org/cgi-bin/viewvc.cgi/trunk/test/win32ole/test_win32ole_type.rb?r1=13241&r2=13240
  http://svn.ruby-lang.org/cgi-bin/viewvc.cgi/trunk/ChangeLog?r1=13241&r2=13240
  http://svn.ruby-lang.org/cgi-bin/viewvc.cgi/trunk/ext/win32ole/win32ole.c?r1=13241&r2=13240

Index: ChangeLog
===================================================================
--- ChangeLog	(revision 13240)
+++ ChangeLog	(revision 13241)
@@ -1,3 +1,13 @@
+Thu Aug 23 20:02:25 2007  Masaki Suketa  <masaki.suketa@n...>
+
+	* ext/win32ole/win32ole.c (reg_get_value): use RegQueryValueEx instead
+	  of RegQueryValueEx.
+
+	* ext/win32ole/win32ole.c (typelib_file_from_clsid): fix the bug
+	  that the function always returns Qnil.
+
+	* test/win32ole/test_win32ole_type.rb (test_initialize): add some test.
+
 Thu Aug 23 17:25:05 2007  Nobuyoshi Nakada  <nobu@r...>
 
 	* configure.in (group_member): check if presents.
Index: ext/win32ole/win32ole.c
===================================================================
--- ext/win32ole/win32ole.c	(revision 13240)
+++ ext/win32ole/win32ole.c	(revision 13241)
@@ -116,7 +116,7 @@
 
 #define WC2VSTR(x) ole_wc2vstr((x), TRUE)
 
-#define WIN32OLE_VERSION "1.0.2"
+#define WIN32OLE_VERSION "1.0.3"
 
 typedef HRESULT (STDAPICALLTYPE FNCOCREATEINSTANCEEX)
     (REFCLSID, IUnknown*, DWORD, COSERVERINFO*, DWORD, MULTI_QI*);
@@ -1929,22 +1929,48 @@
 static VALUE
 reg_get_val(HKEY hkey, const char *subkey)
 {
-    char buf[BUFSIZ];
-    LONG size_buf = sizeof(buf);
-    LONG err = RegQueryValue(hkey, subkey, buf, &size_buf);
+    char *pbuf;
+    DWORD dwtype = 0;
+    LONG size = 0;
+    VALUE val = Qnil;
+    LONG err = RegQueryValueEx(hkey, subkey, NULL, &dwtype, NULL, &size); 
+
     if (err == ERROR_SUCCESS) {
-        return rb_str_new2(buf);
+        pbuf = ALLOC_N(char, size + 1);
+        err = RegQueryValueEx(hkey, subkey, NULL, &dwtype, pbuf, &size);
+        if (err == ERROR_SUCCESS) {
+            pbuf[size] = '\0';
+            val = rb_str_new2(pbuf);
+        }
+        free(pbuf);
     }
-    return Qnil;
+    return val;
 }
 
 static VALUE
+reg_get_val2(HKEY hkey, const char *subkey)
+{
+    HKEY hsubkey;
+    LONG err;
+    VALUE val = Qnil;
+    err = RegOpenKeyEx(hkey, subkey, 0, KEY_READ, &hsubkey);
+    if (err == ERROR_SUCCESS) {
+        val = reg_get_val(hsubkey, NULL);
+        RegCloseKey(hsubkey);
+    }
+    if (val == Qnil) {
+        val = reg_get_val(hkey, subkey);
+    }
+    return val;
+}
+
+static VALUE
 reg_get_typelib_file_path(HKEY hkey)
 {
     VALUE path = Qnil;
-    path = reg_get_val(hkey, "win32");
+    path = reg_get_val2(hkey, "win32");
     if (path == Qnil) {
-        path = reg_get_val(hkey, "win16");
+        path = reg_get_val2(hkey, "win16");
     }
     return path;
 }
@@ -1952,34 +1978,28 @@
 static VALUE
 typelib_file_from_clsid(VALUE ole)
 {
-    OLECHAR *pbuf;
-    CLSID clsid;
-    HRESULT hr;
     HKEY hroot, hclsid;
     LONG err;
     VALUE typelib;
-    VALUE vclsid;
+    char path[MAX_PATH + 1];
 
-    pbuf  = ole_mb2wc(StringValuePtr(ole), -1);
-    hr = CLSIDFromProgID(pbuf, &clsid);
-    SysFreeString(pbuf);
-    if (FAILED(hr)) {
-        return Qnil;
-    }
-    StringFromCLSID(&clsid, &pbuf);
-    vclsid = WC2VSTR(pbuf);
     err = reg_open_key(HKEY_CLASSES_ROOT, "CLSID", &hroot);
     if (err != ERROR_SUCCESS) {
         return Qnil;
     }
-    err = reg_open_key(hroot, StringValuePtr(vclsid), &hclsid);
+    err = reg_open_key(hroot, StringValuePtr(ole), &hclsid);
     if (err != ERROR_SUCCESS) {
         RegCloseKey(hroot);
         return Qnil;
     }
-    typelib = reg_get_val(hclsid, "InprocServer32");
+    typelib = reg_get_val2(hclsid, "InprocServer32");
     RegCloseKey(hroot);
     RegCloseKey(hclsid);
+    if (typelib != Qnil) {
+        ExpandEnvironmentStrings(StringValuePtr(typelib), path, sizeof(path));
+        path[MAX_PATH] = '\0';
+        typelib = rb_str_new2(path);
+    }
     return typelib;
 }
 
@@ -4428,9 +4448,9 @@
         err = reg_open_vkey(hclsids, clsid, &hclsid);
         if (err != ERROR_SUCCESS)
             continue;
-        if ((v = reg_get_val(hclsid, "ProgID")) != Qnil) 
+        if ((v = reg_get_val2(hclsid, "ProgID")) != Qnil) 
             rb_ary_push(progids, v);
-        if ((v = reg_get_val(hclsid, "VersionIndependentProgID")) != Qnil)
+        if ((v = reg_get_val2(hclsid, "VersionIndependentProgID")) != Qnil)
             rb_ary_push(progids, v);
         RegCloseKey(hclsid);
     }
@@ -4545,7 +4565,7 @@
             version = reg_enum_key(hguid, j);
             if (version == Qnil)
                 break;
-            if ( (name = reg_get_val(hguid, StringValuePtr(version))) != Qnil ) {
+            if ( (name = reg_get_val2(hguid, StringValuePtr(version))) != Qnil ) {
                 typelib = rb_funcall(cWIN32OLE_TYPELIB, rb_intern("allocate"), 0);
                 oletypelib_set_member(typelib, name, guid, version);
                 rb_ary_push(typelibs, typelib);
Index: test/win32ole/test_win32ole_type.rb
===================================================================
--- test/win32ole/test_win32ole_type.rb	(revision 13240)
+++ test/win32ole/test_win32ole_type.rb	(revision 13241)
@@ -30,6 +30,31 @@
       }
       ole_type = WIN32OLE_TYPE.new("Microsoft Shell Controls And Automation", "Shell")
       assert_instance_of(WIN32OLE_TYPE, ole_type)
+
+      ole_type2 = WIN32OLE_TYPE.new("{13709620-C279-11CE-A49E-444553540000}", "Shell")
+      assert_instance_of(WIN32OLE_TYPE, ole_type)
+      assert_equal(ole_type.name, ole_type2.name)
+      assert_equal(ole_type.ole_type, ole_type2.ole_type)
+      assert_equal(ole_type.guid, ole_type2.guid)
+      assert_equal(ole_type.progid, ole_type2.progid)
+      assert_equal(ole_type.name, ole_type2.name)
+      assert_equal(ole_type.ole_type, ole_type2.ole_type)
+      assert_equal(ole_type.guid, ole_type2.guid)
+      assert_equal(ole_type.progid, ole_type2.progid)
+      assert_equal(ole_type.visible?, ole_type2.visible?)
+      assert_equal(ole_type.to_s, ole_type2.to_s)
+      assert_equal(ole_type.major_version, ole_type2.major_version)
+      assert_equal(ole_type.minor_version, ole_type2.minor_version)
+      assert_equal(ole_type.typekind, ole_type2.typekind)
+      assert_equal(ole_type.helpstring, ole_type2.helpstring)
+      assert_equal(ole_type.src_type, ole_type2.src_type)
+      assert_equal(ole_type.helpfile, ole_type2.helpfile)
+      assert_equal(ole_type.helpcontext, ole_type2.helpcontext)
+      assert_equal(ole_type.variables.size, ole_type2.variables.size)
+      assert_equal(ole_type.ole_methods[0].name, ole_type2.ole_methods[0].name)
+      assert_equal(ole_type.ole_typelib.name, ole_type2.ole_typelib.name)
+      assert_equal(ole_type.implemented_ole_types.size, ole_type2.implemented_ole_types.size)
+      assert_equal(ole_type.inspect, ole_type2.inspect)
     end
 
     def setup

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

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