Create an MFC extension DLL in Visual C ++

Source: Internet
Author: User

Create an MFC extension DLL in Visual C ++We compiled an example of the extension class and encapsulated it in the DLL to show you this process.

Some tested windows programmers gradually release the Windows SDK, however, it is switched to an open environment that provides high-level image extraction for low-level computers in windows. One of the main benefits of this type of transfer is Visual C ++, which relies on the MFC library to provide visual images for the Windows API.

MFC is a powerful tool held by experienced programmers, but it is far away from the beauty. In fact, all the people I know who use the MFC programming as their mobile phone segment have developed their own expansion and integration, they use the MFC class as the base class to create their own classes. This is the power of C ++. If a class cannot meet your needs (and if it is good enough, it can start with as a design ), you can generate a new class from the place where it is from and modify the part that you don't like.

Assume that you have compiled an MFC expansion and expansion set, and are willing to share it with its launch staff of the company. How can you install these extensions? You can separate the source code files or the components that are compatible with the visual C ++ Component Library (Component Gallery. Or you may block your expansion in DLL like MFC. Just as the traditional dll can export the number of functions, the MFC expansion dll can export the class. Any dynamic link that can be connected to the mfc dll can be connected to the MFC expansion DLL in the process sequence. As the initiator, you only need to include the required header file and add DLL import to the database in the Link-to-column table of the application procedure.

Is it difficult to compile the MFC expansion DLL? With the support of Visual C ++ and MFC, this is often loose. This article explains how to create an MFC extension DLL to fill in the ctooltipctrl class of MFC. Once you understand its simplicity, you will not be able to endure the expansion of several self-compiled MFC files.

    Compile and write the MFC extension DLL

From the perspective of theory, the ctool-tipctrl class of MFC simplifies the tooltip) the process of connecting to any region of the phone holder or window port. (Information delivery refers to the small pop-up window for help text when the mouse indicator stops on the work bar and presses the button or its UI is opposite to the image. ) But there is a question to be solved. Because ctooltipctrl: addtool cannot be automatically converted into a sub-class that provides information according to the window, because this mouse badge must be handed over to the Information Delivery Control System by hand. This often implies that you must create a subcategory for the window.

If you send a correct logo to the information control system under the ctooltipctrl object, it should be able to create sub-classes for itself-this is obviously a function of being omitted by the MFC design group. Fortunately, it is not difficult to correct it. You only need to generate a class from the ctooltipctrl class, and replace the ctooltipctrl: addtool with the class-like function generation, the ttm_addtool message of this function is constructed using toolinfo. Its uflags field contains ttf_subclass logs. A better method is to replace it with two function generations: they do not add information to the sub-window and the moment-shaped window domain. The addtool function supports two recipients at the same time, but the two methods used to create the creden。 are not the same in the syntax structure.

Figures 1 and 2 show the source code of the ctooltipctrl class named ctooltip-ctrlex. The school class adds two numbers of letters to its capacity. Its ctooltipctrl: addwindow is connected with the sub-window interface, the second addrectangle adds the information to the moment region of the window. Both of these two functions use ttf_subclass to simplify the process of creating information. The false m_tooltipctrl is the ctooltipctrlex object. It is quite easy to add a prompt message to the button whose control ID is idc_button:

M_tooltipctrl.addwindow (

Getdlgitem (idc_button ),

"Enter tooltip text here! ");

How can I seal the ctooltipctrlex class into a DLL? The detailed steps in Visual C ++ 4.x are as follows:

1. Start visual c ++ and select new from the File menu to create a new project. Double-click the project workspace. In the Name box of the new project workspace, enter "mfcext" (without a reference number ). Select MFC Appwizard (DLL) in the Type box ). Then, click the create button.

