手头上有个自己写的类,比较复杂,请问怎么封装到DLL里面去

teli_eurydice 2005-05-24 10:05:39
这个类是基类,继承自CObject,MFC 调用,会有其它类继承这个基类
...全文
150 8 打赏 收藏 转发到动态 举报
写回复
用AI写文章
8 条回复
切换为时间正序
请发表友善的回复…
发表回复
xyw2278 2005-05-25
  • 打赏
  • 举报
回复
//给你一个最简单的例子:用的时候,先用向导生成一个MFC Dll(扩展MFC DLL):

// MfcDll.cpp : Defines the initialization routines for the DLL.
//

#include "stdafx.h"
#include <afxdllx.h>

#ifdef _DEBUG
#define new DEBUG_NEW
#undef THIS_FILE
static char THIS_FILE[] = __FILE__;
#endif




static AFX_EXTENSION_MODULE MfcDllDLL = { NULL, NULL };

extern "C" int APIENTRY
DllMain(HINSTANCE hInstance, DWORD dwReason, LPVOID lpReserved)
{
// Remove this if you use lpReserved
UNREFERENCED_PARAMETER(lpReserved);

if (dwReason == DLL_PROCESS_ATTACH)
{
TRACE0("MFCDLL.DLL Initializing!\n");

// Extension DLL one-time initialization
if (!AfxInitExtensionModule(MfcDllDLL, hInstance))
return 0;

// Insert this DLL into the resource chain
// NOTE: If this Extension DLL is being implicitly linked to by
// an MFC Regular DLL (such as an ActiveX Control)
// instead of an MFC application, then you will want to
// remove this line from DllMain and put it in a separate
// function exported from this Extension DLL. The Regular DLL
// that uses this Extension DLL should then explicitly call that
// function to initialize this Extension DLL. Otherwise,
// the CDynLinkLibrary object will not be attached to the
// Regular DLL's resource chain, and serious problems will
// result.

new CDynLinkLibrary(MfcDllDLL);
}
else if (dwReason == DLL_PROCESS_DETACH)
{
TRACE0("MFCDLL.DLL Terminating!\n");
// Terminate the library before destructors are called
AfxTermExtensionModule(MfcDllDLL);
}
return 1; // ok
}




// TestClass.cpp: implementation of the CTestClass class.
//
//////////////////////////////////////////////////////////////////////

#include "stdafx.h"
#include "TestClass.h"

#ifdef _DEBUG
#undef THIS_FILE
static char THIS_FILE[]=__FILE__;
#define new DEBUG_NEW
#endif

//////////////////////////////////////////////////////////////////////
// Construction/Destruction
//////////////////////////////////////////////////////////////////////

CTestClass::CTestClass()
{

}

CTestClass::~CTestClass()
{

}

void CTestClass::Print()
{
AfxMessageBox("Test MFC DLL!\n");
}



// TestClass.h: interface for the CTestClass class.
//
//////////////////////////////////////////////////////////////////////

#if !defined(AFX_TESTCLASS_H__47D06873_54D9_4348_9156_7CF9F657A180__INCLUDED_)
#define AFX_TESTCLASS_H__47D06873_54D9_4348_9156_7CF9F657A180__INCLUDED_

#if _MSC_VER > 1000
#pragma once
#endif // _MSC_VER > 1000

class _declspec(dllexport) CTestClass
{
public:
void Print();
CTestClass();
virtual ~CTestClass();
};

#endif // !defined(AFX_TESTCLASS_H__47D06873_54D9_4348_9156_7CF9F657A180__INCLUDED_)


//总共3个文件,你将向导生成的文件用这边第一个文件内容替换掉,加入其他两个文件,编译:
//调用的时候:将.DLL文件放入调用程序的exe所在目录或系统目录
//将.lib文件和TestClass.h文件放在调用程序得项目文件夹即和其它头文件在同一个目录
//然后
//
#include "TestClass.h"
//就可以用了
teli_eurydice 2005-05-25
  • 打赏
  • 举报
回复
UP
teli_eurydice 2005-05-25
  • 打赏
  • 举报
回复
up
caesar22 2005-05-25
  • 打赏
  • 举报
回复
必须使用扩展的MFC DLL了。

使用AFX_EXT修饰你的类就可以
teli_eurydice 2005-05-24
  • 打赏
  • 举报
回复
有例子给我看看吗,对这个不是很了解阿,郁闷,呵呵
byf2002 2005-05-24
  • 打赏
  • 举报
回复
导出类就行了
teli_eurydice 2005-05-24
  • 打赏
  • 举报
回复
不要太复杂,呵呵
jerry 2005-05-24
  • 打赏
  • 举报
回复
那只能做成 扩展 MFC DLL

15,471

社区成员

发帖
与我相关
我的任务
社区描述
VC/MFC 进程/线程/DLL
社区管理员
  • 进程/线程/DLL社区
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