当前位置:网站首页>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
边栏推荐
- MySQL realizes row to column SQL
- Basic concepts of multithreading (concurrency and parallelism, threads and processes) and entry cases
- Flip coin (Blue Bridge Cup)
- [2022 ICLR] Pyramid: low complexity pyramid attention for long range spatiotemporal sequence modeling and prediction
- Uglifyjs compress JS
- Simple application of parallel search set (red alarm)
- Publish your own wheel - pypi packaging upload practice
- Detailed explanation of concurrent topics
- Backup MySQL database with Navicat
- configmap
猜你喜欢
Independent station operation | Facebook marketing artifact - chat robot manychat
Servlet3 0 + event driven for high performance long polling
《2021多多阅读报告》发布,95后、00后图书消费潜力攀升
At pgconf Asia Chinese technology forum, listen to Tencent cloud experts' in-depth understanding of database technology
The applet calls the function of scanning QR code and jumps to the path specified by QR code
Nacos source code startup error report solution
[2021] Spatio-Temporal Graph Contrastive Learning
项目经理值得一试的思维方式:项目成功方程式
Let the LAN group use the remote device
Simple application of parallel search set (red alarm)
随机推荐
Machine learning - linear regression
青岛敏捷之旅,来了!
【openh264】cmake: msopenh264-static
Jupyter notebook crawling web pages
MySQL views the SQL statement details executed by the optimizer
[database] MySQL multi table query (I)
Using MySQL with Oracle
2022年最热门的招聘技术技能是什么,您绝对想不到
DevOps生命周期,你想知道的全都在这里了!
At pgconf Asia Chinese technology forum, listen to Tencent cloud experts' in-depth understanding of database technology
Grpc long connection keepalive
Mairadb数据库基本操作之数据管理
Various ways of writing timed tasks of small programs
MySQL uses or to query SQL, and SQL execution is very slow
退出vim的方法
项目经理值得一试的思维方式:项目成功方程式
即将毕业的大学生找技术开发工作的焦虑根源
Nacos source code startup error report solution
The WebService interface writes and publishes calls to the WebService interface (2)
Cross border e-commerce | Facebook and instagram: which social media is more suitable for you?