summaryrefslogtreecommitdiff
path: root/ext/win32ole
diff options
context:
space:
mode:
authorsuke <suke@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2017-02-25 22:28:22 +0000
committersuke <suke@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2017-02-25 22:28:22 +0000
commit8feb9779182bd4285f3881029fe850dac188c1ac (patch)
tree6d5b7eceafcc1e9c50f8999bfeb0e8ab300b22d7 /ext/win32ole
parent573222510251c3778d6b0c382daa6de8416bc095 (diff)
ext/win32ole/win32ole.c(ole_initialize): avoid to fail in Windows nano server.
This is experimental. Thanks to mwrock, Ethan Brown. git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@57715 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
Diffstat (limited to 'ext/win32ole')
-rw-r--r--ext/win32ole/win32ole.c37
1 files changed, 33 insertions, 4 deletions
diff --git a/ext/win32ole/win32ole.c b/ext/win32ole/win32ole.c
index 9518e2f..b05ace7 100644
--- a/ext/win32ole/win32ole.c
+++ b/ext/win32ole/win32ole.c
@@ -50,6 +50,7 @@ static volatile DWORD g_ole_initialized_key = TLS_OUT_OF_INDEXES;
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(VALUE self);
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)
}
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)
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;