Use of MFC - use MFC in shared DLLs, use MFC in static libraries

Reprinted from: http://blog.csdn.net/albertsh/article/details/52838419

foreword

When we use Microsoft Visual Studio software (that is, VS we often say), there is an item in the project properties called "MFC use", which contains different settings, which will affect the use of the programs we write. Today I In this case, let's summarize together to avoid making the same mistakes.

content

I wrote a small program yesterday, using the MFC application project, the version of the tool is VS2013, the project parameters are all default, there is a setting called "MFC use", the default setting is "Use MFC in shared DLL" ", although I saw it, but I didn't take it to heart. During the encoding, a problem that MFC reported an error using a multi-byte character set was solved. I won't expand it here. I handed it over to a user named "Little Lightning", and she took it to the company's computer with great excitement and used it, but the result was an error! ! !

write picture description here

"This program cannot be started because mfc120.dll is missing from the computer. Try reinstalling the program to solve this problem." When I saw this problem, the first thing I thought about was the dynamic link library, because I was using the one that VS2013 just used It is the library file of version 12.0, so it should be said that the library does not exist on the target machine. Of course, you can manually download the library file and add it to the "C:\Windows\System32" directory, but in the program development project, you cannot require all users You will do this, you can only find a solution from yourself.

Of course, I also carefully checked the parameter called "Use of MFC", which actually includes 3 options, as shown in the screenshot:

write picture description here

  1. Use standard Windows libraries   
  2. Using MFC in a static library   
  3. Using MFC in a shared DLL 

These three of course have different meanings:

  • The first, as the name suggests, is to use the WINDOWS SDK API library instead of the MFC class. Speaking of which, an MFC application does not use MFC classes. I couldn't figure it out at first. Later, I created a new MFC application project, and then filled in this parameter as this one, and then the program failed to compile, the specific error As shown in the figure below, this shows the problem. If it is an MFC project, the second or third item must be selected, and the first item "Use the standard Windows library" is prepared for non-MFC projects (I don't know if the understanding is correct, please enlighten me) .

write picture description here

  • The second refers to writing the relevant code in the DLL into the EXE file, the file is larger, but it can be run on a machine without the relevant DLL. Personally, I feel that it is better to use this option during program testing, at least to ensure the normal operation of the program.

  • The third is that the contents of some MFC DLLs are not included in the EXE file when packaging, so the EXE file is smaller, but the runtime requires the system to have related DLL files. This is the option that my program chose at the beginning, requiring at least the "mfc120.dll" library file in the target computer, otherwise it won't work.

Summarize

  • For the MFC application project, regarding the "Use of MFC" property, you should select "Use MFC in a shared DLL" or "Use MFC in a static library".
  • The "Use standard Windows library" option can only be used in non-MFC projects. If it is used in MFC projects, it will cause code compilation errors.
  • The "Use MFC in Shared DLL" option produces a smaller executable file, but requires that the target machine must have the necessary library files installed.
  • The program executable files generated by the "Use MFC in static library" option can be executed by almost all Windows, but the program is larger and contains the necessary library files, which can basically guarantee normal operation on other machines.

Guess you like

Origin http://10.200.1.11:23101/article/api/json?id=326769559&siteId=291194637