How to link dll
I got a problem when I am trying to link other project in MS VC++. I made a project A and include and link the header and library in B without problem. But I can not find a good way to link dll of B, there for I have to copy all dll in A. Ugly! I think there must be a way to do it in MS VC++. Please help me. Thank you. :)
Linking to a library is possible because that is the function of compiled library files. You cannot link (at compile time [which is what it sounds like you're meaning]) to a DLL because of the very nature of a DLL ("Dynamic Link" Library). You must link dynamically (at run time) to a DLL file by loading it into your program's memory space. Look up LoadLibrary().
Thanks for help. I have just looked at it and it uses SetDllDirectory( LPCTSTR lpPathName). Since I have a couple of derectories of dll that has to be used at run time, I tried to set path in Env. variables of the system but it does not work. I have less exp. in using MS VC++, is there any where that allowing use dlls from other place like linking library? :)
Since DLLs are loaded at run time, you cannot specify anything within the MSVC IDE that has anything to do with it. If you set your PATH variable to include your DLL directories and they can't be loaded, try rebooting your system then giving it another shot. One thing to note, however, is that if you are distributing these DLLs, you should just use SetDllDirectory() because your end users likely won't be thrilled about having to modify their system path just so your app can find it's DLLs.
Thanks, I will try to use SetDllDirectory().
>>Since DLLs are loaded at run time, you cannot specify anything within the MSVC IDE that has anything to do with it.
Not 100% true.....
DLLs can be linked IMPLICITLY or EXPLICITLY.
Implicitly is at load time. It requires that you link the exe to the DLLs header and LIB file using the IDE (as you would to a .LIB). If you created the DLL these will have been produced by the DLL. The DLL can be written in any language as long as the correct calling conventions are defined in the DLLs functions.
If the DLL is not found the app will not run.
"The import library only contains code to load the DLL and to implement calls to functions in the DLL. Finding an external function in an import library informs the linker that the code for that function is in a DLL. To resolve external references to DLLs, the linker simply adds information to the executable file that tells the system where to find the DLL code when the process starts up."
Explicitly is at run time. You LoadLibrary(), lock the functions with GetProcAddress() and use the DLL code. When finished you 'drop' the DLL with FreeLibrary(). This means the DLL can be used as required and freed when not in use.
You may also need a .DEF file as in some cases the function names can get 'mangled'.
This form of linking is usually reserved for special uses
ie don't know which DLL you will use until run time.
not all versions of app will use DLL so some don't include it ie demo versions.
The DLL changes frequently and so don't want to link to its .LIB