summaryrefslogtreecommitdiff
path: root/ext/win32ole
diff options
context:
space:
mode:
authorsuke <suke@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2010-01-23 11:02:17 +0000
committersuke <suke@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2010-01-23 11:02:17 +0000
commit4b18062808a3731e5ffabb82e0b5dcbe207d5672 (patch)
tree4dd60c302dd1c740af461a505e4be684378afffa /ext/win32ole
parent0f29696f9d38642962766ecee2c2f9008675e7dd (diff)
* ext/win32ole/win32ole.c: add WIN32OLE.ole_initialize,
WIN32OLE.ole_uninitialize to use in win32ole.rb. You must not use thease methods. * ext/win32ole/lib/win32ole.rb: add win32ole.rb re-define Thread#initialize (fix ruby-core:27634) git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@26383 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
Diffstat (limited to 'ext/win32ole')
-rw-r--r--ext/win32ole/lib/win32ole.rb22
-rw-r--r--ext/win32ole/win32ole.c44
2 files changed, 65 insertions, 1 deletions
diff --git a/ext/win32ole/lib/win32ole.rb b/ext/win32ole/lib/win32ole.rb
new file mode 100644
index 0000000..aaf7e7c
--- /dev/null
+++ b/ext/win32ole/lib/win32ole.rb
@@ -0,0 +1,22 @@
+require 'win32ole.so'
+
+# re-define Thread#initialize
+# bug #2618(ruby-core:27634)
+
+class Thread
+ alias :org_initialize :initialize
+ def initialize(*arg, &block)
+ if block
+ org_initialize(*arg) {
+ WIN32OLE.ole_initialize
+ begin
+ block.call(*arg)
+ ensure
+ WIN32OLE.ole_uninitialize
+ end
+ }
+ else
+ org_initialize(*arg)
+ end
+ end
+end
diff --git a/ext/win32ole/win32ole.c b/ext/win32ole/win32ole.c
index 77b6644..3fff8ba 100644
--- a/ext/win32ole/win32ole.c
+++ b/ext/win32ole/win32ole.c
@@ -130,7 +130,7 @@ const IID IID_IMultiLanguage2 = {0xDCCFC164, 0x2B38, 0x11d2, {0xB7, 0xEC, 0x00,
#define WC2VSTR(x) ole_wc2vstr((x), TRUE)
-#define WIN32OLE_VERSION "1.4.6"
+#define WIN32OLE_VERSION "1.4.7"
typedef HRESULT (STDAPICALLTYPE FNCOCREATEINSTANCEEX)
(REFCLSID, IUnknown*, DWORD, COSERVERINFO*, DWORD, MULTI_QI*);
@@ -357,6 +357,10 @@ static BOOL CALLBACK installed_lcid_proc(LPTSTR str);
static BOOL lcid_installed(LCID lcid);
static VALUE fole_s_set_locale(VALUE self, VALUE vlcid);
static VALUE fole_s_create_guid(VALUE self);
+static void ole_pure_initialize();
+static VALUE fole_s_ole_initialize(VALUE self);
+static void ole_pure_uninitialize();
+static VALUE fole_s_ole_uninitialize(VALUE self);
static VALUE fole_initialize(int argc, VALUE *argv, VALUE self);
static VALUE hash2named_arg(VALUE pair, struct oleparam* pOp);
static VALUE set_argv(VARIANTARG* realargs, unsigned int beg, unsigned int end);
@@ -3092,6 +3096,42 @@ fole_s_create_guid(VALUE self)
}
/*
+ * WIN32OLE.ole_initialize and WIN32OLE.ole_uninitialize
+ * are used in win32ole.rb to fix the issue bug #2618 (ruby-core:27634).
+ * You must not use thease method.
+ */
+
+static void ole_pure_initialize()
+{
+ HRESULT hr;
+ hr = OleInitialize(NULL);
+ if(FAILED(hr)) {
+ ole_raise(hr, rb_eRuntimeError, "fail: OLE initialize");
+ }
+}
+
+static void ole_pure_uninitialize()
+{
+ OleUninitialize();
+}
+
+/* :nodoc */
+static VALUE
+fole_s_ole_initialize(VALUE self)
+{
+ ole_pure_initialize();
+ return Qnil;
+}
+
+/* :nodoc */
+static VALUE
+fole_s_ole_uninitialize(VALUE self)
+{
+ ole_pure_uninitialize();
+ return Qnil;
+}
+
+/*
* Document-class: WIN32OLE
*
* <code>WIN32OLE</code> objects represent OLE Automation object in Ruby.
@@ -9043,6 +9083,8 @@ Init_win32ole()
rb_define_singleton_method(cWIN32OLE, "locale", fole_s_get_locale, 0);
rb_define_singleton_method(cWIN32OLE, "locale=", fole_s_set_locale, 1);
rb_define_singleton_method(cWIN32OLE, "create_guid", fole_s_create_guid, 0);
+ rb_define_singleton_method(cWIN32OLE, "ole_initialize", fole_s_ole_initialize, 0);
+ rb_define_singleton_method(cWIN32OLE, "ole_uninitialize", fole_s_ole_uninitialize, 0);
rb_define_method(cWIN32OLE, "invoke", fole_invoke, -1);
rb_define_method(cWIN32OLE, "[]", fole_getproperty_with_bracket, -1);