The information in this article applies to:
SYMPTOMSAn application uses the RUNTIME_CLASS macro to obtain a pointer to the CRuntimeClass associated with a class implemented in an extension DLL. When that pointer is used, an access violation or other unexpected behavior occurs. CAUSE
The CRuntimeClass data member of the class is not properly declared as
imported data. RESOLUTIONEnsure that AFX_DATA is defined as __declspec(dllimport) when including the class header file in code for the module that imports the class from the DLL. See the "Sample Code" section of this article for a detailed example. STATUSThis behavior is by design. MORE INFORMATIONThe DECLARE_DYNAMIC macro declares a CRuntimeClass object as follows:
Therefore, defining AFX_DATA as __declspec(dllimport) affects the
declaration of that object. The rest of this section describes why it is
important to do so.The RUNTIME_CLASS macro is defined in afx.h as follows:
In other words, this macro returns the address of the static CRuntimeClass
member added to the class by the DECLARE_DYNAMIC macro or one of its
cousins (DECLARE_SERIAL or DECLARE_DYNCREATE).Here is some disassembled (X86) code from an EXE that uses a class named CMyClass, which it imports from an extension DLL. The extension DLL uses its module definition file to export the members of the class, and the header file does not declare the class or any of its members as imported. m_pMyClass has just been initialized as follows:
The code fails the assertion.Here is the disassembly of the same code when the header file defines AFX_DATA as __declspec(dllimport):
This code sequence passes the assertion, as expected.Notice the difference in the way the stack is set up prior to the call to IsKindOf, especially the first item pushed. In the second case, eax is loaded with the address of an item located through the import table, while in the first case, a direct value is used. Sample Code
REFERENCES
For additional information on how to export classes from extension DLLs,
please see:
Additional query words: 2.00 2.10 3.00 3.10 4.00
Keywords : kbDLL kbMFC kbVC |
Last Reviewed: August 3, 1999 © 2000 Microsoft Corporation. All rights reserved. Terms of Use. |