轉載:https://blog.csdn.net/gaofeidongdong/article/details/7781345
在工程屬性中 預編譯宏中加上 DLL_EXPORT
為了減少使用dll時候的設置或者代碼編寫,把dll.h修改一下:
#ifndef DLL_EXPORT
#define DECLDIR __declspec(dllimport)
#else
#define DECLDIR __declspec(dllexport)
#endif
dll實現代碼:
#include "stdafx.h"
#include <iostream>
#define DLL_EXPORT //先定義宏
#include "dll.h"//這個頭文件必須在#define DLL_EXPORT后面
extern "C"{
DECLDIR int Add( int a, int b )
{
return( a + b );
}
DECLDIR void Function( void )
{
std::cout << "DLL Called!" << std::endl;
}
}
這樣編譯后,使用dll的工程中就不需要定義和dll相關的宏了
————————————————
版權聲明:本文為CSDN博主「fisher」的原創文章,遵循CC 4.0 BY-SA版權協議,轉載請附上原文出處鏈接及本聲明。
原文鏈接:https://blog.csdn.net/gaofeidongdong/article/details/7781345