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

ruby-changes:45643

From: suke <ko1@a...>
Date: Sun, 26 Feb 2017 07:28:46 +0900 (JST)
Subject: [ruby-changes:45643] suke:r57715 (trunk): ext/win32ole/win32ole.c(ole_initialize): avoid to fail in Windows nano server.

suke	2017-02-26 07:28:22 +0900 (Sun, 26 Feb 2017)

  New Revision: 57715

  https://svn.ruby-lang.org/cgi-bin/viewvc.cgi?view=revision&revision=57715

  Log:
    ext/win32ole/win32ole.c(ole_initialize): avoid to fail in Windows nano server. 
    This is experimental. Thanks to mwrock, Ethan Brown.

  Modified files:
    trunk/ext/win32ole/win32ole.c
Index: ext/win32ole/win32ole.c
===================================================================
--- ext/win32ole/win32ole.c	(revision 57714)
+++ ext/win32ole/win32ole.c	(revision 57715)
@@ -50,6 +50,7 @@ static volatile DWORD g_ole_initialized_ https://github.com/ruby/ruby/blob/trunk/ext/win32ole/win32ole.c#L50
 static BOOL g_uninitialize_hooked = FALSE;
 static BOOL g_cp_installed = FALSE;
 static BOOL g_lcid_installed = FALSE;
+static BOOL g_running_nano = FALSE;
 static HINSTANCE ghhctrl = NULL;
 static HINSTANCE gole32 = NULL;
 static FNCOCREATEINSTANCEEX *gCoCreateInstanceEx = NULL;
@@ -169,6 +170,7 @@ static VALUE fole_activex_initialize(VAL https://github.com/ruby/ruby/blob/trunk/ext/win32ole/win32ole.c#L170
 static void com_hash_free(void *ptr);
 static void com_hash_mark(void *ptr);
 static size_t com_hash_size(const void *ptr);
+static void check_nano_server(void);
 
 static const rb_data_type_t ole_datatype = {
     "win32ole",
@@ -817,16 +819,23 @@ ole_initialize(void) https://github.com/ruby/ruby/blob/trunk/ext/win32ole/win32ole.c#L819
     }
 
     if(g_ole_initialized == FALSE) {
+        if(g_running_nano) {
+            hr = CoInitializeEx(NULL, COINIT_MULTITHREADED);
+        } else {
+            hr = OleInitialize(NULL);
+        }
         hr = OleInitialize(NULL);
         if(FAILED(hr)) {
             ole_raise(hr, rb_eRuntimeError, "fail: OLE initialize");
         }
         g_ole_initialized_set(TRUE);
 
-        hr = CoRegisterMessageFilter(&imessage_filter, &previous_filter);
-        if(FAILED(hr)) {
-            previous_filter = NULL;
-            ole_raise(hr, rb_eRuntimeError, "fail: install OLE MessageFilter");
+        if (g_running_nano == FALSE) {
+            hr = CoRegisterMessageFilter(&imessage_filter, &previous_filter);
+            if(FAILED(hr)) {
+                previous_filter = NULL;
+                ole_raise(hr, rb_eRuntimeError, "fail: install OLE MessageFilter");
+            }
         }
     }
 }
@@ -3891,11 +3900,31 @@ com_hash_size(const void *ptr) https://github.com/ruby/ruby/blob/trunk/ext/win32ole/win32ole.c#L3900
     return st_memsize(tbl);
 }
 
+static void
+check_nano_server(void)
+{
+    HKEY hsubkey;
+    LONG err;
+    const char * subkey = "SOFTWARE\\Microsoft\\Windows NT\\CurrentVersion\\Server\\ServerLevels";
+    const char * regval = "NanoServer";
+
+    err = RegOpenKeyEx(HKEY_LOCAL_MACHINE, subkey, 0, KEY_READ, &hsubkey);
+    if (err == ERROR_SUCCESS) {
+        err = RegQueryValueEx(hsubkey, regval, NULL, NULL, NULL, NULL);
+        if (err == ERROR_SUCCESS) {
+            g_running_nano = TRUE;
+        }
+        RegCloseKey(hsubkey);
+    }
+}
+
+
 void
 Init_win32ole(void)
 {
     cWIN32OLE_lcid = LOCALE_SYSTEM_DEFAULT;
     g_ole_initialized_init();
+    check_nano_server();
 
     com_vtbl.QueryInterface = QueryInterface;
     com_vtbl.AddRef = AddRef;

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

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