Using Visual Studio 2015 to create. DLL and use. DLL

Use Visual Studio 2015 to create.dll and use.dll
In this paper, the implementation of an addition and meet function is taken as an example:
Create a DLL project:
1, File — New — Project — Win32 console application. Give it a name, like myadd. Click OK. Next, select DLL(D) for the application type and click Finish.
>
>
>
>
>
>
>
>
> You can delete it. Create a new one. CPP, name “mydll. CPP”, create a new “mydll.h”
3, write an addition and subtraction function for example; In mydll. CPP, write the following:

#include"stdafx.h"
#include"mydll.h"
int add(int a,int b)
{
    return a+b;
}

int sub(int c,int d)
{
    return c-d;
}

4. Write the following in mydll.h:

#pragma once
_declspec(dllexport)int add(int a, int b);
_declspec(dllexport)int sub(int a, int b);

5. Build — Build the solution. (select Debug X86 mode) and it will be in the project root directory (with.sln directory), under the Debug folder. Generate.dll and.lib files.

> File — New — Project — Win32 Console Application Give it a name like MyDllTest, click OK, Next, Console Application (W), Empty Project (E), Finish;
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
> Right click, add an existing item, and add mydll.h to the header file.

#include<iostream>
#include "mydll.h"
using namespace std;

int main()
{

    int ad, su;
    ad = add(100, 200);
    su = sub(10, 20);
    cout << "ad: " << ad << endl;
    cout << "su: " << su << endl;
    getchar();
    return 0;
}

5, in the project “resource file” right click, add – existing item; Select the.lib file and click OK.
6, Build, Solution, Run That’s it.

Read More: