PRB: MFC Loads Wrong Resource in Extension DLL (150121)
The information in this article applies to:
- The Microsoft Foundation Classes (MFC), when used with:
- Microsoft Visual C++ for Windows, 16-bit edition 1.0
- Microsoft Visual C++ for Windows, 16-bit edition 1.5
- Microsoft Visual C++ for Windows, 16-bit edition 1.51
- Microsoft Visual C++ for Windows, 16-bit edition 1.52
- Microsoft Visual C++, 32-bit Editions 2.0
- Microsoft Visual C++, 32-bit Editions 2.1
- Microsoft Visual C++, 32-bit Editions 2.2
- Microsoft Visual C++, 32-bit Editions 4.0
- Microsoft Visual C++, 32-bit Editions 4.1
- Microsoft Visual C++, 32-bit Enterprise Edition 4.2
- Microsoft Visual C++, 32-bit Professional Edition 4.2
- Microsoft Visual C++, 32-bit Enterprise Edition 5.0
- Microsoft Visual C++, 32-bit Professional Edition 5.0
- Microsoft Visual C++, 32-bit Enterprise Edition 6.0
- Microsoft Visual C++, 32-bit Professional Edition 6.0
- Microsoft Visual C++, 32-bit Learning Edition 6.0
This article was previously published under Q150121 SYMPTOMS
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.
CAUSE
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.
RESOLUTION
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++.
STATUS
This behavior is by design.
REFERENCES
For more information on:
- Extension DLLs, see the MFC Technical Note 33 and the DLLHUSK sample.
- Resource management in projects, see Technical Note 35.
Modification Type: | Major | Last Reviewed: | 12/10/2003 |
---|
Keywords: | kbArchitecture kbBitmap kbcode kbDLL kbIcon kbprb kbResource kbString KB150121 |
---|
|