//dll.h
//author: clsoeall
//time : 2006.09
////////////////////////////////////////////////////////////////////
#ifndef DLL_H_
#define DLL_H_
#define MYFIRSTDLL extern "C" __declspec( dllexport )
MYFIRSTDLL void ShowText() ;
#endif
2、然后创建dll.cpp.代码如下。
//dll.cpp
//author: closeall
//time : 2006.09
///////////////////////////////////////////////////////////////////
//#define MYFIRSTDLL extern "C" __declspec( dllexport )
#include “stdio.h”
#include "dll.h"
void ShowText()
{
printf( "This is dll export show 。 " ) ;
}
编译完成以后,就会生成一个dll.dll的文件和一个dll.lib 的文件。在使用dll.dll这个动态连接库的时候,应该把dll.h头文件包含在可执行文件中,而且还要把dll.lib连入程序。
下面的代码是使用这个动态连接库的测试程序。
//testdll.cpp
//author: closeall
//time : 2006.09
///////////////////////////////////////////////
#include <stdio.h>
#include “iostream.h”
#include "dll.h"
#pragma comment( lib, "dll.lib" )
int main()
{
ShowText() ; //这个函数是从动态连接库dll.dll中调用的
printf( "This is execute show \n" ) ;
int i ;
cin>> i ;
return 1 ; //返回真值。。
}