看了<<Programming Microsoft Windows CE.NET 3rd>>一书的Chapter 10/Modules ,做点笔记
EXE .VS DLL
When launches an EXE, Windows create a separate process space for that module, resolves any imported functions, initializes the proper static data areas, craetes a local heap,creates a thread,and then jumps to the entry point of the module.
However, DLL can't be launched independently. Only by a request from an EXE or another DLL.
Two way to load DLL
1.implicit loading . loaded automatically when Windows loads an EXE that lists the DLL in its import table. The linker generates the import table whn the EXE is linked, and the table containes the list of DLLs and functions within thoese DLLs that the EXE might call during the life of the application.
2. explicit loading . In this case, it's loaded programmatically by the application using one of the two calls, LoadLibray or LoadLibrayEx.
Prototype of LoadLibrary: HINSTANCE LoadLibrary(LPCTSTR lpLibFileName) ;
Prototype of LoadLibraryEx:HINSTANCE LoadLibraryEx(LPCTSTR lpLibFileName, HANDLE hFile,DOWD dwFlags);
searching order(if the parameter does not have path info):
1. The image of the DLL that has already benn loaded in memory;
2. The directory of the executable loading the library;
3. If a relative path was specified, the relative path based on the root(/);
4. The windows directory(/Windows);
5. The root directory in the object store(/);
6. If no relative path is specified, search the image of the DLL in ROM;
7. The path specified in the SystemPath value in[HKEY_LOCAL_MACHINE]/Loader;
notes: 1.applications should avoid the use of relative paths when specifying DLLs because some unexpected results.
2. LoadLibrary ignores extision of fiename, for instance, LoadLibrary(Simple.dll) is the same as LoadLibrary(Simple.cpl);
then use the following function to get a pointer to a function exported by the DLL :
FARPROC GetProcAddress (HMODULE hModule, LPCWSTR lpProcName);
The two parameters are the handle of the module and the name of the function you want to get a pointer to.
free the library when you have finished using the functions:
BOOL FreeLibrary(HMODULE hLibModule);
FreeLibrary decrements the use count on the DLL. If the use count drops to 0, the library is removed from the memory.
When a DLL is first loaded , unloaded or a new thread is created or destroyed in the process that loads it, its entry point is called .
prototyped as :
BOOL APIENTRY DllMain(HANDLE hModule, DWORD ul_reason_for_call,LPVOID lpReserved);
one more function:
BOOL DisableThreadLibraryCalls(HMODULE hLibModule);
this fuctiion tell the operation system not to send DLL_THREAD_ATTACH and DLL_THREAD_DETACH notifications to the DLL when threads are created or destroyed in the application.