summaryrefslogtreecommitdiff
path: root/plugins/Mir_core
diff options
context:
space:
mode:
Diffstat (limited to 'plugins/Mir_core')
-rw-r--r--plugins/Mir_core/mir_core.def1
-rw-r--r--plugins/Mir_core/miranda.cpp14
-rw-r--r--plugins/Mir_core/miranda.h1
-rw-r--r--plugins/Mir_core/modules.cpp70
4 files changed, 41 insertions, 45 deletions
diff --git a/plugins/Mir_core/mir_core.def b/plugins/Mir_core/mir_core.def
index 323ef00961..7d998c0d14 100644
--- a/plugins/Mir_core/mir_core.def
+++ b/plugins/Mir_core/mir_core.def
@@ -123,3 +123,4 @@ db_set_s @119
db_set_utf @120
db_set_w @121
db_set_ws @122
+UnloadCoreModule @123
diff --git a/plugins/Mir_core/miranda.cpp b/plugins/Mir_core/miranda.cpp
index 83abfb3acd..910b204292 100644
--- a/plugins/Mir_core/miranda.cpp
+++ b/plugins/Mir_core/miranda.cpp
@@ -350,6 +350,9 @@ MIR_CORE_DLL(INT_PTR) Thread_Pop()
return 1;
}
+/////////////////////////////////////////////////////////////////////////////////////////
+// module init
+
static LRESULT CALLBACK APCWndProc(HWND hwnd, UINT msg, WPARAM wParam, LPARAM lParam)
{
if (msg == WM_NULL) SleepEx(0, TRUE);
@@ -358,10 +361,7 @@ static LRESULT CALLBACK APCWndProc(HWND hwnd, UINT msg, WPARAM wParam, LPARAM lP
return DefWindowProc(hwnd, msg, wParam, lParam);
}
-/////////////////////////////////////////////////////////////////////////////////////////
-// module init
-
-static void LoadSystemModule(void)
+static void LoadCoreModule(void)
{
INITCOMMONCONTROLSEX icce = {0};
icce.dwSize = sizeof(icce);
@@ -390,7 +390,7 @@ static void LoadSystemModule(void)
InitialiseModularEngine();
}
-static void UnloadSystemModule(void)
+MIR_CORE_DLL(void) UnloadCoreModule(void)
{
DestroyWindow(hAPCWindow);
CloseHandle(hStackMutex);
@@ -406,9 +406,7 @@ BOOL WINAPI DllMain(HINSTANCE hinstDLL, DWORD fdwReason, LPVOID lpvReserved)
{
if (fdwReason == DLL_PROCESS_ATTACH) {
hInst = hinstDLL;
- LoadSystemModule();
+ LoadCoreModule();
}
- else if(fdwReason == DLL_PROCESS_DETACH)
- UnloadSystemModule();
return TRUE;
}
diff --git a/plugins/Mir_core/miranda.h b/plugins/Mir_core/miranda.h
index 5e0a0d2fb1..65140260c1 100644
--- a/plugins/Mir_core/miranda.h
+++ b/plugins/Mir_core/miranda.h
@@ -42,6 +42,7 @@ void DestroyModularEngine(void);
int InitPathUtils(void);
extern HINSTANCE hInst;
+extern HWND hAPCWindow;
/**** modules.cpp **********************************************************************/
diff --git a/plugins/Mir_core/modules.cpp b/plugins/Mir_core/modules.cpp
index 6a9aa54bcb..0818e8916e 100644
--- a/plugins/Mir_core/modules.cpp
+++ b/plugins/Mir_core/modules.cpp
@@ -81,24 +81,35 @@ static HANDLE hMainThread;
static HANDLE hMissingService;
static THook *pLastHook = NULL;
+/////////////////////////////////////////////////////////////////////////////////////////
+
+static int QueueMainThread(PAPCFUNC pFunc, void* pParam, HANDLE hDoneEvent)
+{
+ int result = QueueUserAPC(pFunc, hMainThread, (ULONG_PTR)pParam);
+ PostMessage(hAPCWindow, WM_NULL, 0, 0); // let this get processed in its own time
+ if (hDoneEvent) {
+ WaitForSingleObject(hDoneEvent, INFINITE);
+ CloseHandle(hDoneEvent);
+ }
+ return result;
+}
+
///////////////////////////////////////////////////////////////////////////////
// HOOKS
MIR_CORE_DLL(HANDLE) CreateHookableEvent(const char *name)
{
- THook* ret;
- int idx;
-
if (name == NULL)
return NULL;
EnterCriticalSection(&csHooks);
+ int idx;
if ((idx = hooks.getIndex((THook*)name)) != -1) {
LeaveCriticalSection(&csHooks);
return NULL;
}
- ret = (THook*)mir_alloc(sizeof(THook));
+ THook* ret = (THook*)mir_alloc(sizeof(THook));
strncpy(ret->name, name, sizeof(ret->name)); ret->name[ MAXMODULELABELLENGTH-1 ] = 0;
ret->id = hookId++;
ret->subscriberCount = 0;
@@ -242,24 +253,16 @@ static void CALLBACK HookToMainAPCFunc(ULONG_PTR dwParam)
MIR_CORE_DLL(int) NotifyEventHooks(HANDLE hEvent, WPARAM wParam, LPARAM lParam)
{
- extern HWND hAPCWindow;
+ if ( GetCurrentThreadId() == mainThreadId)
+ return (checkHook(hEvent) == -1) ? -1 : CallHookSubscribers(hEvent, wParam, lParam);
- if ( GetCurrentThreadId() != mainThreadId) {
- THookToMainThreadItem item;
-
- item.hDoneEvent = CreateEvent(NULL, FALSE, FALSE, NULL);
- item.hook = (THook*)hEvent;
- item.wParam = wParam;
- item.lParam = lParam;
-
- QueueUserAPC(HookToMainAPCFunc, hMainThread, (ULONG_PTR)&item);
- PostMessage(hAPCWindow, WM_NULL, 0, 0); // let it process APC even if we're in a common dialog
- WaitForSingleObject(item.hDoneEvent, INFINITE);
- CloseHandle(item.hDoneEvent);
- return item.result;
- }
-
- return (checkHook(hEvent) == -1) ? -1 : CallHookSubscribers(hEvent, wParam, lParam);
+ mir_ptr<THookToMainThreadItem> item;
+ item->hDoneEvent = CreateEvent(NULL, FALSE, FALSE, NULL);
+ item->hook = (THook*)hEvent;
+ item->wParam = wParam;
+ item->lParam = lParam;
+ QueueMainThread(HookToMainAPCFunc, item, item->hDoneEvent);
+ return item->result;
}
static HANDLE HookEventInt(int type, const char* name, MIRANDAHOOK hookProc, void* object, LPARAM lParam)
@@ -548,23 +551,18 @@ static void CALLBACK CallServiceToMainAPCFunc(ULONG_PTR dwParam)
MIR_CORE_DLL(INT_PTR) CallServiceSync(const char *name, WPARAM wParam, LPARAM lParam)
{
- extern HWND hAPCWindow;
-
if (name == NULL) return CALLSERVICE_NOTFOUND;
// the service is looked up within the main thread, since the time it takes
// for the APC queue to clear the service being called maybe removed.
// even thou it may exists before the call, the critsec can't be locked between calls.
if (GetCurrentThreadId() != mainThreadId) {
- TServiceToMainThreadItem item;
- item.wParam = wParam;
- item.lParam = lParam;
- item.name = name;
- item.hDoneEvent = CreateEvent(NULL, FALSE, FALSE, NULL);
- QueueUserAPC(CallServiceToMainAPCFunc, hMainThread, (ULONG_PTR) &item);
- PostMessage(hAPCWindow, WM_NULL, 0, 0); // let this get processed in its own time
- WaitForSingleObject(item.hDoneEvent, INFINITE);
- CloseHandle(item.hDoneEvent);
- return item.result;
+ mir_ptr<TServiceToMainThreadItem> item;
+ item->wParam = wParam;
+ item->lParam = lParam;
+ item->name = name;
+ item->hDoneEvent = CreateEvent(NULL, FALSE, FALSE, NULL);
+ QueueMainThread(CallServiceToMainAPCFunc, &item, item->hDoneEvent);
+ return item->result;
}
return CallService(name, wParam, lParam);
@@ -572,10 +570,8 @@ MIR_CORE_DLL(INT_PTR) CallServiceSync(const char *name, WPARAM wParam, LPARAM lP
MIR_CORE_DLL(int) CallFunctionAsync(void (__stdcall *func)(void *), void *arg)
{
- extern HWND hAPCWindow;
- int r = QueueUserAPC((void (__stdcall *)(ULONG_PTR))func, hMainThread, (ULONG_PTR)arg);
- PostMessage(hAPCWindow, WM_NULL, 0, 0);
- return r;
+ QueueMainThread((PAPCFUNC)func, arg, 0);
+ return 0;
}
MIR_CORE_DLL(void) KillModuleServices(HINSTANCE hInst)