Windows writes dynamic-link library DLLs

Source: Internet
Author: User

1. In the VC new Win32 Console project, the project calls the dynamic link library My.dll in the function add, implementation of the addition, the code is as follows

#include <stdio.h> #include <windows.h>typedef int (*lpaddfun) (int, int);//macro defines function pointer type int main (int argc, Char *argv[]) {    hinstance hdll;//dll handle    lpaddfun addfun;//function pointer    hdll = LoadLibrary ("My.dll");//Load Library    if (hdll ! = NULL)    {        Addfun = (lpaddfun) GetProcAddress (hDLL, "add");//Get the Add function pointer        if (addfun! = NULL)        {            int result = Addfun (2, 3);            printf ("%d\n", result);        }        FreeLibrary (hDLL);    }    return 0;}

2. Create a new dynamic link library in VC My, which has an addition function add, the code is as follows

extern "C" __declspec (dllexport) int add (int, int);//export library function addint Add (int a, int b) {return a + B;}
This DLL can be called by putting the compiled DLL of the project into the same directory as the console project in 1.

Windows writes dynamic-link library DLLs

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.