summaryrefslogtreecommitdiff
path: root/src/core
diff options
context:
space:
mode:
authorTobias Weimer <wishmaster51@googlemail.com>2015-01-27 20:12:13 +0000
committerTobias Weimer <wishmaster51@googlemail.com>2015-01-27 20:12:13 +0000
commitafd50c0e531b68e02c35b4e27c5465d85ee7c765 (patch)
treea5dceaa1c482d8bffae3c1a009d4f08a7b47cc2c /src/core
parentdd802db0d3cb38f4590d15aebaa301eb4608157c (diff)
Unload libraries
git-svn-id: http://svn.miranda-ng.org/main/trunk@11930 1316c22d-e87f-b044-9b9b-93d7a3e3ba9c
Diffstat (limited to 'src/core')
-rw-r--r--src/core/miranda.cpp119
1 files changed, 62 insertions, 57 deletions
diff --git a/src/core/miranda.cpp b/src/core/miranda.cpp
index 841c8ca29c..e4e56c0f15 100644
--- a/src/core/miranda.cpp
+++ b/src/core/miranda.cpp
@@ -163,23 +163,24 @@ static INT_PTR CALLBACK WaitForProcessDlgProc(HWND hwnd, UINT msg, WPARAM wParam
return FALSE;
}
-int CheckRestart()
+INT_PTR CheckRestart()
{
- int result = 0;
LPCTSTR tszPID = CmdLine_GetOption(_T("restart"));
if (tszPID) {
HANDLE hProcess = OpenProcess(SYNCHRONIZE, FALSE, _ttol(tszPID));
if (hProcess) {
- result = DialogBoxParam(hInst, MAKEINTRESOURCE(IDD_WAITRESTART), NULL, WaitForProcessDlgProc, (LPARAM)hProcess);
+ INT_PTR result = DialogBoxParam(hInst, MAKEINTRESOURCE(IDD_WAITRESTART), NULL, WaitForProcessDlgProc, (LPARAM)hProcess);
CloseHandle(hProcess);
+ return result;
}
}
- return result;
+ return 0;
}
static void crtErrorHandler(const wchar_t*, const wchar_t*, const wchar_t*, unsigned, uintptr_t)
{}
+
int WINAPI _tWinMain(HINSTANCE hInstance, HINSTANCE, LPTSTR cmdLine, int)
{
hInst = hInstance;
@@ -198,13 +199,14 @@ int WINAPI _tWinMain(HINSTANCE hInstance, HINSTANCE, LPTSTR cmdLine, int)
_CrtSetDbgFlag(_CRTDBG_ALLOC_MEM_DF | _CRTDBG_LEAK_CHECK_DF);
#endif
+ HMODULE hDwmApi, hThemeAPI;
if (IsWinVerVistaPlus()) {
- HINSTANCE hDwmApi = LoadLibraryA("dwmapi.dll");
+ hDwmApi = LoadLibrary(_T("dwmapi.dll"));
if (hDwmApi) {
dwmExtendFrameIntoClientArea = (pfnDwmExtendFrameIntoClientArea)GetProcAddress(hDwmApi, "DwmExtendFrameIntoClientArea");
dwmIsCompositionEnabled = (pfnDwmIsCompositionEnabled)GetProcAddress(hDwmApi, "DwmIsCompositionEnabled");
}
- HINSTANCE hThemeAPI = LoadLibraryA("uxtheme.dll");
+ hThemeAPI = LoadLibrary(_T("uxtheme.dll"));
if (hThemeAPI) {
drawThemeTextEx = (pfnDrawThemeTextEx)GetProcAddress(hThemeAPI, "DrawThemeTextEx");
setWindowThemeAttribute = (pfnSetWindowThemeAttribute)GetProcAddress(hThemeAPI, "SetWindowThemeAttribute");
@@ -215,6 +217,8 @@ int WINAPI _tWinMain(HINSTANCE hInstance, HINSTANCE, LPTSTR cmdLine, int)
getBufferedPaintBits = (pfnGetBufferedPaintBits)GetProcAddress(hThemeAPI, "GetBufferedPaintBits");
}
}
+ else
+ hDwmApi = hThemeAPI = 0;
if (bufferedPaintInit)
bufferedPaintInit();
@@ -232,66 +236,67 @@ int WINAPI _tWinMain(HINSTANCE hInstance, HINSTANCE, LPTSTR cmdLine, int)
UnloadDefaultModules();
result = 1;
- goto exit;
}
- InitPathVar();
- NotifyEventHooks(hModulesLoadedEvent, 0, 0);
- bModulesLoadedFired = true;
-
- // ensure that the kernel hooks the SystemShutdownProc() after all plugins
- HookEvent(ME_SYSTEM_SHUTDOWN, SystemShutdownProc);
-
- forkthread(compactHeapsThread, 0, NULL);
- CreateServiceFunction(MS_SYSTEM_SETIDLECALLBACK, SystemSetIdleCallback);
- CreateServiceFunction(MS_SYSTEM_GETIDLE, SystemGetIdle);
- dwEventTime = GetTickCount();
- DWORD myPid = GetCurrentProcessId();
-
- bool messageloop = true;
- while (messageloop) {
- MSG msg;
- DWORD rc;
- BOOL dying = FALSE;
- rc = MsgWaitForMultipleObjectsEx(waitObjectCount, hWaitObjects, INFINITE, QS_ALLINPUT, MWMO_ALERTABLE);
- if (rc < WAIT_OBJECT_0 + waitObjectCount) {
- rc -= WAIT_OBJECT_0;
- CallService(pszWaitServices[rc], (WPARAM)hWaitObjects[rc], 0);
- }
- //
- while (PeekMessage(&msg, NULL, 0, 0, PM_REMOVE)) {
- if (msg.message != WM_QUIT) {
- HWND h = GetForegroundWindow();
- DWORD pid = 0;
- checkIdle(&msg);
- if (h != NULL && GetWindowThreadProcessId(h, &pid) && pid == myPid && GetClassLongPtr(h, GCW_ATOM) == 32770)
- if (IsDialogMessage(h, &msg))
- continue;
-
- TranslateMessage(&msg);
- DispatchMessage(&msg);
- if (SetIdleCallback != NULL)
- SetIdleCallback();
+ else {
+ InitPathVar();
+ NotifyEventHooks(hModulesLoadedEvent, 0, 0);
+ bModulesLoadedFired = true;
+
+ // ensure that the kernel hooks the SystemShutdownProc() after all plugins
+ HookEvent(ME_SYSTEM_SHUTDOWN, SystemShutdownProc);
+
+ forkthread(compactHeapsThread, 0, NULL);
+ CreateServiceFunction(MS_SYSTEM_SETIDLECALLBACK, SystemSetIdleCallback);
+ CreateServiceFunction(MS_SYSTEM_GETIDLE, SystemGetIdle);
+ dwEventTime = GetTickCount();
+ DWORD myPid = GetCurrentProcessId();
+
+ bool messageloop = true;
+ while (messageloop) {
+ MSG msg;
+ BOOL dying = FALSE;
+ DWORD rc = MsgWaitForMultipleObjectsEx(waitObjectCount, hWaitObjects, INFINITE, QS_ALLINPUT, MWMO_ALERTABLE);
+ if (rc < WAIT_OBJECT_0 + waitObjectCount) {
+ rc -= WAIT_OBJECT_0;
+ CallService(pszWaitServices[rc], (WPARAM)hWaitObjects[rc], 0);
}
- else if (!dying) {
- dying++;
- SetEvent(hMirandaShutdown);
- NotifyEventHooks(hPreShutdownEvent, 0, 0);
-
- // this spins and processes the msg loop, objects and APC.
- Thread_Wait();
- NotifyEventHooks(hShutdownEvent, 0, 0);
- // if the hooks generated any messages, it'll get processed before the second WM_QUIT
- PostQuitMessage(0);
+ //
+ while (PeekMessage(&msg, NULL, 0, 0, PM_REMOVE)) {
+ if (msg.message != WM_QUIT) {
+ HWND h = GetForegroundWindow();
+ DWORD pid = 0;
+ checkIdle(&msg);
+ if (h != NULL && GetWindowThreadProcessId(h, &pid) && pid == myPid && GetClassLongPtr(h, GCW_ATOM) == 32770)
+ if (IsDialogMessage(h, &msg))
+ continue;
+
+ TranslateMessage(&msg);
+ DispatchMessage(&msg);
+ if (SetIdleCallback != NULL)
+ SetIdleCallback();
+ }
+ else if (!dying) {
+ dying++;
+ SetEvent(hMirandaShutdown);
+ NotifyEventHooks(hPreShutdownEvent, 0, 0);
+
+ // this spins and processes the msg loop, objects and APC.
+ Thread_Wait();
+ NotifyEventHooks(hShutdownEvent, 0, 0);
+ // if the hooks generated any messages, it'll get processed before the second WM_QUIT
+ PostQuitMessage(0);
+ }
+ else if (dying)
+ messageloop = false;
}
- else if (dying)
- messageloop = false;
}
}
-exit:
UnloadNewPluginsModule();
UnloadCoreModule();
CloseHandle(hMirandaShutdown);
+ FreeLibrary(hDwmApi);
+ FreeLibrary(hThemeAPI);
if (pTaskbarInterface)
pTaskbarInterface->Release();