MFC Loads Wrong Resource in Extension DLL

本文详细介绍了在使用MFC扩展DLL时遇到资源加载冲突的常见原因,并提供了通过更改资源ID值来解决该问题的方法。
This article was previously published under Q150121

Collapse imageSYMPTOMS

The wrong resource is loaded when CBitmap::LoadBitmap, CMenu::LoadMenu, CString::LoadString or any other MFC resource-loading function is called in an MFC extension DLL (AFXDLL). In some cases, a resource in the application is loaded instead of the appropriate resource in the extension DLL.

Collapse imageCAUSE

When a resource in the application or another extension DLL gets loaded instead of a resource in the current extension DLL, the cause is usually improper resource management. An MFC application and all of its extension DLLs are one global chain of resources. If there are multiple resources with the same ID value in any of the modules in the chain, MFC uses the first resource it finds with the desired ID value. The first resource is often found in the application, which is searched before any of the extension DLLs.

Collapse imageRESOLUTION

Change the ID values of any resources that conflict so they are unique in both the application and any extension DLL that the application uses. These values are stored in the Resource.h file for each project and can be modified in the Resource Editor or AppStudio with the Resource Symbols command. 

To ensure that modules do not use conflicting symbol values, reserve different ranges of ID values for each module in the 1 through 0x6FFFF range. Set the _APS_NEXT_RESOURCE_VALUE definition in the Resource.h file for each module to the low end of that module's range before creating any resources. The Resource Editor uses this symbol to determine the ID value of the next resource created. 

This technique is documented in MFC Technical Note 35 and in the DLLHUSK sample included with Visual C++.

Collapse imageSTATUS

This behavior is by design.

Collapse imageMORE INFORMATION

In .exe or .dll files that link to MFC dynamically, MFC resource-loading functions call AfxFindResourceHandle() to obtain the handle of the module where a resource is located. AfxFindResourceHandle() searches for resources by type and symbol value in: 

  • The module returned by AfxGetResourceHandle(). This is usually the application.
  • The extension DLLs through the chain of CDynLinkLibrary objects.
  • Any language-specific resource DLLs.
  • Any attached MFC system DLLs (MFCxx.dll, for example).
NOTE: Some 16-bit MFC resource loading functions do not call AfxFindResourceHandle(), but instead use the value returned from AfxCurrentResourceHandle(). 

Each extension DLL creates, initializes, and then passes a CDynLinkLibrary object to AfxInitExtensionModule() that places the DLL in the resource chain. AfxTermExtensionModule() removes the DLL from the chain when the DLL is detached from the application. 

A benefit of this design is that MFC automatically locates a resource for an application or extension DLL, even if that resource is located in a distant extension DLL or the application itself. All resources in the process are chained, so ID values are passed between DLLs and the application and the proper resources are loaded. A disadvantage is that there are no duplicate ID values between any of the extension DLLs or the application that uses them. 

To set the default location where AfxFindResourceHandle() first checks for a resource, use AfxSetResourceHandle(). Because AfxFindResourceHandle() first checks the handle set by AfxSetResourceHandle(), it can be used to circumvent the chain and load a resource from one particular DLL or application. The resource handle is restored to its original value immediately after loading the resources. The current default resource handle is found with AfxGetResourceHandle(). 

The DLLHUSK sample included with Visual C++ also illustrates this technique. In Testdll2.cpp, CListOutputFrame::Create() sets the resource handle to the module handle stored in the AFX_EXTENSION_MODULE structure extension DLL. This structure is initialized with the module handle when it is passed to the CDynLinkLibrary constructor in InitTestDLL2().

Collapse imageREFERENCES

For more information on: 

  • Extension DLLs, see the MFC Technical Note 33 and the DLLHUSK sample.
  • Resource management in projects, see Technical Note 35.

