Analysis of types and usage of DLL in C ++

Source: Internet
Author: User

A. Non-mfc dll: Refers to a DLL written directly in C language without the use of the MFC class library structure. The output function generally uses the Standard C interface, applications that can be compiled by non-MFC or MFCProgramCalled.

B. regular DLL: similar to the following extension DLLs, it is written in the MFC class library. Obviously, there is a class that inherits cwinapp in the source file. It can be subdivided into static connection to MFC and dynamic connection to MFC.

The dynamic connection library for static connection to MFC is only supported by VC professional and Enterprise Edition. The output functions in such DLL applications can be used by any Win32 program, including the applications using MFC. The input function is in the following format:
Extern "C" Export yourexportedfunction ();
Without the extern "C" modifier, the output function can onlyCode.
DLL applications are derived from cwinapp, but there is no message loop.

The output function in the DLL application that dynamically links to the MFC rule can be used by any Win32 program, including the application that uses the MFC. However, all functions output from the DLL should start with the following statement:
Afx_manage_state (afxgetstaticmodulestate ())
This statement is used to correctly switch the status of the MFC module.

Regular dll can be called by all applications written in languages that support DLL technology. In this dynamic connection library, it must have a class inherited from cwinapp. The dllmain function is provided by MFC and does not need to be explicitly written by itself.

C. extension DLL: Used to reuse the classes inherited from MFC. That is to say, a dynamic Connection Library of this type can be used to output a class inherited from MFC. Its output functions can only be used by applications that use MFC and dynamically link to MFC. You can inherit the classes you want from MFC that are more suitable for your use and provide them to your applications. You can also provide the object pointer of the MFC or MFC inheritance class to your application at will. Extension DLL is created using the dynamic connection version of MFC, and is called only by applications written in the MFC class library. Extension DLLs is different from regular DLLs. It does not have a class Object inherited from cwinapp. Therefore, you must add initialization code and end code for your own dllmain function.

Compared with rule DLL:

1. It does not have an object derived from cwinapp;
2. It must have a dllmain function;
3. When dllmain calls the afxinitextensionmodule function, it must check the return value of this function. If 0 is returned, dllmmain also returns 0;
4. If you want to output a cruntimeclass object or resource, you must provide an initialization function to create a cdynlinklibrary object. In addition, it is necessary to output the initialization function;
5. the MFC application using extended dll must have a class derived from cwinapp, and the extended DLL initialization function is generally called in initinstance.

 

Reference: http://bbs.csdn.net/topics/80315152

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.