After checking the official Microsoft documentation Import into an application using __declspec(dllimport) and Exporting from a DLL Using __declspec(dllexport), I still don’t quite understand, so I searched for a lot of information. Below is my understanding. May I ask if my understanding is correct?
__declspec(dllimport)
is used to inform the compiler that this function or class is imported from another file and is not defined in this program.
// There is a function in library libTest called sum.
#include "libTest.h"
__declspec(dllimport) int sum(int a, int b);
int main()
{
int res = sum(a, b);
reutnr 0;
}
__declspec(dllexport)
is used to inform the compiler that this function or class is defined in this file and will be used to expose the library for use by other programs.
libTest.h
__declspec(dllexport) int sum(int a, int b)
{
return a + b;
}