dll导出函数
#include<stdio.h>
//引用库的时候必须包含两个文件
#include"../exportDll2/exportDll2.h"//1.头文件
int main()
{
int result;
result = Add(1, 2);
printf("%d", result);
return 0;
}
报错:

修改:
#include<stdio.h>
//引用库的时候必须包含两个文件
#include"../exportDll2/exportDll2.h"//1.引用头文件,函数声明
#pragma comment(lib,"../Debug/EXPORTDLL2.lib")//2.引用库文件,引用静态库的方式, 函数实现
int main()
{
int result;
result = Add(1, 2);
printf("%d", result);
return 0;
}
源文件:
exportDll2.h
// The following ifdef block is the standard way of creating macros which make exporting // from a DLL simpler. All files within this DLL are compiled with the EXPORTDLL2_EXPORTS // symbol defined on the command line. This symbol should not be defined on any project // that uses this DLL. This way any other project whose source files include this file see // EXPORTDLL2_API functions as being imported from a DLL, whereas this DLL sees symbols // defined with this macro as being exported. #ifdef EXPORTDLL2_EXPORTS #define EXPORTDLL2_API __declspec(dllexport) #else #define EXPORTDLL2_API __declspec(dllimport) #endif EXPORTDLL2_API int fnexportDll2(void); EXPORTDLL2_API int Add(int a, int b);
eportDll2.cpp
// exportDll2.cpp : Defines the exported functions for the DLL.
//
#include "pch.h"
#include "framework.h"
#include "exportDll2.h"
// This is an example of an exported function.
EXPORTDLL2_API int fnexportDll2(void)
{
return 0;
}
EXPORTDLL2_API int Add(int a, int b)
{
return a+b;
}
创建具有导出项的dll文件时,在Debug中会生成两个文件,一个是dll文件,一个是lib文件

系统自动将库文件名改为大写

浙公网安备 33010602011771号