forked from Public-Mirror/Textractor
remove dependency of ithsys on host
This commit is contained in:
parent
3ac79fb9c5
commit
30f95423f1
@ -41,7 +41,7 @@ target_compile_options(vnrhost PRIVATE
|
|||||||
#STRING(REPLACE "/EHsc" "" CMAKE_CXX_FLAGS ${CMAKE_CXX_FLAGS})
|
#STRING(REPLACE "/EHsc" "" CMAKE_CXX_FLAGS ${CMAKE_CXX_FLAGS})
|
||||||
|
|
||||||
target_link_libraries(vnrhost
|
target_link_libraries(vnrhost
|
||||||
ithsys
|
#ithsys
|
||||||
profile
|
profile
|
||||||
${WDK_HOME}/lib/wxp/i386/ntdll.lib
|
${WDK_HOME}/lib/wxp/i386/ntdll.lib
|
||||||
)
|
)
|
||||||
|
@ -38,7 +38,7 @@ Settings *settings;
|
|||||||
HWND dummyWindow;
|
HWND dummyWindow;
|
||||||
BOOL running;
|
BOOL running;
|
||||||
|
|
||||||
#define ITH_SYNC_HOOK IthMutexLocker locker(::hookMutex)
|
#define ITH_SYNC_HOOK MutexLocker locker(::hookMutex)
|
||||||
|
|
||||||
namespace
|
namespace
|
||||||
{ // unnamed
|
{ // unnamed
|
||||||
@ -64,11 +64,10 @@ BOOL WINAPI DllMain(HINSTANCE hinstDLL, DWORD fdwReason, LPVOID unused)
|
|||||||
case DLL_PROCESS_ATTACH:
|
case DLL_PROCESS_ATTACH:
|
||||||
DisableThreadLibraryCalls(hinstDLL);
|
DisableThreadLibraryCalls(hinstDLL);
|
||||||
InitializeCriticalSection(&::hostCs);
|
InitializeCriticalSection(&::hostCs);
|
||||||
IthInitSystemService();
|
|
||||||
GetDebugPrivileges();
|
GetDebugPrivileges();
|
||||||
// jichi 12/20/2013: Since I already have a GUI, I don't have to InitCommonControls()
|
// jichi 12/20/2013: Since I already have a GUI, I don't have to InitCommonControls()
|
||||||
// Used by timers.
|
// Used by timers.
|
||||||
InitCommonControls();
|
// InitCommonControls();
|
||||||
// jichi 8/24/2013: Create hidden window so that ITH can access timer and events
|
// 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);
|
dummyWindow = CreateWindowW(L"Button", L"InternalWindow", 0, 0, 0, 0, 0, 0, 0, hinstDLL, 0);
|
||||||
break;
|
break;
|
||||||
@ -76,7 +75,6 @@ BOOL WINAPI DllMain(HINSTANCE hinstDLL, DWORD fdwReason, LPVOID unused)
|
|||||||
if (::running)
|
if (::running)
|
||||||
CloseHost();
|
CloseHost();
|
||||||
DeleteCriticalSection(&::hostCs);
|
DeleteCriticalSection(&::hostCs);
|
||||||
IthCloseSystemService();
|
|
||||||
DestroyWindow(dummyWindow);
|
DestroyWindow(dummyWindow);
|
||||||
break;
|
break;
|
||||||
default:
|
default:
|
||||||
|
@ -201,13 +201,15 @@ void DispatchSentence(void* str,DWORD status, int len)
|
|||||||
memcpy(sentenceBuffer,str,len);
|
memcpy(sentenceBuffer,str,len);
|
||||||
*(WORD*)(sentenceBuffer+len)=0;
|
*(WORD*)(sentenceBuffer+len)=0;
|
||||||
HGLOBAL hCopy;
|
HGLOBAL hCopy;
|
||||||
wchar_t copy[0x200];
|
wchar_t copy[0x400];
|
||||||
if (status&USING_UNICODE)
|
if (status&USING_UNICODE)
|
||||||
{
|
{
|
||||||
memcpy(copy, sentenceBuffer, len + 2);
|
memcpy(copy, sentenceBuffer, len + 2);
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
copy[MB_WC(sentenceBuffer, copy)] = 0;
|
{
|
||||||
|
MultiByteToWideChar(932, 0, sentenceBuffer, -1, copy, 0x400);
|
||||||
|
}
|
||||||
DispatchSentenceToExtensions(copy, status);
|
DispatchSentenceToExtensions(copy, status);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -79,88 +79,15 @@ template <>
|
|||||||
bool try_lock() { return ::TryEnterCriticalSection(&_M_mutex); }
|
bool try_lock() { return ::TryEnterCriticalSection(&_M_mutex); }
|
||||||
};
|
};
|
||||||
|
|
||||||
// Conditional variable
|
class MutexLocker
|
||||||
|
|
||||||
template <typename _Cond>
|
|
||||||
class win_mutex_cond
|
|
||||||
{
|
{
|
||||||
typedef win_mutex_cond<_Cond> _Self;
|
HANDLE m;
|
||||||
typedef _Cond __native_type;
|
|
||||||
win_mutex_cond(const _Self&);
|
|
||||||
_Self &operator=(const _Self&);
|
|
||||||
|
|
||||||
__native_type _M_cond;
|
|
||||||
public:
|
public:
|
||||||
enum wait_status { no_timeout = 0, timeout };
|
explicit MutexLocker(HANDLE mutex) : m(mutex)
|
||||||
typedef __native_type *native_handle_type;
|
|
||||||
|
|
||||||
win_mutex_cond() {}
|
|
||||||
native_handle_type native_handle() { return &_M_cond; }
|
|
||||||
|
|
||||||
void notify_one() {}
|
|
||||||
void notify_all() {}
|
|
||||||
|
|
||||||
template <typename _Mutex>
|
|
||||||
void wait(_Mutex &mutex) {}
|
|
||||||
|
|
||||||
template <typename _Mutex, typename _Pred>
|
|
||||||
void wait(_Mutex &mutex, _Pred pred) {}
|
|
||||||
|
|
||||||
template <typename _Mutex>
|
|
||||||
wait_status wait_for(_Mutex &mutex, int msecs) {}
|
|
||||||
|
|
||||||
template <typename _Mutex, typename _Pred>
|
|
||||||
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<CONDITION_VARIABLE>
|
|
||||||
{
|
{
|
||||||
typedef win_mutex_cond<CONDITION_VARIABLE> _Self;
|
WaitForSingleObject(m, 0);
|
||||||
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 <typename _Mutex>
|
|
||||||
void wait(_Mutex &mutex)
|
|
||||||
{ ::SleepConditionVariableCS(&_M_cond, mutex.native_handle(), INFINITE); }
|
|
||||||
|
|
||||||
template <typename _Mutex, typename _Pred>
|
|
||||||
void wait(_Mutex &mutex, _Pred pred)
|
|
||||||
{ while (!pred()) wait(mutex); }
|
|
||||||
|
|
||||||
template <typename _Mutex>
|
|
||||||
wait_status wait_for(_Mutex &mutex, int msecs)
|
|
||||||
{ return ::SleepConditionVariableCS(&_M_cond, mutex.native_handle(), msecs) ? no_timeout : timeout; }
|
|
||||||
|
|
||||||
template <typename _Mutex, typename _Pred>
|
|
||||||
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;
|
|
||||||
}
|
}
|
||||||
|
~MutexLocker() { if (m != INVALID_HANDLE_VALUE && m != nullptr) ReleaseMutex(m); }
|
||||||
};
|
};
|
||||||
|
|
||||||
// EOF
|
// EOF
|
||||||
|
Loading…
x
Reference in New Issue
Block a user