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.
p>
#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:
- Installation failed with message Invalid File
- How to solve the error after Java importing project
- Environment configuration at the beginning of OpenCV + vs2015
- Vs2017 compiles pcl1.8.1 with vtk8.0 and uses qt5.9.5
- Configuring OpenGL in Visual Studio
- Installation failed with message Invalid File:
- [VTK] vtk8.2.0 + vs2015 + win10 compilation and configuration
- Why does the result screen flash when visual studio runs the program?
- Vtk8.2.0 (32bit + 64bit) compilation and installation test (win10 + vs2017 + Qt5)
- Configure OpenGL in CodeBlocks
- Syntax error, insert “Finally” to complete TryStatem in Myeclipse in Java-
- Three methods of how to remove the flashback of running result box in VS
- The perfect solution of VS2010 console program running in a flash
- Problem solving – vs debugging window flash solution
- VS2010 debugging window flash solution
- Error in the project tag in the POM file of Maven project: failure to transfer
- How to solve the problem that the console window disappears in a flash after visual studio 2017 runs
- [OpenGL · error] visual studio 2019 reports an error. It is an external symbol gladloadglloader that cannot be parsed. This symbol is referenced in the function main
- Unhandled exception at 0x00000000: 0xc0000005: access violation at position 0x0000000000
- Configuring OpenGL environment with code blocks16.0 in Windows 10