How to include, load, and use a .dll in c++

3.6k views Asked by At

I am new to using .dll's in c++ and am trying to load a .dll file in my code. The dll is "Extremely Simple Capture API" or escapi.dll . The site I got the .dll from did not include a library file with the .dll, and considering I don't know how to load a .dll with the library file, trying to do it without it is doubly hard. i just want to take a snapshot with the webcam on the computer and display the image on the screen.

The functions I use from the .dll to do this are:

int setupESCAPI(int height, int width);
int initCapture(SimpleCapParams *capture);
void doCapture();
void isCaptureDone();
void deinitCapture();

If anyone can give me easy instructions on how to include this .dll without a .lib file, I would appreciate it. Thanks.

Dan

2

There are 2 answers

1
Jim Rhodes On

I looked at the download for ESCAPI and it has all you need. Just include escapi.cpp in your project and call setupESCAPI. setupESCAPI loads the DLL for you. You will also need to put the DLL in the same folder as your executable.

0
Grantly On

An elegant way to link to DLLs is dynamically. Then no LIB file is required, and you can have nicer error management. This article is good:

http://msdn.microsoft.com/en-us/library/ms810279.aspx

What you basically do is create prototypes in C++ of the functions you want to call in the DLL. (Not exactly prototypes, but you can think of them the same way)

Then call LoadLibrary to load the DLL, and GetProcAddress to link your prototype to each function in the DLL.

Then you can call your 'functions' (prototypes) - and they will be attached to the functions in the DLL