Link to home
Start Free TrialLog in
Avatar of Evan Li
Evan LiFlag for United States of America

asked on

How to convert MFC APP to Win32 APP.

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.
Avatar of sarabande
sarabande
Flag of Luxembourg image

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
Avatar of Evan Li

ASKER

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
Avatar of Evan Li

ASKER

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.
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 ....
...
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
Avatar of Evan Li

ASKER

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.
Avatar of Evan Li

ASKER

CRT Libraries are very small, but MFC is pretty big.
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
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.
Avatar of Evan Li

ASKER

Are you saying, if we are doing it right, we have to install MFC140u.dll regardless if we use it or not?
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.
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.
Avatar of Evan Li

ASKER

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
Avatar of Evan Li

ASKER

I had a typo for the last comment:

I really could not convince people here to use this approach though.
How can I make the installer small, while I can still make the UI correctly
Rewrite your application.
Avatar of Evan Li

ASKER

Yes, it is coming back  to the question that I have asked. How to do it is a better approach.
ASKER CERTIFIED SOLUTION
Avatar of Julian Hansen
Julian Hansen
Flag of South Africa image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of Evan Li

ASKER

Thank you.
You are welcome, good luck.