Targetname = DLL
Targettype = dynlink
Sources = DLL. cpp \
Use_msvcrt = 1
Targetlibs = $ (sdk_lib_path) \ gdi32.lib \
$ (Sdk_lib_path) \ user32.lib \
$ (Sdk_lib_path) \ kernel32.lib \
$ (Sdk_lib_path) \ NTDLL. Lib \
The content of the sources file. Note that the type is dynlink.
! Include $ (ntmakeenv) \ makefile. Def
Makefile content
DLL. cpp source file content
# Include "windows. H"
Int add (int A, int B)
{
Return A + B;
}
Bool winapi dllmain (
Hinstance hinstdll, // handle to the DLL module
DWORD fdwreason, // reason for calling function
Lpvoid lpvreserved // Reserved
)
{
Switch (fdwreason)
{
Case dll_process_attach:
Case dll_thread_attach:
MessageBox (null, text ("load DLL"), text ("load DLL"), mb_ OK );
Break;
Case dll_thread_detach:
Case dll_process_detach:
MessageBox (null, text ("Unload DLL"), text ("Unload DLL"), mb_ OK );
Break;
}
Return true;
}
DLL. Def File Content
Library DLL
Exports add @ 1
Compilation Method:
Save the preceding files as sources, makefile, and DLL. CPP, DLL. def then open the wdk compiling environment and switch to the directory where the files are stored. Execute build-C to generate a DLL. DLL file, which contains an export function add
Note: The _ stdcall call Convention is used to reference the export function of a dynamic library.