Dynamic link database
DLL can include global data and local data
Variable range
The default range of the DLL variable is the same as the variable scope declared by the application, and the global variable in the DLL source file is all visible to each process using the DLL. Static variables are limited to the scope of the declaration. By default, each process has its own DLL global variables and static variable instances.
The development tool you use may allow you to go beyond the default global and static variable range. See the development tool-related documentation for more information.
Dynamic memory allocation
When the DLL is assigned by the memory allocation function (GlobalLoc, Localalloc, HeapAlloc, and Virtualalloc), the assigned memory is in the virtual location space of the calling process, and can only be accessed by the process.
DLL can use file images to assign memory that can be shared between processes. About how to create a full discussion of the file image to create a shared naming storage space, you can refer to the "file image". View the shared memory of the application DLLMAIN function to set up a file image, refer to "Use Sharing Memory in Dynamic Link Library".
Thread local storage
Each thread in a multi-thread process utilizes a thread local storage (TLS) function, allowing the DLL to allocate storage and retrieve different values in the multi-thread process. For example, when a user opens a new spreadsheet in an electronic table program, create a new instance in the same thread. The DLL for providing functions for a variety of spreadsheets can save the current status of each spreadsheet (line, column, etc.) of each spreadsheet by TLS. About TLS more comprehensive discussion, refer to "Thread Local Storage". An example of establishing a thread local storage through a DLLMAIN function can be referred to the "Using Thread Local Storage in Dynamic Link Library".
WARNING: The Visual C compiler can be used to declare the linear variables in the Visual C compiler. If the syntax is applied, you cannot clearly load the DLL through the LoadLibrary or LoadLibraryEx function. If you need to explicitly load the DLL through a function, you must implement the function of the thread partial storage, not _Declspec (thread).
Dynamic link library redirection
The problem will occur when the application loads a DLL that is different from the loaded version. If it is running in Windows 2000, you can use the correct version of the DLL by creating a redirect file. The content of the redirection file will be ignored, but if it exists, (system) will force all DLLs from the directory where the application is located.
The redirection file must be named in the following format:
Appname.local
For example, if the application's name is editor.exe, the name of the redirected file should be editor.exe.local. You must install Editor.Exe.local in the same directory where Editor.exe is located, you must also install the DLL to the same directory.
If the redirect file exists, the LoadLibrary and LoadLibraryEx functions change the search order. If the path is specified and the redirect file is also specified, these functions searches for the DLL in the application's directory. If the DLL is in the application directory, these functions ignore the specified path and load the DLL in the program directory. If not in the program directory, the function will load the DLL by specified directory.
For example, an application C: /myapp/myapp.ex is called with the following path: LoadLibrary:
C: / program files / common files / system / mydll.dll.
If c: /myapp/myapp.exe.local and c: /myapp/mydll.dll exists, LoadLibrary will load C: /myApp/mydll.dll; otherwise, load C: / Program Files / Common files / System / mydll.dll. Note: To develop a good habit of installing the required DLL to the same directory as the application, even if you don't need to redirect it. This will ensure that your program will not overwrite other DLL copies, of course, will not cause other application errors. In addition, other applications will not override your DLL copy, causing your application to run failed.