Importing funcs w/ __declspec(dllimport)
I know the Win32 API dll functions accomplish the same task, but I think this would be more convenient since it''s just one line before the function call. I''m not exactly sure on how to use it though, the documentation says something like this...
//In DLL (stuff.dll)
void func1(void)
{
...
}
//In header (stuff.h)
void func1 (void);
//In application, whenever you want to use the function
__declspec(dllimport) void func1(void);
func1();
I''m assuming you create the dll like you would anything else, just stick all the functions you want in the dll in a .c source and the compile and link to a dll instead of an app, and make up the header as usual. Is that correct so far?
Now, whenever I want to use that function and I use the above code, does the function get loaded each time? Or if it was recently used does it stay in memory? If it was something time sensitive then it would be a pain to load it from the HD each time it was used. Does it work the same way with inlined functions as well? And, do I have to do anything to unload it? I''m guessing I don''t.
Thanks for any insight anyone can offer.
------------
- outRider -
October 11, 2000 11:11 AM
When you load the program, the loader checks which DLL''s the program imports functions from, and loads that DLL. Then, all addresses are resolved. The linking occurs at load-time. DLL''s are not unloaded until your program exits.
Alternatively, you can control the loading yourself via LoadLibrary()/GetProcAddress(). Generally, you onlt want to do this if you are unsure the DLL exists, or you don''t know which DLL''s you need until run-time.
Another method, is delay imports. You don''t actually load the DLL until the function is called.
BTW, remember to also include __declspec(dllexport) on all functions you want the DLL to export.
Alternatively, you can control the loading yourself via LoadLibrary()/GetProcAddress(). Generally, you onlt want to do this if you are unsure the DLL exists, or you don''t know which DLL''s you need until run-time.
Another method, is delay imports. You don''t actually load the DLL until the function is called.
BTW, remember to also include __declspec(dllexport) on all functions you want the DLL to export.
This topic is closed to new replies.
Advertisement
Popular Topics
Advertisement
Recommended Tutorials
Advertisement