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;
}
posted @ 2012-09-12 19:30  大气象  阅读(1133)  评论(7编辑  收藏  举报
http://www.tianqiweiqi.com