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:
- Three methods of referencing DLL in Visual Studio 2015
- Visual studio 2017, OpenGL program running prompt glut32.dll missing solution
- Solution to the error “tcnative-1.dll: can’t load amd 64 bit. DLL on IA 32 bit platform”
- Start Tomcat and report an error: tcnative-1.dll: can’t load ia 32-bit. DLL on a amd 64 bit platform
- Error loading Python DLL ‘python36.dll’. LoadLibrary: The specified module could not be found.
- Windows10解决ImportError: DLL load failed: A dynamic link library (DLL) initialization routine failed
- After Android studio is installed, open a pop-up window to prompt failed to load JVM DLL XXX
- How to use it RegAsm.exe Register C in a development / production environment#/ VB.NET Developed DLL
- Detailed steps for installing Visual Studio 2010 + Intel parallel studio Xe 2013 and configuring mpich2
- Solution to the flash of visual studio 2017 running program
- Solution to flash back of visual studio 2017 running program
- R | failed to load cairo DLL
- How to solve the problem that the console window disappears in a flash after visual studio 2017 runs
- tensorflow import error: DLL load failed: The specified module could not be found (DLL load failed: The specified module could not be found)
- Configuring OpenGL in Visual Studio
- Solution to msxml3.dll error ‘80072efd’
- Solution to the problem that OpenGL can’t find glew32.dll in vs2019
- Solution to the flashback of visual studio output window
- The solution to the black window flash of running program on Visual Studio
- Solution to msxml3.dll error ‘800c0008’ the system cannot locate the resource specified