- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Greetings:
Playing with DLLs and noticing behaviors that make sense but seeking confirmation.
I amplugging into a 3'rd party application called Unigraphics so I have little control over the execution environment.I am assuming that they load and explicitly unload my DLL each time the user chooses to perform my task.
1) "Global" variables defined in the DLL get re-initialized upon each loading of the DLL. So if I want any "static" variable to exist between multiple execution of my dll (with in the same PID)I better write them to an environment variable or file. (my choice is env variable as it is specific to the PID and is cleaned up automatically)
2) Every DLL at load time gets it's own copy of "atexit" routines. ( reference http://social.msdn.microsoft.com/Forums/en-US/vclanguage/thread/2036168e-0f5e-49a7-92d4-24626c80f148)
So how do I load up the "atexit" routines when my dll is loaded? Is there an "atentry" routine that get called when a a dll is loaded?
3) While global variables get re-initialized, file pointers do not. So let's say the DLL opens a file but does not close it before it is unloaded. Can I assume thefile handles scope is at the process level and not the dll level. So any checks on file closure should be done in the dlls "atexit" routine.
Any comments or pointers to more info would be greatly appreciated.
Regards
Carl
Link Copied
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
The DllMain function is designed for simple initialization or termination tasks. See :
http://msdn.microsoft.com/en-us/library/ms682583%28v=VS.85%29.aspx
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
An application can have multiple instances of itself running in the system simultaneously, whereas a DLL can have only one instance.
An application can own things such as a stack, global memory, file handles, and a message queue, but a DLL cannot.
So a file that is opened in a DLL and not closed by DLL exit is "leaked", and subsequent use of the file will be problematic until the process ends.

- Subscribe to RSS Feed
- Mark Topic as New
- Mark Topic as Read
- Float this Topic for Current User
- Bookmark
- Subscribe
- Printer Friendly Page