Change from Application.exe to DynamicLibrary dll using vs 2003 vc++

Posted on 2011-02-17
Last Modified: 2012-05-11

If I wish to turn an exe application (Use MFC in a Shared DLL) into dll (Use standard windows libraries)

Since i dont enough the different between the two... How should i do it properly?

Question by:JSW21
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
  • 4
  • 3
  • 2
LVL 31

Expert Comment

ID: 34914980
Hi JSW21,

what kind of application is it? Is it an application which uses MFC? If so does it does it have a GUI (i.e. dialog, doc/view architecture MDI/SDI)? In which way do you plan to use the DLL (either impliciteley linked so you can use classes from the DLL in the calling app directly, or not linked so you only can access functions from the DLL using 'LoadLibrary/GetProcAddress')?


Author Comment

ID: 34915082
Sorry i mean to write as below

an exe application (Use MFC in a Shared DLL) into dll (Use MFC shared libraries)

the application do not have anything at the moment it only have a close button. it act as a server awaiting for a client.

I dont know enough yet to answer your question, but i wish to some how load this dll from other exe application and still preserve the same client and sever functionally.

LVL 31

Accepted Solution

Zoppo earned 250 total points
ID: 34915269
ok, I guess you're mixing up some things here.

First I don't know any 'Use MFC shared libraries' - I guess you meant 'Use MFC in a static Library'

The difference between 'Use MFC in a Shared DLL' and 'Use MFC in a static Library' has nothing to do with the fact whether you project should generate an EXE or a DLL. The difference is whether the MFC used in the EXE or DLL is linked statically to the binary or dynamically used from MFC DLLs.

It's not really easy to change an existing MFC Application to a MFC DLL, so I would suggest to create a new MFC DLL from the scratch and move the needed functionality from the EXE to the DLL (I'm not sure what you finally want to achieve, but when I read 'server' and 'client' maybe it might be a good idea to break it into two DLLs, one for the server, one for the clients - but that's your decision).

Now you still have to decide how you want to use the DLLs as I wrote before:

1. Impliciteley linked: This means your EXE can include headers from the DLL and links against a LIB created with the DLL - thus it's even possible to use classes, variables and functions exported by the DLL directly in the EXE as if they were part of the EXE.
- Advantage: the easy use of the DLL in the EXE.
- Disadvantage is that whenenver the DLL is changed each EXE which uses the DLL may need to be re-built using the current headers/LIBs.

2. Explicitely linked: In this case the EXE can only access and call functions which are expliciteley exported by the DLL. It's not possible to directly access variables or use classes from the DLL.
- Advantage: As long as with any changes in the DLL the exported functions don't change their signature each calling EXE can use it without needing a re-build. And, it's possible to i.e. implement an EXE which uses the DLL without any further needed data (so no headers, LIBs, ...).
- Disadvantage: Each function which should be called from the EXE has to be achieved using 'LoadLibrary' and 'GetProcAddress' whereas error handling has to be implemented - and, since 'GetProcAddress' just returns a pointer which has to be interpreted by the calling EXE to point to a function with a given signature there's absoluteley no type-safety, i.o. words i.e. if the DLL exports a function 'void foo( char* )' but the EXE for any reason wants to use it as 'int foo( char* )' a call to the function will lead to a corrupted stack.

So, that's a decision you have to make ... I think it's a good idea to start reading a lot from here: - i.e. in this sub-topic you may find further hints on how to decide which kind of DLL you should use:

Hope that helps,


Industry Leaders: 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!

LVL 34

Expert Comment

ID: 34915310
do you want to make your application a 'service'  which runs in background?

a service normally is more like a console application - though service control manager calls it similar to how an app calls a dll -  and has no GUI.


Author Comment

ID: 34916017
yep it was a dll that set to 'Use MFC in a Shared DLL'
I think I have much better idea what dll i want to create. I gonna try to create from scratch first hopefully it is not an impossible task.

LVL 34

Expert Comment

ID: 34916329
the main point was explained by zoppo: a dll needs some application which calls it. so normally a dll isn't a substitute for an app but you divide an app into a smaller app and one or more dll(s) where the dll gets all functions you might need in a further project again.

but it makes little sense to move the whole gui part of an app to a dll cause the main window of a mfc app should run in the main thread and not in dll.

so it also makes little sense to turn your mfc app project to a dll project but you should follow the advice zoppo gave to create a new dll project and move some functionality from app to dll.



Author Comment

ID: 34917410
I try to recreate the dll but it turn out that my server application now not working. So i guess i have to roll back to the idea of making the dialog... hidden or be as background work.

Can i just remove my Dialog in Resource View? If so how to initialize the exe anyway.
LVL 34

Assisted Solution

sarabande earned 250 total points
ID: 34917825
why not iconize the dialog in the taskbar?

if you remove the dialog resource the mfc app would have an error when calling DoModal in InitInstance function of your application class.

you need the message loop that is performed when calling DoModal.

but you alternatively can have a SDI app and hide the frame and view immediately after creation.

you even can prevent an icon in the taskbar though it might difficult to stop your application then.


Author Closing Comment

ID: 34923807
Thanks, so i ended up using exe application but with minimal appearance.

Featured Post

On Demand Webinar - Networking for the Cloud Era

This webinar discusses:
-Common barriers companies experience when moving to the cloud
-How SD-WAN changes the way we look at networks
-Best practices customers should employ moving forward with cloud migration
-What happens behind the scenes of SteelConnect’s one-click button

Question has a verified solution.

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

Suggested Solutions

The following diagram presents a diamond class hierarchy: As depicted, diamond inheritance denotes when two classes (e.g., CDerived1 and CDerived2), separately extending a common base class (e.g., CBase), are sub classed simultaneously by a fourt…
Introduction This article is the first in a series of articles about the C/C++ Visual Studio Express debugger.  It provides a quick start guide in using the debugger. Part 2 focuses on additional topics in breakpoints.  Lastly, Part 3 focuses on th…
The goal of the tutorial is to teach the user how to use functions in C++. The video will cover how to define functions, how to call functions and how to create functions prototypes. Microsoft Visual C++ 2010 Express will be used as a text editor an…
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…

726 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