MyDll.h

#pragma once

#ifdef _MYDLL_EXPORT

#define DLL_API _declspec(dllexport)

#else

#define DLL_API _declspec(dllimport)

#endif


DLL_API int Add(int, int);

 

MyDll.cpp

#include "MyDll.h"

int Add(int a, int b)
{
    return (a + b);
}

注意:工程设置里预处理器命令加上_MYDLL_EXPORT

编译生成.dll和.lib文件.

 

二.使用动态链接库.

test.cpp

#include "stdafx.h"
#include "MyDll.h"


int _tmain(int argc, _TCHAR* argv[])
{
    printf("10+5=%d\n", Add(10, 5));
    return 0;
}

工程设置 

C/C++ => 常规 => 附加包含目录:MyDll.h所在目录

链接器=> 常规 => 附加库目录:MyDll.lib所在目录

链接器=>输入=>附加依赖项:MyDll.lib

 

相关文章:

  • 2021-06-04
  • 2021-07-31
  • 2021-08-11
  • 2021-10-12
  • 2021-05-17
  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
猜你喜欢
  • 2021-07-04
  • 2022-01-05
  • 2022-12-23
  • 2021-07-29
  • 2021-12-03
  • 2022-12-23
相关资源
相似解决方案