Solved

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

Posted on 2011-02-17
9
506 Views
Last Modified: 2012-05-11
Hello

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?

0
Comment
Question by:JSW21
  • 4
  • 3
  • 2
9 Comments
 
LVL 30

Expert Comment

by:Zoppo
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')?

ZOPPO
0
 

Author Comment

by:JSW21
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.

0
 
LVL 30

Accepted Solution

by:
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: 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,

ZOPPO

0
 
LVL 32

Expert Comment

by:sarabande
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.

Sara
0
What Security Threats Are You Missing?

Enhance your security with threat intelligence from the web. Get trending threat insights on hackers, exploits, and suspicious IP addresses delivered to your inbox with our free Cyber Daily.

 

Author Comment

by:JSW21
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.

0
 
LVL 32

Expert Comment

by:sarabande
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.

Sara

0
 

Author Comment

by:JSW21
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.
0
 
LVL 32

Assisted Solution

by:sarabande
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.

Sara
0
 

Author Closing Comment

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

Featured Post

6 Surprising Benefits of Threat Intelligence

All sorts of threat intelligence is available on the web. Intelligence you can learn from, and use to anticipate and prepare for future attacks.

Join & Write a Comment

Often, when implementing a feature, you won't know how certain events should be handled at the point where they occur and you'd rather defer to the user of your function or class. For example, a XML parser will extract a tag from the source code, wh…
Introduction This article is a continuation of the C/C++ Visual Studio Express debugger series. Part 1 provided a quick start guide in using the debugger. Part 2 focused on additional topics in breakpoints. As your assignments become a little more …
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 viewer will learn additional member functions of the vector class. Specifically, the capacity and swap member functions will be introduced.

757 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

22 Experts available now in Live!

Get 1:1 Help Now