Implicit vs Explicit Linking of DLLs
-
I finally figured out how to get my dlls setup properly and exported the functions and was able to import the functions into another project. When I did this I had to add the .lib file to my project and compile the project with the lib file to be able to access the exported functions. What I would really like to do is link to the dll Explicitly using LoadLibrary and GetProcAddress. To explain why I need to ask another question. I am going to have a series of dlls that will all export the same functions but will have different data returned depending on the dll that is called. For example each dll might have a function exported call GetNames(). If dll1 is called in might return John, Jill, Jack and Joe. If dll2 is called it might return Amber, Ally, Allen and Ashely. Now what I really wanted to be able to do is not have to recompile the the main application when I add each dll. I need a way to be able to have my main application check to see which dlls are available and then call those functions for each dll. If I have to include the .lib file for each dll won't I have to recompile the project each time I add a new dll? Or will I have to recompile the project each time no matter which style I use? Thanks for all the help from everyone with my relentless dll questions. :) -Eric
-
I finally figured out how to get my dlls setup properly and exported the functions and was able to import the functions into another project. When I did this I had to add the .lib file to my project and compile the project with the lib file to be able to access the exported functions. What I would really like to do is link to the dll Explicitly using LoadLibrary and GetProcAddress. To explain why I need to ask another question. I am going to have a series of dlls that will all export the same functions but will have different data returned depending on the dll that is called. For example each dll might have a function exported call GetNames(). If dll1 is called in might return John, Jill, Jack and Joe. If dll2 is called it might return Amber, Ally, Allen and Ashely. Now what I really wanted to be able to do is not have to recompile the the main application when I add each dll. I need a way to be able to have my main application check to see which dlls are available and then call those functions for each dll. If I have to include the .lib file for each dll won't I have to recompile the project each time I add a new dll? Or will I have to recompile the project each time no matter which style I use? Thanks for all the help from everyone with my relentless dll questions. :) -Eric
VanHlebar wrote: If I have to include the .lib file for each dll won't I have to recompile the project each time I add a new dll? yes. since you're linking to the static lib, your app will have the DLL name encoded into it somewhere. it sounds like you're doing a plug-in system. (click here to learn more! :) ) if that's the case, what you need to do (IMO) is to write an interface layer between the DLLs and the code that calls the DLL. this layer will act as a proxy between your DLLs and the caller. in addition to allowing a way to call the DLL functions, it will handle DLL loading and unloading. your app can just scan a folder (or whatever) and get a list of DLLs that support your interface (just GetProcAddr for all your calls; if they're all there, the DLL is good, add it to the list). make that proxy layer a class and instantiate one per DLL. put them all in an array and you're all set :) -c
I'm not the droid you're looking for.
-
VanHlebar wrote: If I have to include the .lib file for each dll won't I have to recompile the project each time I add a new dll? yes. since you're linking to the static lib, your app will have the DLL name encoded into it somewhere. it sounds like you're doing a plug-in system. (click here to learn more! :) ) if that's the case, what you need to do (IMO) is to write an interface layer between the DLLs and the code that calls the DLL. this layer will act as a proxy between your DLLs and the caller. in addition to allowing a way to call the DLL functions, it will handle DLL loading and unloading. your app can just scan a folder (or whatever) and get a list of DLLs that support your interface (just GetProcAddr for all your calls; if they're all there, the DLL is good, add it to the list). make that proxy layer a class and instantiate one per DLL. put them all in an array and you're all set :) -c
I'm not the droid you're looking for.
Chris Losinger wrote: it sounds like you're doing a plug-in system. (click here to learn more! ) Chris, I clicked but didn't go anywhere :) Yes it is sort of a plug-in system. The user will be able to get the extra dlls and choose which ones they want to use and which ones not to use. I like the idea of being able to instantiate one class per dll and having an array, but I guess I would need more information on how to do just that. Thanks for the help, -Eric
-
Chris Losinger wrote: it sounds like you're doing a plug-in system. (click here to learn more! ) Chris, I clicked but didn't go anywhere :) Yes it is sort of a plug-in system. The user will be able to get the extra dlls and choose which ones they want to use and which ones not to use. I like the idea of being able to instantiate one class per dll and having an array, but I guess I would need more information on how to do just that. Thanks for the help, -Eric
somethign like this:
class CMyProxy
{
public:
CMyProxy();// calls FreeLibrary
~CMyProxy();// calls LoadLibrary. then calls GetProcAddress for each function
// and assigns each proc addr to a member function of the appropriate type
bool Load(const char *pDLLName);RetType MyFunc1(...) {return (m_pFunc1)(...);}
RetType MyFunc2(...) {return (m_pFunc2)(...);}protected:
FuncType1 m_pFunc1;
FuncType2 m_pFunc2;
};CMyProxy proxy;
if (proxy.Load(pDLLFileName))
{
RetType ret = proxy.MyFunc1(whatever, whatever);
}so, the CMyProxy class loads the DLL, gets function pointers and lets you call DLL functions through its own function wrappers. -c
I'm not the droid you're looking for.
-
Chris Losinger wrote: it sounds like you're doing a plug-in system. (click here to learn more! ) Chris, I clicked but didn't go anywhere :) Yes it is sort of a plug-in system. The user will be able to get the extra dlls and choose which ones they want to use and which ones not to use. I like the idea of being able to instantiate one class per dll and having an array, but I guess I would need more information on how to do just that. Thanks for the help, -Eric
This article Plug-In Architecture.asp[^] of mine does what Chris is suggesting. Its probably overkill for your current situation, but you should be able to cut out the bits you needs and modify them to what you require. Roger Allen Sonork 100.10016 This is a multiple choice question, choose wisely Why did the hedgehog cross the road? A: To show he had guts? B: To see his flat mate?