--- 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; @@ -817,16 +818,22 @@ ole_initialize(void) } if(g_ole_initialized == FALSE) { - hr = OleInitialize(NULL); + if(g_running_nano == TRUE) { + hr = CoInitializeEx(NULL, COINIT_MULTITHREADED); + } else { + 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"); + } } } } @@ -3890,10 +3897,29 @@ com_hash_size(const void *ptr) } 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;