Want to protect your cyber security and still get fast solutions? Ask a secure question today.Go Premium


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

Posted on 2011-02-17
Medium Priority
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
  • 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 1000 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: http://msdn.microsoft.com/en-us/library/9se914de%28v=VS.80%29.aspx - i.e. in this sub-topic you may find further hints on how to decide which kind of DLL you should use: http://msdn.microsoft.com/en-us/library/253b8k2c%28v=VS.80%29.aspx

Hope that helps,



Modern healthcare requires a modern cloud. View this brief video to understand how the Concerto Cloud for Healthcare can help your organization.

LVL 35

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 35

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 35

Assisted Solution

sarabande earned 1000 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

Upgrade your Question Security!

Your question, your audience. Choose who sees your identity—and your question—with question security.

Question has a verified solution.

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

When writing generic code, using template meta-programming techniques, it is sometimes useful to know if a type is convertible to another type. A good example of when this might be is if you are writing diagnostic instrumentation for code to generat…
Basic understanding on "OO- Object Orientation" is needed for designing a logical solution to solve a problem. Basic OOAD is a prerequisite for a coder to ensure that they follow the basic design of OO. This would help developers to understand the b…
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 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.
Suggested Courses

572 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