Global variable issues for dynamic link libraries
When the dynamic link library is called multiple times externally, will the global variables of the dynamic library itself be reinitialized each time it is called? How does that make me do it every time I invoke a dynamic library from the last state?
The question of whether you scored the same process or a different process is called. If it is a different process, then your dynamic connection library is completely reloaded. Because a dynamic connection library is mapped to the process in which it is called, and different processes have different address spaces, it is not necessary for different processes to call the same DLL, unless you declare variables in the shared data segment so that the variables are shared among different processes.
If you LoadLibrary the same process multiple times, it doesn't have to be reinitialized, in fact windows works like this. He creates a variable for the dynamic connection library to record the number of times the load is LoadLibrary, and in one process each time the reference count is added 1, each time the reference record is FreeLibrary minus 1, and when the count becomes 0 o'clock, Windows completely releases the DLL. This time you load again, then all the initialization work will be done again. If you load a DLL that has already been loaded elsewhere in the program, it is not initialized.
Save status can be saved to a file, saved to the registry, and so on.
-
Questioner evaluation
-
Very detailed, thank you! And thanks to other enthusiastic friends ^_^
Go: Global variable problem for dynamic link library