VC++速記

速記用到,怕忘的vc小知識。

條件編譯
條件編譯常見用在定義動態鏈接庫時。
在源文件中定義爲導出dllexport
在頭文件中定義爲導入dllimport
這樣的頭文件既可以用在鏈接庫項目中,
也可以直接複製到引用項目中用。
Dll.h
#ifdef DLL_API
#else
#define DLL_API extern "C" _declspec(dllimport)
#endif

DLL_API int _stdcall add(int a,int b);
DLL_API int _stdcall subtract(int a,int b);
Dll.cpp
#define DLL_API extern "C" _declspec(dllexport)
#include "Dll.h"
#include <Windows.h>
#include <stdio.h>

int _stdcall add(int a,int b)
{
    return a+b;
}

int _stdcall subtract(int a,int b)
{
    return a-b;
}
發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章