Dynamic link Library's implicit dynamic link and display dynamic link

Source: Internet
Author: User

To create a DLL project:

1#include"CustomDll.h"2#include <windows.h>3 BOOL apientry DLLMAIN (hmodule hmodule, DWORD reason_for_call, lpvoid lpreserved)4 {5     Switch(Reason_for_call)6     {7      CaseDll_process_attach:8      CaseDll_process_detach:9      CaseDll_thread_attach:Ten      CaseDll_thread_detach: One          Break; A     } -     returnTRUE; - } the intDllfuncadd (intAintb) - { -     returnA +b; -}

Create Usedll project, implicitly dynamic Link: Copy the DLL project to the Usedll project root, then use the following code

1#include <windows.h>2#include"CustomDll.h"  3#include <iostream>4 using namespacestd;5 #pragmaComment (lib, "Customdll")6 intMain ()7 {8     intc =1, B =2;9cout << Dllfuncadd (c, b) <<Endl;Ten     return 0; One}

Show Dynamic Link: Click Project in original DLL project, add new item, check module definition file (. def), then name input DLL, determine

Add the following code to the Dll.def file:

1 exports 2 Dllfuncadd

Then edit the Usedll project in the following code:

1#include <windows.h>2#include <iostream>3 using namespacestd;4typedefint(*pfnexportfunc) (intAintb);5 intMain ()6 {7 intc =1, B =2;8hmodule hmodule = LoadLibrary (L"CustomDll.dll");9 if(Hmodule! =NULL)Ten { OnePfnexportfunc Mdllfuncadd = (pfnexportfunc) GetProcAddress (hmodule,"Dllfuncadd"); A     if(Mdllfuncadd! =NULL) -     { -cout << Mdllfuncadd (c, b) <<Endl; the     } - FreeLibrary (hmodule); - } -  + return 0; -}

On the line.

Dynamic link Library's implicit dynamic link and display dynamic link

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.