diff options
Diffstat (limited to 'src')
-rw-r--r-- | src/mir_app/src/db_ini.cpp | 11 | ||||
-rw-r--r-- | src/mir_app/src/menu_utils.cpp | 12 | ||||
-rw-r--r-- | src/mir_app/src/mir_app.def | 1 | ||||
-rw-r--r-- | src/mir_app/src/mir_app64.def | 1 | ||||
-rw-r--r-- | src/mir_app/src/miranda.cpp | 89 | ||||
-rw-r--r-- | src/mir_app/src/srmm_toolbar.cpp | 10 |
6 files changed, 61 insertions, 63 deletions
diff --git a/src/mir_app/src/db_ini.cpp b/src/mir_app/src/db_ini.cpp index b33095de6c..7dd28b411b 100644 --- a/src/mir_app/src/db_ini.cpp +++ b/src/mir_app/src/db_ini.cpp @@ -593,11 +593,10 @@ static void DoAutoExec(void) FindClose(hFind);
}
-static INT_PTR CheckIniImportNow(WPARAM, LPARAM)
+static void CALLBACK CheckIniImportNow()
{
DoAutoExec();
FindNextChangeNotification(hIniChangeNotification);
- return 0;
}
static INT_PTR ImportINI(WPARAM wParam, LPARAM)
@@ -616,10 +615,9 @@ int InitIni(void) wchar_t szMirandaDir[MAX_PATH];
PathToAbsoluteW(L".", szMirandaDir);
hIniChangeNotification = FindFirstChangeNotification(szMirandaDir, 0, FILE_NOTIFY_CHANGE_FILE_NAME);
- if (hIniChangeNotification != INVALID_HANDLE_VALUE) {
- CreateServiceFunction("DB/Ini/CheckImportNow", CheckIniImportNow);
- CallService(MS_SYSTEM_WAITONHANDLE, (WPARAM)hIniChangeNotification, (LPARAM)"DB/Ini/CheckImportNow");
- }
+ if (hIniChangeNotification != INVALID_HANDLE_VALUE)
+ Miranda_WaitOnHandle(CheckIniImportNow, hIniChangeNotification);
+
return 0;
}
@@ -628,6 +626,5 @@ void UninitIni(void) if (!bModuleInitialized)
return;
- CallService(MS_SYSTEM_REMOVEWAIT, (WPARAM)hIniChangeNotification, 0);
FindCloseChangeNotification(hIniChangeNotification);
}
diff --git a/src/mir_app/src/menu_utils.cpp b/src/mir_app/src/menu_utils.cpp index 2b2f07e35d..85b205ea19 100644 --- a/src/mir_app/src/menu_utils.cpp +++ b/src/mir_app/src/menu_utils.cpp @@ -916,11 +916,8 @@ static int sttDumpItem(TMO_IntMenuItem *pmi, void *szModule) return 0;
}
-static INT_PTR sttUpdateMenuService(WPARAM wParam, LPARAM)
+static void CALLBACK sttUpdateMenuService()
{
- CallService(MS_SYSTEM_REMOVEWAIT, wParam, 0);
- CloseHandle((HANDLE)wParam);
-
for (int i = 0; i < g_menus.getCount(); i++) {
TIntMenuObject *pmo = g_menus[i];
if (!pmo->m_bUseUserDefinedItems)
@@ -963,16 +960,11 @@ static INT_PTR sttUpdateMenuService(WPARAM wParam, LPARAM) MO_RecursiveWalkMenu(pmo->m_items.first, Menu_LoadFromDatabase, szModule);
}
}
- return 0;
}
-#define MS_MENU_UPDATE "System/Genmenu/Update"
-
void ScheduleMenuUpdate()
{
- HANDLE hEvent = CreateEvent(NULL, TRUE, TRUE, NULL);
- CreateServiceFunction(MS_MENU_UPDATE, sttUpdateMenuService);
- CallService(MS_SYSTEM_WAITONHANDLE, (WPARAM)hEvent, (LPARAM)MS_MENU_UPDATE);
+ Miranda_WaitOnHandle(sttUpdateMenuService);
}
/////////////////////////////////////////////////////////////////////////////////////////
diff --git a/src/mir_app/src/mir_app.def b/src/mir_app/src/mir_app.def index 6cd5b0ddf1..2dcaf3ed1b 100644 --- a/src/mir_app/src/mir_app.def +++ b/src/mir_app/src/mir_app.def @@ -338,3 +338,4 @@ Srmm_RedrawToolbarIcons @338 Srmm_GetNthButton @339
Srmm_GetButtonCount @340
Srmm_ClickToolbarIcon @341
+Miranda_WaitOnHandle @342
diff --git a/src/mir_app/src/mir_app64.def b/src/mir_app/src/mir_app64.def index b7ca0d8171..73b3111bf1 100644 --- a/src/mir_app/src/mir_app64.def +++ b/src/mir_app/src/mir_app64.def @@ -338,3 +338,4 @@ Srmm_RedrawToolbarIcons @338 Srmm_GetNthButton @339
Srmm_GetButtonCount @340
Srmm_ClickToolbarIcon @341
+Miranda_WaitOnHandle @342
diff --git a/src/mir_app/src/miranda.cpp b/src/mir_app/src/miranda.cpp index 6c6452066c..e21b06339e 100644 --- a/src/mir_app/src/miranda.cpp +++ b/src/mir_app/src/miranda.cpp @@ -42,13 +42,10 @@ pfnGetBufferedPaintBits getBufferedPaintBits; pfnDwmExtendFrameIntoClientArea dwmExtendFrameIntoClientArea;
pfnDwmIsCompositionEnabled dwmIsCompositionEnabled;
-ITaskbarList3 * pTaskbarInterface;
+ITaskbarList3 *pTaskbarInterface;
HANDLE hOkToExitEvent, hModulesLoadedEvent;
HANDLE hShutdownEvent, hPreShutdownEvent;
-static HANDLE hWaitObjects[MAXIMUM_WAIT_OBJECTS-1];
-static char *pszWaitServices[MAXIMUM_WAIT_OBJECTS-1];
-static int waitObjectCount = 0;
HANDLE hMirandaShutdown;
HINSTANCE g_hInst;
DWORD hMainThreadId;
@@ -56,6 +53,42 @@ int hLangpack = 0; bool bModulesLoadedFired = false;
int g_iIconX, g_iIconY, g_iIconSX, g_iIconSY;
+/////////////////////////////////////////////////////////////////////////////////////////
+
+struct MWaitableObject
+{
+ MWaitableObject(MWaitableStub pFunc, HANDLE hEvent) :
+ m_bOwnsEvent(false),
+ m_hEvent(hEvent),
+ m_pFunc(pFunc)
+ {
+ if (hEvent == NULL) {
+ m_hEvent = CreateEvent(NULL, TRUE, TRUE, NULL);
+ m_bOwnsEvent = true;
+ }
+ }
+
+ ~MWaitableObject()
+ {
+ if (m_bOwnsEvent)
+ ::CloseHandle(m_hEvent);
+ }
+
+ bool m_bOwnsEvent;
+ HANDLE m_hEvent;
+ MWaitableStub m_pFunc;
+};
+
+static OBJLIST<MWaitableObject> arWaitableObjects(1, HandleKeySortT);
+
+MIR_APP_DLL(void) Miranda_WaitOnHandle(MWaitableStub pFunc, HANDLE hEvent)
+{
+ arWaitableObjects.insert(new MWaitableObject(pFunc, hEvent));
+}
+
+/////////////////////////////////////////////////////////////////////////////////////////
+// dll entry point
+
BOOL WINAPI DllMain(HINSTANCE hinstDLL, DWORD dwReason, LPVOID)
{
if (dwReason == DLL_PROCESS_ATTACH) {
@@ -214,6 +247,15 @@ INT_PTR CheckRestart() static void crtErrorHandler(const wchar_t*, const wchar_t*, const wchar_t*, unsigned, uintptr_t)
{}
+static DWORD myWait()
+{
+ HANDLE *hWaitObjects = (HANDLE*)_alloca(arWaitableObjects.getCount() * sizeof(HANDLE));
+ for (int i = 0; i < arWaitableObjects.getCount(); i++)
+ hWaitObjects[i] = arWaitableObjects[i].m_hEvent;
+
+ return MsgWaitForMultipleObjectsEx(arWaitableObjects.getCount(), hWaitObjects, INFINITE, QS_ALLINPUT, MWMO_ALERTABLE);
+}
+
int WINAPI mir_main(LPTSTR cmdLine)
{
hMainThreadId = GetCurrentThreadId();
@@ -286,12 +328,13 @@ int WINAPI mir_main(LPTSTR cmdLine) while (messageloop) {
MSG msg;
BOOL dying = FALSE;
- DWORD rc = MsgWaitForMultipleObjectsEx(waitObjectCount, hWaitObjects, INFINITE, QS_ALLINPUT, MWMO_ALERTABLE);
- if (rc < WAIT_OBJECT_0 + waitObjectCount) {
+ DWORD rc = myWait();
+ if (rc < WAIT_OBJECT_0 + arWaitableObjects.getCount()) {
rc -= WAIT_OBJECT_0;
- CallService(pszWaitServices[rc], (WPARAM)hWaitObjects[rc], 0);
+ (*arWaitableObjects[rc].m_pFunc)();
+ arWaitableObjects.remove(rc);
}
- //
+
while (PeekMessage(&msg, NULL, 0, 0, PM_REMOVE)) {
if (msg.message != WM_QUIT) {
HWND h = GetForegroundWindow();
@@ -402,34 +445,6 @@ static INT_PTR GetMirandaVersionText(WPARAM wParam, LPARAM lParam) return 0;
}
-INT_PTR WaitOnHandle(WPARAM wParam, LPARAM lParam)
-{
- if (waitObjectCount >= MAXIMUM_WAIT_OBJECTS - 1)
- return 1;
-
- hWaitObjects[waitObjectCount] = (HANDLE)wParam;
- pszWaitServices[waitObjectCount] = (char*)lParam;
- waitObjectCount++;
- return 0;
-}
-
-static INT_PTR RemoveWait(WPARAM wParam, LPARAM)
-{
- int i;
-
- for (i = 0; i < waitObjectCount; i++)
- if (hWaitObjects[i] == (HANDLE)wParam)
- break;
-
- if (i == waitObjectCount)
- return 1;
-
- waitObjectCount--;
- memmove(&hWaitObjects[i], &hWaitObjects[i + 1], sizeof(HANDLE)*(waitObjectCount - i));
- memmove(&pszWaitServices[i], &pszWaitServices[i + 1], sizeof(char*)*(waitObjectCount - i));
- return 0;
-}
-
///////////////////////////////////////////////////////////////////////////////
int LoadSystemModule(void)
@@ -446,8 +461,6 @@ int LoadSystemModule(void) CreateServiceFunction(MS_SYSTEM_GETVERSION, GetMirandaVersion);
CreateServiceFunction(MS_SYSTEM_GETFILEVERSION, GetMirandaFileVersion);
CreateServiceFunction(MS_SYSTEM_GETVERSIONTEXT, GetMirandaVersionText);
- CreateServiceFunction(MS_SYSTEM_WAITONHANDLE, WaitOnHandle);
- CreateServiceFunction(MS_SYSTEM_REMOVEWAIT, RemoveWait);
CreateServiceFunction(MS_SYSTEM_GETEXCEPTFILTER, srvGetExceptionFilter);
CreateServiceFunction(MS_SYSTEM_SETEXCEPTFILTER, srvSetExceptionFilter);
return 0;
diff --git a/src/mir_app/src/srmm_toolbar.cpp b/src/mir_app/src/srmm_toolbar.cpp index 5c96538e40..caf9335836 100644 --- a/src/mir_app/src/srmm_toolbar.cpp +++ b/src/mir_app/src/srmm_toolbar.cpp @@ -741,13 +741,9 @@ static int SrmmModulesLoaded(WPARAM, LPARAM) return 0; } -static INT_PTR SrmmLoadToolbar(WPARAM wParam, LPARAM) +static void CALLBACK SrmmLoadToolbar() { - CallService(MS_SYSTEM_REMOVEWAIT, wParam, 0); - CloseHandle((HANDLE)wParam); - NotifyEventHooks(hHookToolBarLoadedEvt, 0, 0); - return 0; } static int ConvertToolbarData(const char *szSetting, LPARAM) @@ -764,9 +760,7 @@ void LoadSrmmToolbarModule() { HookEvent(ME_SYSTEM_MODULESLOADED, SrmmModulesLoaded); - HANDLE hEvent = CreateEvent(NULL, TRUE, TRUE, NULL); - CreateServiceFunction("Srmm/LoadToolbar", SrmmLoadToolbar); - CallService(MS_SYSTEM_WAITONHANDLE, (WPARAM)hEvent, (LPARAM)"Srmm/LoadToolbar"); + Miranda_WaitOnHandle(SrmmLoadToolbar); hHookButtonPressedEvt = CreateHookableEvent(ME_MSG_BUTTONPRESSED); hHookToolBarLoadedEvt = CreateHookableEvent(ME_MSG_TOOLBARLOADED); |