C++动态链接库的调用

BuildDll.h:
//防止重复链接
#ifndef BUILDDLL_H_
#define BUILDDLL_H_

//若有该宏,则为输出,否则为输入
#ifdef BUILDDLL_BUILD_EXPORTS
#    define BUILDDLL_EXPORTS __declspec(dllexport)
#else
#    define BUILDDLL_EXPORTS __declspec(dllimport)
#endif

BUILDDLL_EXPORTS int a;
BUILDDLL_EXPORTS void MyFunc();

#endif

注意,应在Properties->C/C++->Preprocessor->Preprocessor Definitions中添加BUILDDLL_BUILD_EXPORTS定义

有关输出路径请自行设置。

BuildDll.cpp:
#include "BuildDll.h"
BUILDDLL_EXPORTS void MyFunc()
{
    a=1;
}

猜你喜欢

转载自blog.csdn.net/qq_34329383/article/details/80863923