DLL开发
来源:互联网 发布:私人摄像头直播软件 编辑:程序博客网 时间:2024/06/15 19:28
一DLL生成及设置
1.新建一个MFC extension dll工程
2.在工程下新建两个文件myfun.h,mufun.cpp
3.在.h文件中添加如下定义
#pragma once
int AFX_EXT_API MyFun1(int a);
int AFX_EXT_API MyFun2(int a,float b);
4.在.cpp文件中添加代码如下
#include "stdafx.h"
#include "myfun.h"
int MyFun1(int a)
{
CString sText;
sText.Format(L"%d",a);
AfxMessageBox(sText);
return a;
}
int MyFun2(int a,float b)
{
CString sText;
sText.Format(L"%d",a+b);
AfxMessageBox(sText);
return a;
}
5.在def文件中添加如下代码
; DynLoadDll.def : Declares the module parameters for the DLL.
LIBRARY "DynLoadDll"
EXPORTS
; Explicit exports can go here
MyFun1
MyFun2
编译
二.显示加载该dll
//程序如下,注意dll的路径问题,可以是绝对路径也可以是相对路径
typedef int ( myfun1)(int);
typedef int ( myfun2)(int,float);
myfun1* fun1;
myfun2* fun2;
HINSTANCE hMyDll = ::LoadLibrary(L"DynLoadDll.dll");
int nErr = 0;
if (hMyDll==NULL)
{
nErr = GetLastError();
}
else
{
fun1 = (myfun1*)::GetProcAddress(hMyDll,"MyFun1");
fun2 = (myfun2*)::GetProcAddress(hMyDll,"MyFun2");
if (fun1!=NULL&&fun2!=NULL)
{
fun1(10);
fun2(10,0.5);
}
}
FreeLibrary(hMyDll);
1.新建一个MFC extension dll工程
2.在工程下新建两个文件myfun.h,mufun.cpp
3.在.h文件中添加如下定义
#pragma once
int AFX_EXT_API MyFun1(int a);
int AFX_EXT_API MyFun2(int a,float b);
4.在.cpp文件中添加代码如下
#include "stdafx.h"
#include "myfun.h"
int MyFun1(int a)
{
CString sText;
sText.Format(L"%d",a);
AfxMessageBox(sText);
return a;
}
int MyFun2(int a,float b)
{
CString sText;
sText.Format(L"%d",a+b);
AfxMessageBox(sText);
return a;
}
5.在def文件中添加如下代码
; DynLoadDll.def : Declares the module parameters for the DLL.
LIBRARY "DynLoadDll"
EXPORTS
; Explicit exports can go here
MyFun1
MyFun2
编译
二.显示加载该dll
//程序如下,注意dll的路径问题,可以是绝对路径也可以是相对路径
typedef int ( myfun1)(int);
typedef int ( myfun2)(int,float);
myfun1* fun1;
myfun2* fun2;
HINSTANCE hMyDll = ::LoadLibrary(L"DynLoadDll.dll");
int nErr = 0;
if (hMyDll==NULL)
{
nErr = GetLastError();
}
else
{
fun1 = (myfun1*)::GetProcAddress(hMyDll,"MyFun1");
fun2 = (myfun2*)::GetProcAddress(hMyDll,"MyFun2");
if (fun1!=NULL&&fun2!=NULL)
{
fun1(10);
fun2(10,0.5);
}
}
FreeLibrary(hMyDll);
0 0
- DLL开发
- 学习开发DLL笔记
- DLL COM程序开发
- Dll开发基础知识
- vc开发dll
- DLL学习开发笔记
- DLL程序开发实例
- CUDA DLL 开发流程
- VS2005开发DLL工程
- 开发 PHP 扩展 DLL
- CUDA DLL 开发流程
- DLL开发笔记
- 开发 PHP 扩展 DLL
- CUDA DLL 开发流程
- VS2010开发DLL
- Delphi开发DLL常见问题
- vc++ DLL开发小结
- CUDA DLL 开发流程
- JavaWebFrame 中控制器的一些问题和测试用例
- IOS_加速计_碰撞检测_小球位置修复_dispatch_once单例
- 顺序表有关操作(查找、插入、删除)
- maven(1)
- Linux运维第9天:Linux下suid,sgid,acl,shell编程
- DLL开发
- cocos2dx 2.2.3 xcode5.0,新建mac项目报错
- Linux 内核模块开发基本知识
- CentOS 6.4 电信ADSL拨号上网网络配置
- .NET中反射机制的使用
- mave使用私有仓库
- Linux运维第9天:Linux下磁盘管理及使用挂载
- CISCO 4948进入ROMmon
- 毕业4年