2. In the Step 1 dialog box of Appwizard, you can use the "What type of DLL wocould you like to create ?" Select "MFC extension DLL (using shared mfc dll )". Click Finish and then click OK to generate the initial Generation Code of the DLL. Note that "using shared mfc dll" is displayed in the ARC after "MFC extension DLL ". When you compile the MFC expansion DLL, you cannot select static link to MFC. Dll must be dynamically linked to the MFC library.

3. Pop Up classwizard and click Add class to press the button. Select new and open the create new class dialog box. Select ctooltipctrl in the "base class" box, and enter "ctooltipctrlex" in the "name" box ". Use the change button to change the file name to tooltip. h and tooltip. cpp. (Changing the file name is not mandatory. I want to avoid long file names .) Do not select the "add to component Gallery" box to save the disk space. Click Create to execute the classwizard class, and then click OK to return the classwizard.

4. As shown in figure 2, add the member number addwindow and addrectangle to the ctooltipctrlex class. The result is that these two letters are to be accessed outside ctooltipctrlex, because they are all public. Skillful: in Visual C ++, you can add a member letter to the class by right-clicking the class name in the classview window, select Add function from the quick food list.

5. In the classview window, double-click ctooltipctrlex to open the Class header file. Add afx_ext_class after the class key in the class description (see figure 1 ).

6. Create a project. You will generate two important documents: the DLL itself (mfcext. dll) and the DLL import library (mfcext. Lib ). The imported database is based on the column table with the number of export function names -- or, in this example, a series of column export classes. Link to the imported database so that the program sequence can be used to export classes from the MFC extension DLL, for example, databases with classes in the same package are statically chained. Linking with mfcext. Lib also makes it possible for Windows to run the program sequence mfcext. dll.

    Use MFC to expand DLL

The procedure for creating and using mfcext. dll is light and easy to cite. You only need to ensure that tooltip is included in each class that uses ctooltipctrlex. h header file, and the mfcext. LIB can be added to the link library column table of the project. Then ctooltipctrlex can be used like the common MFC class. When you reply to the Appwizard query, You must select "as a shared DLL". In this case, you must use the procedural sequence to link the dynamic state chain to MFC. You can select Settings from the build menu of Visual C ++ to select mfcext. lib is added to the link column table of the Project. Click the link tag and enter mfcext in the box marked with "Object/library modules. lib path (see figure 3 ).

Tooltest is the application sequence used as an example. It displays a button in the dialog box. It dynamically links to mfcext. dll and uses ctooltipctrlex. The program sequence is based on the peer box. The dialog class package contains the ctooltipctrlex variable named m_tooltipctrl. In the oninitdialog function of the phone box, the following code is used to create an information control system, and the following buttons are used to set the information to be presented:

M_tooltipctrl.creat (this );

M_tooltipctrl.addwindowtool (

Getdlgitem (idc_exit ),

"Click here to close ");

When the cursor is stopped on the button, the "Click here to close" dialog box is displayed ". Click the button to close the application process.

You can use the full source code of tooltest and mfcext. dll from PC Magazine online (www.pcmag.com. Select downloads from the menu on the left of the main page, and then select PC tech archives and file v16n15.zip. This article is also available on the utilities/TIPS theory Library (go znt: Tips) of CompuServe. Our file package is included in this file. Decompress the file (mfcext.zip and tooltest.zip) with the-D option of pkunzip to decompress the contents in the. ZIP file. Copy mfcext. DLL to the Windows System directory or tooltest.exe before running tooltest. If the tooltest is executed, you cannot find mfcext. dll in windows. If you create your own tooltest.exe version, modify the path name of the "Object/library modules" box in the Project Settings dialog box, so that visual C ++ can find mfcext in the PC. lib file.

    Summary

Creating an MFC expansion DLL is not always easy-you only need to know what to do. When you develop an MFC extension DLL for it, you do not need to remember to provide a description of the class headers in the DLL and corresponding. lib file and DLL. After that, the launch staff will be able to use your package for expansion.

Related Article

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.