How do I use a third-party DLL file in Visual Studio C++?

Zombies picture Zombies · Jan 30, 2009 · Viewed 210.9k times · Source

I understand that I need to use LoadLibrary(). But what other steps do I need to take in order to use a third-party DLL file?

I simply jumped into C++ and this is the only part that I do not get (as a Java programmer). I am just looking into how I can use a Qt Library and tesseract-ocr, yet the process makes no sense to me and is so difficult to google.

How do I tell the compiler of the functions that I am using? Should there be an include file from the third-party vendor?

Answer

Mark Ransom picture Mark Ransom · Jan 30, 2009

As everyone else says, LoadLibrary is the hard way to do it, and is hardly ever necessary.

The DLL should have come with a .lib file for linking, and one or more header files to #include into your sources. The header files will define the classes and function prototypes that you can use from the DLL. You will need this even if you use LoadLibrary.

To link with the library, you might have to add the .lib file to the project configuration under Linker/Input/Additional Dependencies.