VC 6.0 创建win32 动态库
1、打开VC 6.0 新建一个工作区 如下图:

2、右击添加工程到工作空间

3、弹出了 添加工程的界面 选择win 32动态库 根据图片操作:

4、单机确定之后:

5、工程建好了:展开头文件和源文件 目录->

6、添加头文件到项目

7、编辑头文件 这个头文件没有任何代码 MyDLL.h 添加代码:
//----------------------------------------------------------
#ifndef MYDLL_H
#define MYDLL_H
extern "C" int __declspec(dllexport) add(int a,int b);
#endif
//----------------------------------------------------------

8、然后在MyDLL.cpp中添加实现功能:
//----------------------------------------------------------
#include "stdafx.h"
BOOL APIENTRY DllMain( HANDLE hModule,
DWORD ul_reason_for_call,
LPVOID lpReserved
)
{
return TRUE;
}
int add(int a, int b)
{
return a + b;
}
//----------------------------------------------------------

9、按 F7 编译

10、调用这个动态库 添加MFC 对话框程序到 这个工作空间

11、创建MFC对话框

12、创建对话框程序

13、13

14、编辑代码14

15、代码
// TODO: Add extra validation here
HINSTANCE hDllInst;
typedef int (*lpAddFun)(int ,int );
lpAddFun m_add;
hDllInst = LoadLibrary( "F:\\WorkProject\\LibraryDemo\\MyDLL\\Debug\\MyDLL.dll"); //DLL的路径绝对值 路径要用\\
if (hDllInst != NULL)
{
m_add = (lpAddFun)GetProcAddress (hDllInst, "add");
}
CString str;
if (m_add != NULL)
{
int aa = m_add( 1,1 ); //调用 add 这个函数
str.Format("1 + 1 = %d",aa);
::MessageBox(NULL,str,"提示",MB_OK);
}
//CDialog::OnOK();

16、设置为活动工程

17、编译 + 运行

18、演示结束
