18

How do I import a DLL (minifmod.dll) in C++ ?

I want to be able to call a function inside this DLL. I already know the argument list for the function but I don't know how to call it.

Is there a way of declaring an imported function in C++ like in C# ?

Kristina Brooks
  • 15,329
  • 28
  • 106
  • 178

3 Answers3

16

The c# syntax for declaring an imported function is not available in c++. Here are some other SO questions on how to use DLLs:

Community
  • 1
  • 1
luke
  • 34,649
  • 7
  • 57
  • 81
6

If the DLL includes a COM type library, you can use the #import statement as such:

#import dllname.dll

Otherwise, you'll need to link with an import library, and you'll need to provide a function prototype for your compiler. Typically the import library and a header file with the prototypes are provided by the DLL developer. If you're not, they can be very difficult to produce - unless you already know the argument list for the function, which you say you do. Instructions can be found here, amongst other places.

Russell Newquist
  • 2,626
  • 2
  • 14
  • 18
1

At runtime you can call LoadLibrary() and then call GetProcAddress() to access the function from a DLL. You will need to cast this address to a prototype you define with typedef . See the example at GetProcAddress documentation page.

Serge Rogatch
  • 12,441
  • 6
  • 72
  • 134