Solved

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

Posted on 2011-02-17
9
531 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 31

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 31

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
Free Tool: SSL Checker

Scans your site and returns information about your SSL implementation and certificate. Helpful for debugging and validating your SSL configuration.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

 
LVL 33

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
 

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 33

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 33

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

Free Tool: Path Explorer

An intuitive utility to help find the CSS path to UI elements on a webpage. These paths are used frequently in a variety of front-end development and QA automation tasks.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

Suggested Solutions

Unlike C#, C++ doesn't have native support for sealing classes (so they cannot be sub-classed). At the cost of a virtual base class pointer it is possible to implement a pseudo sealing mechanism The trick is to virtually inherit from a base class…
Container Orchestration platforms empower organizations to scale their apps at an exceptional rate. This is the reason numerous innovation-driven companies are moving apps to an appropriated datacenter wide platform that empowers them to scale at a …
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 how to use the return statement in functions in C++. The video will also teach the user how to pass data to a function and have the function return data back for further processing.

839 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