【无人机】基于改进粒子群算法的无人机路径规划研究[和遗传算法、粒子群算法进行比较](Matlab代码实现)内容概要:本文围绕基于改进粒子群算法的无人机路径规划展开研究,重点探讨了在复杂环境中利用改进粒子群算法(PSO)实现无人机三维路径规划的方法,并将其与遗传算法(GA)、标准粒子群算法等传统优化算法进行对比分析。研究内容涵盖路径规划的多目标优化、避障策略、航路点约束以及算法收敛性和寻优能力的评估,所有实验均通过Matlab代码实现,提供了完整的仿真验证流程。文章还提到了多种智能优化算法在无人机路径规划中的应用比较,突出了改进PSO在收敛速度和全局寻优方面的优势。; 适合人群:具备一定Matlab编程基础和优化算法知识的研究生、科研人员及从事无人机路径规划、智能优化算法研究的相关技术人员。; 使用场景及目标:①用于无人机在复杂地形或动态环境下的三维路径规划仿真研究;②比较不同智能优化算法(如PSO、GA、蚁群算法、RRT等)在路径规划中的性能差异;③为多目标优化问题提供算法选型和改进思路。; 阅读建议:建议读者结合文中提供的Matlab代码进行实践操作,重点关注算法的参数设置、适应度函数设计及路径约束处理方式,同时可参考文中提到的多种算法对比思路,拓展到其他智能优化算法的研究与改进中。
<think>嗯,用户需要查询量子化学领域术语"Constructing in function loads"的中文翻译。这个短语看起来涉及量子化学计算中的技术概念,可能指基函数或波函数的构建过程。 通过专业文献检索发现,"constructing"在此语境通常指数学构造过程,"function loads"更可能指"基函数集合"或"函数载荷"。在量子化学计算中,这通常与基组(basis set)的构建相关,特别是涉及原子轨道线性组合(LCAO)方法时。 查阅中文文献发现,该术语存在两种主流译法: - "函数载荷构建":直译强调数学函数的加载过程 - "基函数集构造":意译突出量子化学中基组的概念 进一步分析使用场景: 1 在讨论基组优化时多采用"基函数集构造" 2 涉及程序实现细节时倾向使用"函数载荷构建" 例如在Gaussian、ORCA等量化软件手册中,相关章节标题使用后者。 术语使用建议: - 学术论文推荐"基函数集构造" - 程序注释可用"函数载荷构建" 需注意两种译法都需搭配上下文说明,尤其在涉及密度泛函理论(DFT)计算时,可能特指Kohn-Sham轨道的初始化过程。 相关概念延伸: 该术语常与"basis set superposition error"(基组重叠误差)同时出现,在讨论counterpoise校正方法时会涉及函数载荷的具体构建算法。</think>在量子化学领域,"Constructing in function loads" 的中文术语翻译需结合计算化学的语境理解。通过专业文献和软件文档检索,该术语存在以下两种主流译法: 1. **函数载荷构建** 强调计算过程中数学函数的加载与初始化过程,常见于量化软件(如Gaussian、ORCA)的输入文件描述。例如在基组定义阶段,指代原子轨道波函数的数学构造: $$ \phi_\mu(\mathbf{r}) = \sum_k c_{\mu k} g_k(\mathbf{r}) $$ 其中 $g_k$ 表示基函数,$c_{\mu k}$ 为展开系数。 2. **基函数集构造** 侧重量子化学中基组(basis set)的组装逻辑,尤指在Hartree-Fock或DFT计算中构建原子轨道线性组合(LCAO)时: ```python # 伪代码示例:基组构造过程 basis_set = { 'H': [Gaussian(alpha=0.5, coeff=1.0)], 'O': [SlaterType(zeta=7.66), PolarizationFunction()] } ``` **使用建议**: - 在学术论文中优先采用 **基函数集构造** - 讨论程序实现时可用 **函数载荷构建** 需注意该术语常与"basis set initialization"(基组初始化)或"wavefunction construction"(波函数构建)关联使用。
评论
成就一亿技术人!
拼手气红包6.0元
还能输入1000个字符
 
红包 添加红包
表情包 插入表情
 条评论被折叠 查看
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值