Use the wdk compiling environment to compile the application build command (dynamic library program)

Source: Internet
Author: User

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.

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.