Solved

How to convert MFC APP to Win32 APP.

Posted on 2016-09-11
19
53 Views
Last Modified: 2016-09-15
As MFC either need statically link to app or install extra DLL, which consume a lot system resources, we need to convert my UI program that is developed in MFC convert to Win32 program, which will not depend on Static lib or DLL, so that we can have a smaller binary and not to install MFC dlls. Does any one has a easy way to do it? Thanks for any help.
0
Comment
Question by:Evan Li
  • 9
  • 7
  • 3
19 Comments
 
LVL 32

Expert Comment

by:sarabande
Comment Utility
or install extra DLL, which consume a lot system resources
mfc dll is some of the most used class libraries in the world. you will not find a windows desktop system that doesn't has mfc installed. so on the best you may spare some space if your application was linked against a very old mfc or a very new mfc dll.

mfc class library is very close to winapi. and many controls like CEdit, CListbox, CStatic, easily could b replaced by using the window handle and native api functions instead. even listview and treeview could be handled with api functions. however, you were lost if you were using sdi or mdi framework for your application. even if your program was dialog-based but is using multiple dialogs in a property sheet, i would say, that the efforts to reimplement all the class functions by native api, is too high.

Sara
0
 

Author Comment

by:Evan Li
Comment Utility
Thank you for answering my question, we do not want to install any DLLs on users machine, is it possible that for windows 7 or later we do not install the MFC Dlls, my app will work, we could not statically link to MFC library, as it gets 4 MB, makes our program pretty large. Thanks for your help again
0
 

Author Comment

by:Evan Li
Comment Utility
I am using VS2015 and I looked at redistribute MFC apps for VS 2015. Looks it is still necessary to install the mfc14.dll. What I would like to do is to move MFC the code that has been used for my program, and compile and link to the code, that makes it no DLL need to be installed and No static linked library which makes the binary to be 3mb bigger. I just wonder does anyone did it, what it takes to do it? Thanks for any help.
0
 
LVL 51

Expert Comment

by:Julian Hansen
Comment Utility
To make your MFC app into a pure WinAPI app - you will need to rewrite the entire application as a WinAPI executable. You can copy some of the code over but all the window / control handling you will need to rewrite.

You are (I think) looking for an automated way to change your application into one that does not use MFC - just so you can get out of distributing the MFC DLL's but what about the other VC run times that are required for WinAPI functions to run - you still need those. No matter what you do you will have to install Microsoft runtimes.

When we redistribute apps we must make the SxS runtime a pre-requisite - we don't bundle it or try to install it we just list in our documentation
System Requirements
VS2015 Runtime avalable here http://www.microsoft.com ....
...
0
 
LVL 32

Expert Comment

by:sarabande
Comment Utility
What I would like to do is to move MFC the code that has been used for my program, and compile and link to the code, that makes it no DLL need to be installed and No static linked library which makes the binary to be 3mb bigger.
no, that is not possible. at least not with a reasonable effort. mfc is a class library based on afx sub system. also atl (active template library) is used by mfc to simplify access to COM. this all happens in the base classes and when using one or more higher-level classes like CDialog, CWnd, CMainFrame, .... you included all the stuff and the linker would demand all the functions which are available only in the mfc dll or static mfc library. i don't know of a mfc 'light' dll and don't believe that it could be made, since it would make unresolvable issues if you have two dll's exporting the same functions. so the only practical way would be to strip the static mfc library down to the amount of functions your application needs abd drop all others. but actually, your linker does that already for you. if you link statically against mfc library only those modules were taken from static library which were necessary, means that was called somehow from any of your classes or their dependent sub classes. in other words the 3 mb are already the minimum you can achieve as long as you were using the original mfc sources and mfc headers. as told, using mfc in a dll makes your application itself smaller and it is a good Chance that the mfc dll was used anyhow by any other application. look at a target system before installing your application whether the mfc140* dll's already existed or not. if not, you may install the vs2015 redistributable package (from MSDN), and search again. you will see that the dll's now were installed to system32 folder and syswow64 folder  (if 64 bit windows). the size of the dll's is about 10 mb, what is negligible for a 20 to 40 gb windows installation.

Sara
0
 

Author Comment

by:Evan Li
Comment Utility
Looks like my company does not allow me to add bigger redistributables and any exe that is large, not more 1 mb bigger, that is why I am seeking help here. The endpoint software could not predict what end machine is. Thanks.
0
 

Author Comment

by:Evan Li
Comment Utility
CRT Libraries are very small, but MFC is pretty big.
0
 
LVL 32

Expert Comment

by:sarabande
Comment Utility
The endpoint software could not predict what end machine is.
the setup of your application needs to install all redistributables needed for your application. that could be done by packaging the redistributable files from your development computer and install them at the target system. or, you invoke download and Installation of the appropriate redistribution package from MSDN from your setup utility. for both use cases your application would be built with mfc dll and should be small enough for your requirements.

