COM学习散记(2) DLL例子

放个DLL小例子

dll.h

#ifdef DLL_API
#else
#define DLL_API _declspec(dllimport)
#endif


extern"C"  DLL_API   int add(int a,int b);
DLL_API  int subtract(int a,int b);

 

dll.cpp

#define DLL_API _declspec(dllexport)
#include "dll.h"
#include <stdio.h>


extern"C"  _declspec(dllexport) int  add(int a , int b){

 return a+b;
}
_declspec(dllexport) int  subtract(int a,int b){

 return a-b;
}

 

TestDLL.cpp

#pragma comment(lib,"DLL.lib")
#include "D:/MyFile/My Documents/Visual Studio 2005/Projects/TestDLL/DLL/dll.h"
#include <string>


void  main(){

 int aa=10;
 int bb=6;
 add(aa,bb);

 
 printf("<aa +  bb>  is %d     :::/n", add(aa,bb));
 printf("<aa -  bb>  is %d      :::/n", subtract(aa,bb));

    char ccc[256]="";
 gets(ccc);      //后面这两句是为了定主控制台,方便看结果的.

 

好了,我刚调试过的

VS2005就可以.

你可能感兴趣的:(String,api,dll)