Presentation is loading. Please wait.

Presentation is loading. Please wait.

Dynamic Link Libraries (DLL)

Similar presentations


Presentation on theme: "Dynamic Link Libraries (DLL)"— Presentation transcript:

1 Dynamic Link Libraries (DLL)

2 What it is? DLLs are important structural MS Windows component.
code fragments compiled into one library library can be used in multiple programs DLL compared to static library isn’t executable executables can be relatively small DLL creation depends from compiler, but coding is universal

3 _declspec Keyword which is not a part of ANSI C but most compilers it “understands” It lets to choose various nonstandart options to decide program’s workflow Two main options: _declspec(dllexport) _declspec(dllimport)

4 dllexport Shows functions available to other programs
Otherwise functions will be used only inside library This keyword should be used in function’s prototype as well as in it’s definition

5 dllimport To be able to use such function it is needed to import this function into program link program with library declare function’s prototype linking is done at compile time!

6

7 Macro Can we simplify all that?

8 DllMain When linking Windows calls DllMain function:
APIENTRY – keyword used inside Windows (we can forget it) hInstance – handle to DLL module

9 reason Value Meaning DLL_PROCESS_ATTACH DLL attaching to program
DLL_PROCESS_DETACH DLL detaching from program DLL_THREAD_ATTACH DLL attaching to thread DLL_THREAD_DETACH DLL detaching from thread

10 reserved If reason is DLL_PROCESS_ATTACH, reserved is NULL for dynamic loads and non-NULL for static loads If reason is DLL_PROCESS_DETACH, reserved is NULL if FreeLibrary has been called or the DLL load failed and non-NULL if the process is terminating

11 DllMain prototype

12 Remarks DllMain returns TRUE if library is loaded succsefully
Should do almost nothing!

13 Linking DLL Static – compiler will generate two files: DLL and LIB. LIB file works like small static library specifying for linker to statically link with DLL file. Dynamic – true way to use library to link with during workflow. That’s why plugins and extensions are available.

14 Dynamic linking LoadLibrary[Ex] SetDllDirectory().

15

16 What to do with library? LoadResource


Download ppt "Dynamic Link Libraries (DLL)"

Similar presentations


Ads by Google