diff --git a/Plugins/PluginPower/PowerPlugin.cpp b/Plugins/PluginPower/PowerPlugin.cpp index 82727500..02501397 100644 --- a/Plugins/PluginPower/PowerPlugin.cpp +++ b/Plugins/PluginPower/PowerPlugin.cpp @@ -64,6 +64,7 @@ enum POWER_STATE std::map g_States; std::map g_Formats; HINSTANCE hDLL = NULL; +int g_Instances = 0; FPCALLNTPOWERINFORMATION fpCallNtPowerInformation = NULL; /* @@ -80,14 +81,15 @@ FPCALLNTPOWERINFORMATION fpCallNtPowerInformation = NULL; */ UINT Initialize(HMODULE instance, LPCTSTR iniFile, LPCTSTR section, UINT id) { - if (hDLL == NULL) - { - hDLL = LoadLibrary(L"powrprof.dll"); - if (hDLL) - { - fpCallNtPowerInformation = (FPCALLNTPOWERINFORMATION)GetProcAddress(hDLL, "CallNtPowerInformation"); - } - } + g_Instances++; + if (hDLL == NULL) + { + hDLL = LoadLibrary(L"powrprof.dll"); + if (hDLL) + { + fpCallNtPowerInformation = (FPCALLNTPOWERINFORMATION)GetProcAddress(hDLL, "CallNtPowerInformation"); + } + } POWER_STATE powerState = POWER_UNKNOWN; @@ -285,10 +287,12 @@ void Finalize(HMODULE instance, UINT id) g_Formats.erase(i2); } - if (hDLL != NULL) + g_Instances--; + if (hDLL != NULL && g_Instances == 0) { FreeLibrary(hDLL); hDLL = NULL; + fpCallNtPowerInformation = NULL; } } diff --git a/revision-number.h b/revision-number.h index d09dd094..ca65d25e 100644 --- a/revision-number.h +++ b/revision-number.h @@ -1,2 +1,2 @@ #pragma once -const int revision_number = 302; \ No newline at end of file +const int revision_number = 304; \ No newline at end of file