MFC rule DLL and extension DLL

Source: Internet
Author: User
1. MFC rule dll mfc rule dll can be used inside the DLL, but the interface with the application cannot be MFC. It can be used by all applications that support DLL programming languages, including those created using MFC. This dynamic link library contains a class inherited from cwinapp, And the dllmain function is also hidden. Rule dll contains two classes: static link to MFC and dynamic connection to MFC. The static link between the rule DLL and the MFC on the MFC is generated directly in. DLL, the resource handle of the DLL is used when the DLL is called; the rule DLL dynamically linked to the MFC can be dynamically linked to the DLL of the MFC and the extension DLL of the MFC at the same time as the application that uses it. At this time, MFC uses the resource handle of the primary application to load the resource template. In this way, if the primary application and DLL have the same resource ID, a problem occurs. In this case, the module conversion is required, in order to make the right home resource. 1. afx_manage_state (inflow () is used as the first statement of the interface to convert the module status. afx_moudle_state * afxapi returns the status of the current module, afx_manage_state (afx_moudle_state * pmoudlestate ), this macro is used to set the pmoudlestate to the current module state. When the macro scope ends, that is, it leaves the scope of the object pointed to on the stack by pmoudlestate, afx_moudle_state destructor to restore the module status; 2. afxgetresourcehandle () // obtain the module handle currently in use by the program, afxsetresourcehandle () // set the module handle required by the program, convert the module status at the beginning of the interface function, and hinstance old_hinsta NCE = afxgetresourcehandle (); afxsetresourcehandle (the handle of the current DLL, you can use theapp. m_hinstance); followed by the rest of the function, ending with afxsetresourcehandle (old_hinstance); converting the module status again; this method can be used in DLL, it can also be used after the application calls the DLL function; 2. the extension DLL of MFC refers to the extension of MFC. The extension DLL of MFC is the same as that of MFC, in addition to MFC extension DLL, the interface between the extension DLL of MFC and the application can also be MFC. The extension DLL of MFC is generally used to enhance the function of MFC, the extended DLL of the MFC generated using the VC ++ wizard automatically generates the dllmain () function. DLL export functions extended by MFC. the variables are similar to others. For export classes, add afx_ext_class before the Declaration class. In the DLL header file Afx_ext_classThe keyword is added to the class declaration as follows: Class afx_ext_class cmyclass: Public cdocument {// <body of class >}; when preprocessing is defined _ AfxdllAnd _ AfxextThe macro is defined _ Declspec (dllexport). However, when _ AfxdllBut Not Defined _ AfxextThe macro is defined _ Declspec (dllimport). Pre-processor symbol after Definition _ AfxdllIndicates that the shared MFC version is being used by the target executable file (DLL or application. When _ AfxdllAnd _ AfxextThis indicates that the target executable file is an extension DLL. This article from http://yanguohong0925.blog.163.com/blog/static/928698420104129560808/

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.