note, as told the mfc dll's are in most cases already installed by other applications or the Windows os itself. therefore a smart setup utility would check existence of the redistributables and invoke the additional setup only if the target system doesn't have a proper environment.

Sara
0
 
LVL 51

Expert Comment

by:Julian Hansen
Comment Utility
CRT Libraries are very small, but MFC is pretty big.
Yes ... but if you are going to install the one you install the other. It is not a good idea only to distribute the one set of dlls. If you need the CRT libraries you download and install the VC Runtime for the version you are running - that gives you the MFC dll's as well - so irrespective of the size of the DLL you use you still end up installing both (if you are doing it right).

EDIT
Correction: you can include a merge module for the dll in your application - however personally I don't think this is the right course of action. If you need those DLL's get them from the SxS (Runtime) install from MS's website.
0
How your wiki can always stay up-to-date

Quip doubles as a “living” wiki and a project management tool that evolves with your organization. As you finish projects in Quip, the work remains, easily accessible to all team members, new and old.
- Increase transparency
- Onboard new hires faster
- Access from mobile/offline

 

Author Comment

by:Evan Li
Comment Utility
Are you saying, if we are doing it right, we have to install MFC140u.dll regardless if we use it or not?
0
 
LVL 51

Expert Comment

by:Julian Hansen
Comment Utility
I am saying when we distribute our VC2015 code we make it a requirement that the client installs this
https://www.microsoft.com/en-za/download/details.aspx?id=48145
That installs the MFC dll's and the CRT.
0
 
LVL 51

Expert Comment

by:Julian Hansen
Comment Utility
Footnote,
In the not too distant past there was a term we used in the industry called DLL hell - a situation brought about by every developer distributing his application with Microsoft DLL's bundled into the install - resulting in DLL's overwriting each other, the wrong versions being installed - one application breaking another.
It became a best practice to keep the Microsoft code separate from the bespoke code. Workstations were updated with official Microsoft packages for the required DLL's as a pre-requisite to installing the bespoke code.
Therefore, as far as I am concerned - if you are not distributing the full run time using the Microsoft install you are not doing it right - but that is just my opinion.
0
 

Author Comment

by:Evan Li
Comment Utility
Thank you Julian.

My company want the installation package is small, the total setup is only 5M, we have CRT library dlls included but not MFC, MS installation is about 14MB, I really could convince people here to use this approach though.

How can I make the installer small, while I can still make the UI correctly.

Thanks.

Evan
0
 

Author Comment

by:Evan Li
Comment Utility
I had a typo for the last comment:

I really could not convince people here to use this approach though.
0
 
LVL 51

Expert Comment

by:Julian Hansen
Comment Utility
How can I make the installer small, while I can still make the UI correctly
Rewrite your application.
0
 

Author Comment

by:Evan Li
Comment Utility
Yes, it is coming back  to the question that I have asked. How to do it is a better approach.
0
 
LVL 51

Accepted Solution

by:
Julian Hansen earned 500 total points
Comment Utility
Your question included
we need to convert my UI program that is developed in MFC convert to Win32 program, which will not depend on Static lib or DLL
The answer is - you need to rewrite your code.
It's like asking: My application was written Visual Basic - how do I make it into a Visual C application.

MFC is there to shortcut and encapsulate the Windows API - converting it is not a simple task - you would need to (as far as I am concerned) re-write the application from scratch pulling in the application logic from your existing application to work with the interface you build with the Windows API.

Not much else I can suggest on this
0
 

Author Comment

by:Evan Li
Comment Utility
Thank you.
0
 
LVL 51

Expert Comment

by:Julian Hansen
Comment Utility
You are welcome, good luck.
0

Featured Post

Do You Know the 4 Main Threat Actor Types?

Do you know the main threat actor types? Most attackers fall into one of four categories, each with their own favored tactics, techniques, and procedures.

Join & Write a Comment

Suggested Solutions

Errors will happen. It is a fact of life for the programmer. How and when errors are detected have a great impact on quality and cost of a product. It is better to detect errors at compile time, when possible and practical. Errors that make their wa…
In days of old, returning something by value from a function in C++ was necessarily avoided because it would, invariably, involve one or even two copies of the object being created and potentially costly calls to a copy-constructor and destructor. A…
The goal of the video will be to teach the user the difference and consequence of passing data by value vs passing data by reference in C++. An example of passing data by value as well as an example of passing data by reference will be be given. Bot…
The viewer will learn additional member functions of the vector class. Specifically, the capacity and swap member functions will be introduced.

744 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

18 Experts available now in Live!

Get 1:1 Help Now