VC++ DLL创建与使用_v2

1 DLL类型:有三种
         Win32DLL: 不使用MFC库,可被任何程序使用。
         MFC Regular DLL 使用MFC库,与MFC库静态或动态连接,可被任何程序使用。
         MFC Extension DLL ,与MFC动态联合编译,只能被MFC程序使用。
   三种DLL的异同:

2 DLL的创建与调用
    2.1 Win32DLL的创建
          两种方法:A通过.h文件定义要输出的资源 B通过.def文件定义要输出的资源
     2.1.1用.h文件定义要输出的资源:
        例子:
        win32dll_h.h
              extern "C" __declspec(dllexport) int MaxNum(int a, int b);
         win32dll_h.cpp
          DllMain(HANDLE hModule, DWORD  ul_reason_for_call, LPVOID lpReserved)
         {
               switch(ul_reason_for_call)
               {
                case DLL_PROCESS_ATTACH:
                case DLL_THREAD_ATTACH:
                case DLL_THREAD_DETACH:
                case DLL_PROCESS_DETACH:
                break;
                }
                return TRUE;
         } 

         int MaxNum(int a, int b)
        {
              if(a>b) return a;
              else return b;
        }
    2.1.2用.def文件定义要输出的资源
       w32dll_def.def
             ; ; is the notes symbol in a def file
             LIBRARY W32DLL_DEF

             DESCRIPTION  "W32DLL_DEF Windows Dynamic Link Library"

             ; Function name must equal  the name in .cpp file and sensitive to 大小写
             EXPORTS
                    MinNum
       W32dll_def.cpp
                     int MaxNum(int a, int b)
                     {
                       if(a<b) return a;
                      else return b;
                     }
    2.1.3 隐式调用W32DLL中的函数
           相同的部分:将.lib文件和.dll文件copy到要调用的程序的目录下或系统目录(/windows等)下
           不同的部分:是调用前的声明。
            .h创建的dll: extern "C" __declspec(dllimport) int MaxNum(int a, int b);
            .def创建的dll:                 __declspec(dllimport) int MaxNum(int a, int b);

                                      不要前面的extern "C"
   2.2 MFC Regular DLL的创建

  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 1
    评论
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值