   Questions about Plugin Framework
  I have some Questions about my Plugin Framework.First here is the code for the framework.Header:#ifdef PLUGIN_FRAMEWORK_EXPORTS#define PLUGIN_API __declspec(dllexport)#else#define PLUGIN_API __declspec(dllimport)#endif#include <string>#include <iostream>#include "RoH_Plugin.h"#include "RakNetworkFactory.h"#include "RakPeerInterface.h"#include <map>typedef Server_Plugin* (*PLUGIN_FACTORY)(); typedef void (*PLUGIN_CLEANUP)(Server_Plugin*);class PLUGIN_API Plugin_Framework {float PF_Version;//get the program's directorychar dir [MAX_PATH];RakPeerInterface *server;std::map<std::string, PluginHandle> Plugins;public:Plugin_Framework();~Plugin_Framework();void loadPlugins(std::string location);void loadPlugin(std::string pluginName);void updatePlugins();void registerPlugin();//Getters//Settersvoid setRakPeerInterface(RakPeerInterface *peer);};and Source:#include "stdafx.h"#include "Plugin_Framework.h"Plugin_Framework::Plugin_Framework(){PF_Version = 0.1;::GetModuleFileName (NULL, dir, MAX_PATH);//eliminate the file name (to get just the directory)char* p = ::strrchr (dir, '\\');*(p + 1) = 0;std::cout << "Plugin Framework started!\n";}Plugin_Framework::~Plugin_Framework(){}void Plugin_Framework::loadPlugins(std::string location){//find all DLLs in the plugins subdirectorychar search_parms [MAX_PATH];::strcpy_s (search_parms, MAX_PATH, dir);::strcat_s (search_parms, MAX_PATH, location.c_str());WIN32_FIND_DATA find_data;HANDLE h_find = ::FindFirstFile (search_parms, &find_data);BOOL f_ok = TRUE;while (h_find != INVALID_HANDLE_VALUE && f_ok) {//load each DLL and determine whether it is exporting the functions we care aboutchar plugin_full_name [MAX_PATH];::strcpy_s (plugin_full_name, MAX_PATH, dir);::strcat_s (plugin_full_name, MAX_PATH, "plugins\\");::strcat_s (plugin_full_name, MAX_PATH, find_data.cFileName);HMODULE h_mod = ::LoadLibrary (plugin_full_name);if (h_mod != NULL){PLUGIN_FACTORY p_factory_function = (PLUGIN_FACTORY) ::GetProcAddress (h_mod, "Create_Plugin");PLUGIN_CLEANUP p_cleanup_function = (PLUGIN_CLEANUP) ::GetProcAddress (h_mod, "Release_Plugin");if (p_factory_function != NULL && p_cleanup_function != NULL){//yes, this DLL exposes the 2 functions we need, it is a plugin we can use!//invoke the factory to create the plugin objectServer_Plugin* p_plugin = (*p_factory_function) ();//show which plugin it is, and let the plugin do the processingprintf ("Now Registering plugin: %s\n", p_plugin->getName().c_str());if(p_plugin->getPluginVersion() < PF_Version){printf("Registration failed. Plugin was made for a older version of the Plugin Framework!\n");printf("Solution: Recompile the plugin with the newest version of the Plugin Framework. \n");}else if(p_plugin->getPluginVersion() > PF_Version){printf("Registration failed. Plugin was made for a newer version of the Plugin Framework!\n");printf("Solution: Upgrade the version of the Plugin Framework currently running in this Server! \n");}else{p_plugin->setRakPeerInterface(server);PluginHandle PH;PH.location = plugin_full_name;PH.plugin = p_plugin;PH.hMod = h_mod;Plugins[p_plugin->getName()] = PH;p_plugin ->Process_Data ();//done, cleanup the plugin by invoking its cleanup function(*p_cleanup_function) (p_plugin);}}::FreeLibrary (h_mod);}//go for the next DLLf_ok = ::FindNextFile (h_find, &find_data);}}void Plugin_Framework::loadPlugin(std::string pluginName){std::cout << "Plugin Loaded\n";}void Plugin_Framework::registerPlugin(){}void Plugin_Framework::updatePlugins(){// Give each active Plugin a chance to updatefor(std::map<std::string, PluginHandle>::iterator i = Plugins.begin(); i != Plugins.end(); i++){i->second.hMod = ::LoadLibrary(i->second.location.c_str());printf(i->second.location.c_str());printf("\n");if (i->second.hMod != NULL){i->second.plugin->Process_Data();}::FreeLibrary (i->second.hMod);}}void Plugin_Framework::setRakPeerInterface(RakPeerInterface *peer){server = peer;}Ok now my questions. How can I keep all the Plugins open with out using ::FreeLibrary? The Updating method causes the CPU usage to jump up over 80% with just 2 plugins being updated with very simple logic in the update methods.Also any other performance enhancements any one can see please let me know! Thanks!   
  There should be no need to LoadLibrary and FreeLibrary your plugin DLL every time you want to use it; instead, load the DLL once when initializing the framework (i.e. in the constructor) and then release it once when destructing the framework. This will also allow for your plugins to retain persistent data during the lifetime of the framework versus just during the lifetime of Plugin_Framework::updatePlugins().   ;  Ok got it working nicely now. Thanks! The Plugin Framework will be released Opensource under the GPL. It's intended for Raknet based Servers however where it's opensource any one could edit it for their own needs.I will be releasing the first version later tonight.   