Want to win a PS4? Go Premium and enter to win our High-Tech Treats giveaway. Enter to Win

x
?
Solved

How to convert MFC APP to Win32 APP.

Posted on 2016-09-11
19
Medium Priority
?
300 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 9
  • 7
  • 3
19 Comments
 
LVL 35

Expert Comment

by:sarabande
ID: 41794430
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
ID: 41794824
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
ID: 41795190
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
What does it mean to be "Always On"?

Is your cloud always on? With an Always On cloud you won't have to worry about downtime for maintenance or software application code updates, ensuring that your bottom line isn't affected.

 
LVL 59

Expert Comment

by:Julian Hansen
ID: 41795520
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 35

Expert Comment

by:sarabande
ID: 41795598
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
ID: 41796287
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
ID: 41796289
CRT Libraries are very small, but MFC is pretty big.
0
 
LVL 35

Expert Comment

by:sarabande
ID: 41796397
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 59

Expert Comment

by:Julian Hansen
ID: 41796437
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
 

Author Comment

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

Expert Comment

by:Julian Hansen
ID: 41796521
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 59

Expert Comment

by:Julian Hansen
ID: 41796526
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
ID: 41796552
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
ID: 41796558
I had a typo for the last comment:

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

Expert Comment

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

Author Comment

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

Accepted Solution

by:
Julian Hansen earned 2000 total points
ID: 41796724
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
ID: 41796789
Thank you.
0
 
LVL 59

Expert Comment

by:Julian Hansen
ID: 41800984
You are welcome, good luck.
0

Featured Post

Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Written by John Humphreys C++ Threading and the POSIX Library This article will cover the basic information that you need to know in order to make use of the POSIX threading library available for C and C++ on UNIX and most Linux systems.   [s…
C++ Properties One feature missing from standard C++ that you will find in many other Object Oriented Programming languages is something called a Property (http://www.experts-exchange.com/Programming/Languages/CPP/A_3912-Object-Properties-in-C.ht…
The viewer will be introduced to the technique of using vectors in C++. The video will cover how to define a vector, store values in the vector and retrieve data from the values stored in the vector.
The viewer will be introduced to the member functions push_back and pop_back of the vector class. The video will teach the difference between the two as well as how to use each one along with its functionality.
Suggested Courses

618 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