Creation and use of dll (for personal use)

Step1: Create dynamic link library

Step2: Keep the original file unchanged, add your own .h file, and add the following code under the file

#define DATAEXCHANGEDLL_API __declspec(dllexport)
#include <cstring>
#include <cmath>
#include <algorithm>
#include<iostream>
#include<stdio.h>//包含一些必要的头文件
using namespace std;
extern "C"

{  

 DATAEXCHANGEDLL_API FunctionName;//此处添加函数名

}

Step3: Create a .cpp file with the same name as the .h file, and add the "pch.h" header file (it comes with it) and the header file you created yourself, and then just write the function to implement it.

Step4: After writing the function and completing the task, click "Generate" and "Generate Solution" to generate .dll and .lib files.

Step5: If you want to use the dll file compiled by yourself, you need to put the .h file you created and the generated .dll and .lib files in the directory of the project you need to use; (for "dllexport" in the .h file Rewritten to "dllimport", but it seems that it can be used without changing it). If you use VS, add an existing item to the resource file, add the .lib file to it, and then you can use it.

Attention: If the function uses default parameters, the parameter size needs to be stated in the .h file or .cpp file (you only need to state it in one file, and the other file only needs to declare this formal parameter)

Guess you like

Origin blog.csdn.net/yoonaanna/article/details/127163536