Solved

Static Linking instead of using dll

Posted on 2006-07-13
5
1,168 Views
Last Modified: 2013-11-20
My MFC application  currently links dynamically to a "dll file", which I have to provide when i ship the software. The dll is a MFC dll project.

I am trying to convert the MFC Application to do a STATIC linking process instead of Dynamic Linking (with the dll or a lib file)  

Is the "Implicit Linkng" option similar to the static link option ? I am getting confused between the implicit and explicit linking methods used in Visual Studio for linking MFC projects...
http://msdn2.microsoft.com/en-us/library/253b8k2c.aspx

What is the best way to proceed in order to perform a static link when i have MFC dll and a MFC executable.

Thanks
0
Comment
Question by:hari4130
  • 2
5 Comments
 
LVL 22

Accepted Solution

by:
mahesh1402 earned 350 total points
ID: 17106040
>>I am getting confused between the implicit and explicit linking methods used in Visual Studio for linking MFC projects...

In Implicit linking you link in a very small lib file that contains little more than a jump table, and at run the time OS loads the DLL and fills in the jump addresses. but if the DLL is not found your program doesn't run.

Explicit linking is awkward but gives you flexible control.  You have to load the DLL yourself (LoadLibrary) and get and use function pointers to the functions you wish to call (GetProcAddress).  But your program can run without the DLL, you can select which DLL to load at run time and you can select when and if the DLL is loaded.  It is a primitive form of a "plug-in" option.

In static linking, the linker gets all the referenced functions from the static link library and places it with your code into your executable. Using DLLs instead of static link libraries makes the size of the executable file smaller. Dynamic linking is faster than static linking. but in static mfc linking you don't have to redistribute mfc*.dll etc with program.

If you statically link to the MFC code library, your .DLL will incorporate within itself all the MFC code it needs. Thus, it will be a larger .DLL, but it won't be dependent on the client computer having the proper MFC code library .DLL. If you can't rely on the host computer having the right version of MFC available, this is the way to go. If your application users are all within your own company, and you have control over what versions of the MFC .DLLs are lurking on their computers, or if your installation program also loads the right MFC .DLL, this might not be an issue.

http://www.codeguru.com/cpp/cpp/cpp_mfc/tutorials/article.php/c4017/
http://www.codeguru.com/cpp/cpp/cpp_mfc/tutorials/article.php/c4019/

-MAHESH
0
 
LVL 22

Expert Comment

by:mahesh1402
ID: 17106058
>>What is the best way to proceed in order to perform a static link when i have MFC dll and a MFC executable.

Creating Static-linked Executables using VC++ :http://www.codeproject.com/dll/staticlink.asp <====

-MAHESH
0
 
LVL 5

Expert Comment

by:bastibartel
ID: 17172326
Hi there,

If I understand your question right, you would like to link statically to some library (DLL) that you currently have to ship along.
That is not possible, unless you can rebuild that library, i.e. have te source code at hand.
If you do, you must turn the DLL project into a static library project - ask along if that is an option for you.

The 'link statically/dynamically' option in DevStudio refers to the actual MFC libraries only, that is to the parts that represent MFC functionality.
It has nothing to do with other libraries, may they be your own or third party, and may they be using MFC or not.

The only concern of yours will be, that programs that are linked to MFC dynamically will usually not work with DLL's linked statically to MFC (and vice versa)
But that is currently not your problem I suppose.

Cheers,
Sebastian


0

Featured Post

Free Tool: Subnet Calculator

The subnet calculator helps you design networks by taking an IP address and network mask and returning information such as network, broadcast address, and host range.

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

Title # Comments Views Activity
How to create frequencies of a variable from SAS dataset? 10 133
modThree challenge 4 98
haveThree challenge 22 121
Updating statistics with error notification email in SQL server 4 110
Here is how to use MFC's automatic Radio Button handling in your dialog boxes and forms.  Beginner programmers usually start with a OnClick handler for each radio button and that's just not the right way to go.  MFC has a very cool system for handli…
Introduction: Hints for the grid button.  Nested classes, templated collections.  Squash that darned bug! Continuing from the sixth article about sudoku.   Open the project in visual studio. First we will finish with the SUD_SETVALUE messa…
This video will show you how to get GIT to work in Eclipse.   It will walk you through how to install the EGit plugin in eclipse and how to checkout an existing repository.
I've attached the XLSM Excel spreadsheet I used in the video and also text files containing the macros used below. https://filedb.experts-exchange.com/incoming/2017/03_w12/1151775/Permutations.txt https://filedb.experts-exchange.com/incoming/201…

830 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