Reputation: 6862
I assume that if I receive a 3rd party DLL, I should also receive the following:
1) Headers with function prototypes
2) Static Linking Library or Import Library (same base name as DLL but with .LIB extension)
My confusion is that I don't understand how to link one Dll into another C++ DLL Project and Build it to link the dependencies properly. Where am I gonna get the function prototypes? For my DLL project, I am using .DEF file and not using __declspec(dlliexport). What Should I have as an absolute minimum to link DLLs to my C++ DLL project?
I know that the current consensus (and also from my research in SOF) is to:
1) Include the 3rd party header file that has got the external function prototypes (I don't have them). 2) Add the .LIB files through the Project Property sheet (in Visual Studio 2010).
Is that the way to go? Do I need to copy the DLLs to the executable folder? What is the correct procedure? Could someone please help me while I try to do this myself?
UPDATE
extern void this_is_dll_A(void); // Prints DLL_A
#include <stdio.h>
#include "Dll_A.h"
void this_is_dll_A(void)
{
printf("THIS IS DLL A\n\n\n");
}
I use the following def file for Dll_A project
LIBRARY Dll_A
EXPORTS
this_is_dll_A @1
#include "Dll_A.h"
extern void this_is_dll_B(void);
I add the include folder for Dll_A.h header file in the property sheet. Also, the .lib file and the containing folder in linker options. BUT NO DLLs.
#include <stdio.h>
#include "Dll_B.h"
void this_is_dll_B(void)
{
printf("This is dll B...and...\n\n");
this_is_dll_A();
}
I use d_b.def file for my Dll_B project
LIBRARY Dll_B
EXPORTS
this_is_dll_B @1
There is no imports?! not sure if this is right.
In my Dll_B project, I don't copy my Dll_A.dll
file in the Debug
folder which a lot of websites include SOF suggests doing.
It builds fine. THe problem is I am not sure whether I can/should do it without the header files. Also, how I should be doing it if I was to link Dll_B to an executable app project in VS2010.
Upvotes: 2
Views: 5082
Reputation: 7980
The build process you described is correct - link the DLL with the import library of the second DLL. As for runtime, both DLLs need to be in the DLL search path (PATH environment variable) or in the same directory as the exe. If the DLLs are not found, your application will not load.
There's an alternative method to load DLLs using the LoadLibrary function. In this case you don't link with the import library and have to map all the DLL imports by hand via GetProcAddress. This method is used for plugins - where all the DLLs have a known exposed interface.
Upvotes: 1