A Division of Labor Development Mode Using MFC Dynamic Link Library Technology

Source: Internet
Author: User

Source http://download1.csdn.net/down3/20070613/13191226649.rar

Description (figure) http://download1.csdn.net/down3/20070613/13191931524.rar

A model for Division of Labor Development Using VC Dynamic Link Library Technology

When using VC to develop project projects, many people often encounter cooperative development. In this case, the entire project must be divided into different small independent sub-modules.

1. Add a workspace
File-> New... -> Enter the project name as the workspace name.
 
2. Add the main program
FileView-> workspace 'project' right-> Add new project to Workspace
Select the MFC Appwizard (exe) Name main
Remove document/view architecture
Finish

3. Add the sub-project DLL sub1
File View-> workspace 'project' right-> Add new project to Workspace
Select the MFC Appwizard (DLL) Name sub1
OK finish
 
4. Set debugging information for the project
Project-> setting...
Ensure that main and sub1 are selected, and the general labels intermediate file and output files are all changed to ../debug to ensure that the debugging information is in the same directory.
 
Project-> dependencies...
Select "Main" and check "sub1 ".
In this way, you can compile sub1 first when compiling main.

File View-> main files-> right build
In the project/debugdirectory, files such as main.exe and sub1.dll are generated.

5. Add a dialog box in the sub-project
File View-> sub1 files-> right set as active project

Insert-> resource...

Dialog-> new insert dialog box
 
In the dialog box, right-click-> classwizard... -> Create a new class name csub1dlg
 
6. Add dialog box interface functions
Add in sub1.cpp
Extern "C" _ declspec (dllexport) void callsub1dlg ()
{
Csub1dlg test;
Test. domodal ();
}
Add header files
# Include "sub1dlg. H"

7. Add the call function in the main program
File View-> main files-> right set as active project
Classview-> cmainframe-> Add member fuction...
Void menuclick (cstring dllname, cstring funcname) // DLL name, function name in DLL
His content is as follows:
Void cmainframe: menuclick (cstring dllname, cstring funcname)
{
Hinstance exe_hinstance = afxgetresourcehandle (); // obtain the handle of the EXE Module
Typedef void (winapi * testdll) (void );
Hinstance hmod;
Hmod =: loadlibrary (dllname );
Hinstance dll_hinstance = getmodulehandle (dllname); // obtain the DLL module handle
If (hmod = NULL)
{
Cstring dllstr;
Dllstr. Format ("% s file call failed", dllname );
Afxmessagebox (dllstr );
Return;
}
Testdll lpproc;
Lpproc = (testdll) getprocaddress (hmod, funcname );
# Ifdef _ debug
If (lpproc = (testdll) null)
{
Freelibrary (hmod );
Cstring STR;
Str. Format ("% s file % s function call failed", dllname, funcname );
Afxmessagebox (STR );
Return;
}
# Endif // used for debugging

If (lpproc! = (Testdll) null)
{
Afxsetresourcehandle (dll_hinstance); // Switch Status
(* Lpproc )();
}
Afxsetresourcehandle (exe_hinstance); // restore the status
Freelibrary (hmod );
}
 
8. Call

Resourceview-> idr_mainframe double-click to add a menu item, call the sub-project, and add two items under it: 111,222
Add a function for 111 using the wizard
 
Add code to the Function
Menuclick ("sub1.dll", "callsub1dlg ");

CTRL + F5 run. If you are prompted to select the EXE program dialog box, select the run EXE file!

Click 111 to bring up the dialog box in DLL.
9. Expansion
After that, if you need to add another dialog box, you can also continue to add the dialog box and create a function for it,
You can also create a new DLL to encapsulate some independent functions.

In this way, we can put each independent module of the program in a DLL, and then call it through the main program to achieve the purpose of division of labor; if it is developed by itself, it can also be like this, in this way, a large project can be divided into several small projects to reduce the difficulty of development and maintenance.

 

Source http://download1.csdn.net/down3/20070613/13191226649.rar

Description (figure) http://download1.csdn.net/down3/20070613/13191931524.rar

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.