   How can I dinamycally load dll into a c++ application?
  Hi,Im planning on writing an application to build game levels.  Basically, what I want to write is a software engine that will load dlls on start up, just like 3D max do.That way, Ill be able to develop plugins on the software, and release an API, later, for developpers to add functionality to the software.My question is, does anyone knows how to load dlls dinamycally on startup?  I know how to include it in a project, but I just dont want to have to recompile the whole software everytime I want to add a plugin.  I would rather give a path to the software, where all the plugins are, and the software would load all the dlls in that directory, on startup.Does anyone knows how to do that?Thanks all,Steve   
  What you are looking for is the LoadLibrary method.  I am assumming since you said dll that you are using Windows.Hope that helps!Magius   ;  Consider using LoadLibrary function.You can extract entry-point functions (if you ever need them) by GetProcAddress.I would suggest using the traditional architecture: each and every "plugin" uses something like Core.dll, which is linked to plugin as project dependences (using load-time dynamic linking), so that Core.dll services are available before any C++ statics in plugin are initialized.This way you can use any factory register/unregister services provided by Core.dll.In the executable you can just enumerate all plugins using FindFirstFile and load them using LoadLibrary() (which is effectively run-time dynamic linking).Plugins will register everything you need either by C++ static initialization or inside DllMain().Read About Dynamic-Link Libraries article on MSDN for more details.Hope it helps :)   ;  A quick example might be something like this:// inside the dll, you have this function:int MyDllFunction(int a, int b) {   return a + b;}// Inside the program to load the DLL, you have this:// define a type function pointer for GetProcAddress, this is // basicly the type you'll use to interface with the function. Typical function pointer.typedef int (CALLBACK* SomeFuncType)(int, int);// Create an instance of the DLLHINSTANCE hDll = NULL;hDll = LoadLibrary("somedll.dll");if(hDll == NULL) {   // couldn't load the dll}// Grab a variable to hold the function addressSomeFuncType MyFunction = NULL;MyFunction = (SomeFuncType)GetProcAddress(hDll, "MyDllFunction");if(MyFunction == NULL) {   // couldn't load the function "MyDllFunction"}// Call the function.int nResult = 0;nResult = MyFunction(10, 20);printf("Result: %d\n", nResult);// once you're done with the DLL, free it.FreeLibrary(hDll);;  I would suggest using __declspec( dllexport ) storage-class attribute in the previous code sample.Otherwise you would need some mumble-jumble bit of magic to export C++ functions/objects correctly.   ;Quote:Original post by illiyadaConsider using LoadLibrary function.You can extract entry-point functions (if you ever need them) by GetProcAddress.I would suggest using the traditional architecture: each and every "plugin" uses something like Core.dll, which is linked to plugin as project dependences (using load-time dynamic linking), so that Core.dll services are available before any C++ statics in plugin are initialized.This way you can use any factory register/unregister services provided by Core.dll.In the executable you can just enumerate all plugins using FindFirstFile and load them using LoadLibrary() (which is effectively run-time dynamic linking).Plugins will register everything you need either by C++ static initialization or inside DllMain().Read About Dynamic-Link Libraries article on MSDN for more details.Hope it helps :)Thats exactly what I wanted!Thanks a lot for your help guys,Steve;Quote:Original post by illiyadaI would suggest using __declspec( dllexport ) storage-class attribute in the previous code sample.Otherwise you would need some mumble-jumble bit of magic to export C++ functions/objects correctly.Actually, I was merely including the tiny function as a quick example to show how the function pointer thing works. Not as if it was really ready to be exported.  I figured he'd know that much. :)   ;  Roger that :)   