当前位置:网站首页>MFC实现资源单独Dll实现
MFC实现资源单独Dll实现
2022-04-23 05:16:00 【houxian1103】
概述
我们在开发MFC项目中,如果是一个项目还好,如果我们分为不同的项目,并且每个项目作为Dll提供,这样资源可能在每个动态库中都存储在,非常不利于管理,所以我们就想着把资源单独作为一个Dll库提供。
资源Dll的实现
创建资源Dll

创建后先进行编译,编译后,表示咱们工程没问题,下面还有一个链接选项需要设置

下面咱们就可以自己添加资源、编辑资源了。
主程序的调用设置资源动态库。
// CMultilingualDemoApp 初始化
BOOL CMultilingualDemoApp::InitInstance()
{
// 如果一个运行在 Windows XP 上的应用程序清单指定要
// 使用 ComCtl32.dll 版本 6 或更高版本来启用可视化方式,
//则需要 InitCommonControlsEx()。 否则,将无法创建窗口。
INITCOMMONCONTROLSEX InitCtrls;
InitCtrls.dwSize = sizeof(InitCtrls);
// 将它设置为包括所有要在应用程序中使用的
// 公共控件类。
InitCtrls.dwICC = ICC_WIN95_CLASSES;
InitCommonControlsEx(&InitCtrls);
CWinApp::InitInstance();
m_hLangDLL = NULL;
AfxEnableControlContainer();
// 创建 shell 管理器,以防对话框包含
// 任何 shell 树视图控件或 shell 列表视图控件。
CShellManager *pShellManager = new CShellManager;
// 激活“Windows Native”视觉管理器,以便在 MFC 控件中启用主题
CMFCVisualManager::SetDefaultManager(RUNTIME_CLASS(CMFCVisualManagerWindows));
// 标准初始化
// 如果未使用这些功能并希望减小
// 最终可执行文件的大小,则应移除下列
// 不需要的特定初始化例程
// 更改用于存储设置的注册表项
// TODO: 应适当修改该字符串,
// 例如修改为公司或组织名
SetRegistryKey(_T("应用程序向导生成的本地应用程序"));
HINSTANCE m_hLangDLL = ::LoadLibrary(_T("Resource_zh.dll"));
if(m_hLangDLL != NULL)
{
AfxSetResourceHandle(m_hLangDLL);
}
else
{
AfxMessageBox(_T("资源DLL文件加载失败!"));
exit(1);
}
到此其实就实现了资源单独动态库的实现。
题外话:
资源单独作为Dll可以成功,那么我们如果是多语言,每一个语言都可以单独的一个Dll,这样就实现了使用Dll实现多语言的支持。
下面代码是实现资源动态加载:
BOOL CMultilingualDemoDlg::ResetDialog()
{
//TODO: 处理可能已添加的附加资源
AfxOleTerm(FALSE);
if(m_hLangDLL)
{
FreeLibrary(m_hLangDLL);
}
STARTUPINFO StartupInfo={
0};
PROCESS_INFORMATION ProcessInfo;
StartupInfo.cb=sizeof(STARTUPINFO);
char Path[256];
GetModuleFileName(NULL,(LPSTR)(LPCTSTR)Path,255);
CreateProcess(NULL,(LPSTR)(LPCTSTR)Path,NULL,NULL,FALSE,0,NULL,NULL,&StartupInfo,&ProcessInfo);
return TRUE;
}
版权声明
本文为[houxian1103]所创,转载请带上原文链接,感谢
https://blog.csdn.net/houxian1103/article/details/124353092
边栏推荐
- mariadb数据库的主从复制
- 《2021多多阅读报告》发布,95后、00后图书消费潜力攀升
- Independent station operation | Facebook marketing artifact - chat robot manychat
- Define defines constants and macros, pointers and structures
- Swing display time (click once to display once)
- Deep learning notes - data expansion
- How to exit VIM
- Where, on when MySQL external connection is used
- Basic knowledge of vegetable chicken database
- At pgconf Asia Chinese technology forum, listen to Tencent cloud experts' in-depth understanding of database technology
猜你喜欢

Let the LAN group use the remote device

#define 定义常量和宏,指针和结构体

数据安全问题已成隐患,看vivo如何让“用户数据”重新披甲

低代码和无代码的注意事项

无线网怎么用手机验证码登录解决方案

Basic theory of Flink

PIP free export with path (@ file: / / /) notes

7-4 is it too fat (10 points) PTA

5 minutes to understand MySQL row column conversion

Backup MySQL database with Navicat
随机推荐
One month countdown, pgconf What are the highlights of the latest outlook of asia2021 Asian Conference?
开源规则引擎——ice:致力于解决灵活繁复的硬编码问题
Discussion on flow restriction
SQLyog的基本使用
MySQL realizes row to column SQL
Acid of MySQL transaction
The WebService interface writes and publishes calls to the WebService interface (I)
Interesting prime number problem hdu5750
Grpc long connection keepalive
[database] MySQL multi table query (I)
Flip coin (Blue Bridge Cup)
Pandas to_ SQL function pit avoidance guide "with correct code to run"
Day.js 常用方法
Chapter II project scope management of information system project manager summary
Power consumption parameters of Jinbei household mute box series
云计算与云原生 — OpenShift 的架构设计
【openh264】cmake: msopenh264-static
Independent station operation | Facebook marketing artifact - chat robot manychat
HRegionServer的详解
Minimum spanning tree -- unblocked project hdu1863