Sign in to follow this  

Question on freeing dynamic loaded dlls

This topic is 3735 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

What would happen if I load the same DLL twice, (using LoadLibrary and GetProcAddress), then removed ONE of them using FreeLibrary? Would the other one still work? I guess my question is really, does windows load each one into memory separately, or does it just point to the same location twice? I did try to write a test case to figure it out, but it's acting strange: even after I call FreeLib, I can still access classes created by the DLL. Is this right? The same questions stand for linux (I'm trying to write cross platform code here) using dlopen, dlsym and dlclose For tools I'm using code::blocks with vc++ 2005 (express) in windows, and g++ 4.4 in ubuntu On the topic of cross-platform code, are there any compiler flags that automatically get put up which identify the platform being compiled for?

Share this post


Link to post
Share on other sites
Quote:
Original post by methinks
What would happen if I load the same DLL twice, (using LoadLibrary and GetProcAddress), then removed ONE of them using FreeLibrary? Would the other one still work? I guess my question is really, does windows load each one into memory separately, or does it just point to the same location twice?

Mu. Windows loads the library once, but increments its reference count twice. If you call FreeLibrary only once, the reference count is only decremented once, and the library is not unloaded.

Share this post


Link to post
Share on other sites
Quote:
Original post by methinks
On the topic of cross-platform code, are there any compiler flags that automatically get put up which identify the platform being compiled for?

Windows projects usually have a preprocessor define for WIN32 and/or _WINDOWS

Share this post


Link to post
Share on other sites
why don't you read the manpage and find out.

Share this post


Link to post
Share on other sites

This topic is 3735 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

Sign in to follow this