Improve company productivity with a Business Account.Sign Up

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 564
  • Last Modified:

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

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
JSW21
Asked:
JSW21
  • 4
  • 3
  • 2
2 Solutions
 
ZoppoCommented:
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
 
JSW21Author Commented:
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
 
ZoppoCommented:
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
Keep up with what's happening at Experts Exchange!

Sign up to receive Decoded, a new monthly digest with product updates, feature release info, continuing education opportunities, and more.

 
sarabandeCommented:
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
 
JSW21Author Commented:
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
 
sarabandeCommented:
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
 
JSW21Author Commented:
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
 
sarabandeCommented:
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
 
JSW21Author Commented:
Thanks, so i ended up using exe application but with minimal appearance.
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

Join & Write a Comment

Featured Post

Free Tool: Port Scanner

Check which ports are open to the outside world. Helps make sure that your firewall rules are working as intended.

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.

  • 4
  • 3
  • 2
Tackle projects and never again get stuck behind a technical roadblock.
Join Now