diff --git a/Library/Rainmeter.cpp b/Library/Rainmeter.cpp index 6f90e814..b80c4f54 100644 --- a/Library/Rainmeter.cpp +++ b/Library/Rainmeter.cpp @@ -99,6 +99,7 @@ int RainmeterMain(LPWSTR cmdLine) { ret = rainmeter.MessagePump(); } + rainmeter.Finalize(); return ret; } @@ -143,32 +144,6 @@ Rainmeter::Rainmeter() : */ Rainmeter::~Rainmeter() { - KillTimer(m_Window, TIMER_NETSTATS); - - DeleteAllUnmanagedMeterWindows(); - DeleteAllMeterWindows(); - - delete m_TrayWindow; - - System::Finalize(); - - MeasureNet::UpdateIFTable(); - MeasureNet::UpdateStats(); - WriteStats(true); - - MeasureNet::FinalizeStatic(); - MeasureCPU::FinalizeStatic(); - MeterString::FinalizeStatic(); - - // Change the work area back - if (m_DesktopWorkAreaChanged) - { - UpdateDesktopWorkArea(true); - } - - if (m_ResourceInstance) FreeLibrary(m_ResourceInstance); - if (m_Mutex) ReleaseMutex(m_Mutex); - CoUninitialize(); GdiplusShutdown(m_GDIplusToken); @@ -441,6 +416,35 @@ int Rainmeter::Initialize(LPCWSTR iniPath, LPCWSTR layout) return 0; // All is OK } +void Rainmeter::Finalize() +{ + KillTimer(m_Window, TIMER_NETSTATS); + + DeleteAllUnmanagedMeterWindows(); + DeleteAllMeterWindows(); + + delete m_TrayWindow; + + System::Finalize(); + + MeasureNet::UpdateIFTable(); + MeasureNet::UpdateStats(); + WriteStats(true); + + MeasureNet::FinalizeStatic(); + MeasureCPU::FinalizeStatic(); + MeterString::FinalizeStatic(); + + // Change the work area back + if (m_DesktopWorkAreaChanged) + { + UpdateDesktopWorkArea(true); + } + + if (m_ResourceInstance) FreeLibrary(m_ResourceInstance); + if (m_Mutex) ReleaseMutex(m_Mutex); +} + bool Rainmeter::IsAlreadyRunning() { typedef struct diff --git a/Library/Rainmeter.h b/Library/Rainmeter.h index 0b76927e..8ac4f943 100644 --- a/Library/Rainmeter.h +++ b/Library/Rainmeter.h @@ -93,6 +93,8 @@ public: static Rainmeter& GetInstance(); int Initialize(LPCWSTR iniPath, LPCWSTR layout); + void Finalize(); + bool IsAlreadyRunning(); int MessagePump();