Pages

Using a DLL

The easiest way of using a DLL in your Windows C/C++ code requires us to use the LIB file, generated by the DLL compilation for letting the compiler know about the exported symbols. A third file that saves us some trouble in using a DLL is a (or more) header for the declaration of the available functions.

In our project property pages, linker section, General tab, we add in the Additional Library Directories the folder where our DLL is. Again in the Linker section, but Input tab, we change the Additional Dependency adding the LIB file relative to our DLL.

Now we can use the DLL in our code:

#include <iostream>
#include "..\xDll\xDll.h"

int _tmain()
{
std::cout << "A banal window app w/DLL" << std::endl;
f();

system("pause");
return 0;
}

Including the xDll.h header file we have available the declaration for the function, named f(), defined in the DLL, so we can use it in the code.

No comments:

Post a Comment