diff --git a/vnr/texthook/host/CMakeLists.txt b/vnr/texthook/host/CMakeLists.txt index 1f6e558..7d71487 100644 --- a/vnr/texthook/host/CMakeLists.txt +++ b/vnr/texthook/host/CMakeLists.txt @@ -41,7 +41,7 @@ target_compile_options(vnrhost PRIVATE #STRING(REPLACE "/EHsc" "" CMAKE_CXX_FLAGS ${CMAKE_CXX_FLAGS}) target_link_libraries(vnrhost - ithsys + #ithsys profile ${WDK_HOME}/lib/wxp/i386/ntdll.lib ) diff --git a/vnr/texthook/host/host.cc b/vnr/texthook/host/host.cc index b663356..b64d101 100644 --- a/vnr/texthook/host/host.cc +++ b/vnr/texthook/host/host.cc @@ -38,7 +38,7 @@ Settings *settings; HWND dummyWindow; BOOL running; -#define ITH_SYNC_HOOK IthMutexLocker locker(::hookMutex) +#define ITH_SYNC_HOOK MutexLocker locker(::hookMutex) namespace { // unnamed @@ -64,11 +64,10 @@ BOOL WINAPI DllMain(HINSTANCE hinstDLL, DWORD fdwReason, LPVOID unused) case DLL_PROCESS_ATTACH: DisableThreadLibraryCalls(hinstDLL); InitializeCriticalSection(&::hostCs); - IthInitSystemService(); GetDebugPrivileges(); // jichi 12/20/2013: Since I already have a GUI, I don't have to InitCommonControls() // Used by timers. - InitCommonControls(); + // InitCommonControls(); // jichi 8/24/2013: Create hidden window so that ITH can access timer and events dummyWindow = CreateWindowW(L"Button", L"InternalWindow", 0, 0, 0, 0, 0, 0, 0, hinstDLL, 0); break; @@ -76,7 +75,6 @@ BOOL WINAPI DllMain(HINSTANCE hinstDLL, DWORD fdwReason, LPVOID unused) if (::running) CloseHost(); DeleteCriticalSection(&::hostCs); - IthCloseSystemService(); DestroyWindow(dummyWindow); break; default: diff --git a/vnr/texthook/host/textthread.cc b/vnr/texthook/host/textthread.cc index c8db23b..4a930c0 100644 --- a/vnr/texthook/host/textthread.cc +++ b/vnr/texthook/host/textthread.cc @@ -201,13 +201,15 @@ void DispatchSentence(void* str,DWORD status, int len) memcpy(sentenceBuffer,str,len); *(WORD*)(sentenceBuffer+len)=0; HGLOBAL hCopy; - wchar_t copy[0x200]; + wchar_t copy[0x400]; if (status&USING_UNICODE) { memcpy(copy, sentenceBuffer, len + 2); } else - copy[MB_WC(sentenceBuffer, copy)] = 0; + { + MultiByteToWideChar(932, 0, sentenceBuffer, -1, copy, 0x400); + } DispatchSentenceToExtensions(copy, status); } } diff --git a/vnr/winmutex/winmutex.h b/vnr/winmutex/winmutex.h index 2e6d4cf..1009f41 100644 --- a/vnr/winmutex/winmutex.h +++ b/vnr/winmutex/winmutex.h @@ -79,88 +79,15 @@ template <> bool try_lock() { return ::TryEnterCriticalSection(&_M_mutex); } }; -// Conditional variable - -template - class win_mutex_cond + class MutexLocker { - typedef win_mutex_cond<_Cond> _Self; - typedef _Cond __native_type; - win_mutex_cond(const _Self&); - _Self &operator=(const _Self&); - - __native_type _M_cond; + HANDLE m; public: - enum wait_status { no_timeout = 0, timeout }; - typedef __native_type *native_handle_type; - - win_mutex_cond() {} - native_handle_type native_handle() { return &_M_cond; } - - void notify_one() {} - void notify_all() {} - - template - void wait(_Mutex &mutex) {} - - template - void wait(_Mutex &mutex, _Pred pred) {} - - template - wait_status wait_for(_Mutex &mutex, int msecs) {} - - template - wait_status wait_for(_Mutex &mutex, int msecs, _Pred pred) {} - }; - -// Note: Conditional variables are NOT availabe on Windows XP/2003 -// See: http://en.cppreference.com/w/cpp/thread/condition_variable -// See: http://msdn.microsoft.com/en-us/library/windows/desktop/ms686903%28v=vs.85%29.aspx -template <> - class win_mutex_cond - { - typedef win_mutex_cond _Self; - typedef CONDITION_VARIABLE __native_type; - win_mutex_cond(const _Self&); - _Self &operator=(const _Self&); - - __native_type _M_cond; - public: - enum wait_status { no_timeout = 0, timeout }; - typedef __native_type *native_handle_type; - native_handle_type native_handle() { return &_M_cond; } - - win_mutex_cond() { ::InitializeConditionVariable(&_M_cond); } - - void notify_one() { ::WakeConditionVariable(&_M_cond); } - void notify_all() { ::WakeAllConditionVariable(&_M_cond); } - - template - void wait(_Mutex &mutex) - { ::SleepConditionVariableCS(&_M_cond, mutex.native_handle(), INFINITE); } - - template - void wait(_Mutex &mutex, _Pred pred) - { while (!pred()) wait(mutex); } - - template - wait_status wait_for(_Mutex &mutex, int msecs) - { return ::SleepConditionVariableCS(&_M_cond, mutex.native_handle(), msecs) ? no_timeout : timeout; } - - template - wait_status wait_for(_Mutex &mutex, int msecs, _Pred pred) - { - auto start = ::GetTickCount(); - while (!pred()) { - auto now = ::GetTickCount(); - msecs -= now - start; - if (msecs <= 0) - return timeout; - start = now; - wait_for(mutex, msecs); - } - return no_timeout; - } + explicit MutexLocker(HANDLE mutex) : m(mutex) + { + WaitForSingleObject(m, 0); + } + ~MutexLocker() { if (m != INVALID_HANDLE_VALUE && m != nullptr) ReleaseMutex(m); } }; // EOF