Solved

Static Linking instead of using dll

Posted on 2006-07-13
5
1,161 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

What Is Threat Intelligence?

Threat intelligence is often discussed, but rarely understood. Starting with a precise definition, along with clear business goals, is essential.

Join & Write a Comment

Suggested Solutions

Title # Comments Views Activity
maven archtype selection in eclipse 1 51
isEverywhere  challenge 19 64
post4 challenge 28 83
Thin secure Windows 10 5 49
Introduction: The undo support, implementing a stack. Continuing from the eigth article about sudoku.   We need a mechanism to keep track of the digits entered so as to implement an undo mechanism.  This should be a ‘Last In First Out’ collec…
Exception Handling is in the core of any application that is able to dignify its name. In this article, I'll guide you through the process of writing a DRY (Don't Repeat Yourself) Exception Handling mechanism, using Aspect Oriented Programming.
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.
This tutorial demonstrates a quick way of adding group price to multiple Magento products.

762 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

19 Experts available now in Live!

Get 1:1 Help Now