标签:嵌入式系统开发,嵌入式开发,http://www.5idzw.com
如何用vc编写dll文件,http://www.5idzw.com
隐式调用不需要调用LoadLibrary()和FreeLibrary().
由此看来,隐式说明调用的方法比较简单,但DLL改变后,应用程序
须从新编译。并且,所有所调用的DLL在应用程序加载的同时被加载到内
存中,但应用程序调用的DLL比较多时,装入的过程十分慢。隐式的调用
则在应用程序不知道所要装入的DLL或隐式调用不成功,此时,允许用户
指定所要加载的动态连接库,比较灵活
发信人: dragon (龙), 信区: VC
标 题: 关于VC中的DLL的编程[3]
Regular DLL能够被所有支持DLL技术的语言所编写的应用程序
所调用。在这种动态连接库中,它必须有一个从CWinApp继承下来的
类,DllMain函数被MFC所提供,不用自己显式的写出来。下面是一个
例子:
// MyRegularDll.h:main header file for the MYREGULARDLL DLL
#include "resource.h" // main symbols
class CMyRegularDllApp : public CWinApp
{
public:
CMyRegularDllApp();
// Overrides
// ClassWizard generated virtual function overrides
//{{AFX_VIRTUAL(CMyRegularDllApp)
//}}AFX_VIRTUAL
//{{AFX_MSG(CMyRegularDllApp)
// NOTE - the ClassWizard will add and
// remove member functions here.
// DO NOT EDIT what you see in these blocks
// of generated code !
//}}AFX_MSG
DECLARE_MESSAGE_MAP()
};
//MyRegularDll.cpp:Defines the initialization routines for the DLL.
//
#include "stdafx.h"
#include "MyRegularDll.h"
// Note!
//
// If this DLL is dynamically linked against the MFC
// DLLs, any functions exported from this DLL which
// call into MFC must have the AFX_MANAGE_STATE macro
// added at the very beginning of the function.
//
// For example:
//
// extern "C" BOOL PASCAL EXPORT ExportedFunction()
// {
// AFX_MANAGE_STATE(AfxGetStaticModuleState());
// // normal function body here
// }
//
// It is very important that this macro appear in each
// function, prior to any calls into MFC. This means that
// it must appear as the first statement within the
// function, even before any object variable declarations
// as their constructors may generate calls into the MFC
// DLL.
BEGIN_MESSAGE_MAP(CMyRegularDllApp, CWinApp)
//{{AFX_MSG_MAP(CMyRegularDllApp)
// NOTE - the ClassWizard will add
// and remove mapping macros here.
// DO NOT EDIT what you see in these blocks
END_MESSAGE_MAP()
////////////////////////////////////////////////////////////
// CMyRegularDllApp construction
CMyRegularDllApp::CMyRegularDllApp()
{
// TOD add construction code here,
// Place all significant initialization in InitInstance
}
以上是AppWizard产生的含有主要代码的两个文件,各位可从中
看出和Non-MFC Dlls的区别。但要注意上面的AppWizard的提醒啊。
发信人: dragon (龙), 信区: VC
标 题: 关于VC中的DLL的编程[4]
发信站: 饮水思源站 (Thu Mar 25 00:46:22 1999) , 站内信件
这次要讲的是最后一种动态连接库:Extension Dlls.再次说明,
Extension Dll只被用MFC类库所编写的应用程序所调用.在这种动态
连接库中,你可以从MFC继承你所想要的、更适于你自己用的类,并
把它提供给你的应用程序。你也可随意的给你的应用程序提供MFC或
MFC继承类的对象指针。
Extension DLLs 和Regular DLLs不一样,它没有一个从CWinApp
继承而来的类的对象,所以,你必须为自己DllMain函数添加初始化
代码和结束代码.如下:
#include "stdafx.h"
#include
static AFX_EXTENSION_MODULE PROJNAMEDLL = { NULL, NULL };
extern "C" int APIENTRY
DllMain(HINSTANCE hInstance, DWORD dwReason, LPVOID lpReserved)
{
if (dwReason == DLL_PROCESS_ATTACH)
{
TRACE0("PROJNAME.DLL Initializing!\n");
// Extension DLL one-time initialization
AfxInitExtensionModule(PROJNAMEDLL,
hInstance);
// Insert this DLL into the resource chain
new CDynLinkLibrary(Dll3DLL);
}
else if (dwReason == DLL_PROCESS_DETACH)
{
TRACE0("PROJNAME.DLL Terminating!\n");
}
return 1; // ok
}
在上面代码中AfxInitExtensionMoudle函数捕捉此动态库模块
用.
在初始化的时NEW一个CDynLinkLibrary对象的目的在于:它
能是Extension DLL想应用程序输出CRuntimeClass对象或资源.
如果此动态连接库被显式的调用,还必须在DLL_PROCESS_DETACH
选择项的执行代码上调用AfxTermEXtensonModule,这保证了当调
用进程与动态连接库分离是正确清理内存中的动态库模块。如果是
隐式的被调用,则此步不是必须的了。,如何用vc编写dll文件
隐式调用不需要调用LoadLibrary()和FreeLibrary().
由此看来,隐式说明调用的方法比较简单,但DLL改变后,应用程序
须从新编译。并且,所有所调用的DLL在应用程序加载的同时被加载到内
存中,但应用程序调用的DLL比较多时,装入的过程十分慢。隐式的调用
则在应用程序不知道所要装入的DLL或隐式调用不成功,此时,允许用户
指定所要加载的动态连接库,比较灵活
发信人: dragon (龙), 信区: VC
标 题: 关于VC中的DLL的编程[3]
Regular DLL能够被所有支持DLL技术的语言所编写的应用程序
所调用。在这种动态连接库中,它必须有一个从CWinApp继承下来的
类,DllMain函数被MFC所提供,不用自己显式的写出来。下面是一个
例子:
// MyRegularDll.h:main header file for the MYREGULARDLL DLL
#include "resource.h" // main symbols
class CMyRegularDllApp : public CWinApp
{
public:
CMyRegularDllApp();
// Overrides
// ClassWizard generated virtual function overrides
//{{AFX_VIRTUAL(CMyRegularDllApp)
//}}AFX_VIRTUAL
//{{AFX_MSG(CMyRegularDllApp)
// NOTE - the ClassWizard will add and
// remove member functions here.
// DO NOT EDIT what you see in these blocks
// of generated code !
//}}AFX_MSG
DECLARE_MESSAGE_MAP()
};
//MyRegularDll.cpp:Defines the initialization routines for the DLL.
//
#include "stdafx.h"
#include "MyRegularDll.h"
// Note!
//
// If this DLL is dynamically linked against the MFC
// DLLs, any functions exported from this DLL which
// call into MFC must have the AFX_MANAGE_STATE macro
// added at the very beginning of the function.
//
// For example:
//
// extern "C" BOOL PASCAL EXPORT ExportedFunction()
// {
// AFX_MANAGE_STATE(AfxGetStaticModuleState());
// // normal function body here
// }
//
// It is very important that this macro appear in each
// function, prior to any calls into MFC. This means that
// it must appear as the first statement within the
// function, even before any object variable declarations
// as their constructors may generate calls into the MFC
// DLL.
BEGIN_MESSAGE_MAP(CMyRegularDllApp, CWinApp)
//{{AFX_MSG_MAP(CMyRegularDllApp)
// NOTE - the ClassWizard will add
// and remove mapping macros here.
// DO NOT EDIT what you see in these blocks
END_MESSAGE_MAP()
////////////////////////////////////////////////////////////
// CMyRegularDllApp construction
CMyRegularDllApp::CMyRegularDllApp()
{
// TOD add construction code here,
// Place all significant initialization in InitInstance
}
以上是AppWizard产生的含有主要代码的两个文件,各位可从中
看出和Non-MFC Dlls的区别。但要注意上面的AppWizard的提醒啊。
发信人: dragon (龙), 信区: VC
标 题: 关于VC中的DLL的编程[4]
发信站: 饮水思源站 (Thu Mar 25 00:46:22 1999) , 站内信件
这次要讲的是最后一种动态连接库:Extension Dlls.再次说明,
Extension Dll只被用MFC类库所编写的应用程序所调用.在这种动态
连接库中,你可以从MFC继承你所想要的、更适于你自己用的类,并
把它提供给你的应用程序。你也可随意的给你的应用程序提供MFC或
MFC继承类的对象指针。
Extension DLLs 和Regular DLLs不一样,它没有一个从CWinApp
继承而来的类的对象,所以,你必须为自己DllMain函数添加初始化
代码和结束代码.如下:
#include "stdafx.h"
#include
static AFX_EXTENSION_MODULE PROJNAMEDLL = { NULL, NULL };
extern "C" int APIENTRY
DllMain(HINSTANCE hInstance, DWORD dwReason, LPVOID lpReserved)
{
if (dwReason == DLL_PROCESS_ATTACH)
{
TRACE0("PROJNAME.DLL Initializing!\n");
// Extension DLL one-time initialization
AfxInitExtensionModule(PROJNAMEDLL,
hInstance);
// Insert this DLL into the resource chain
new CDynLinkLibrary(Dll3DLL);
}
else if (dwReason == DLL_PROCESS_DETACH)
{
TRACE0("PROJNAME.DLL Terminating!\n");
}
return 1; // ok
}
在上面代码中AfxInitExtensionMoudle函数捕捉此动态库模块
用.
在初始化的时NEW一个CDynLinkLibrary对象的目的在于:它
能是Extension DLL想应用程序输出CRuntimeClass对象或资源.
如果此动态连接库被显式的调用,还必须在DLL_PROCESS_DETACH
选择项的执行代码上调用AfxTermEXtensonModule,这保证了当调
用进程与动态连接库分离是正确清理内存中的动态库模块。如果是
隐式的被调用,则此步不是必须的了。,如何用vc编写dll文件
上一篇:如何用pb编写dll文件