Using DLL in C++ project -


have dll library documentation, has no header file. there simple way use functionality of library in c++ program? - how reference dll codeblocks? in advance.

as long have documentation exported dll functions, don't need header file (or import library), need know aspects of function calling.

the documentation should include

  1. function name
  2. function argument types
  3. return type
  4. calling convention (__stdcall, __cdecl, etc.)

once have information, have need call exported dll function(s).

so example, let's 1 of exported functions returns long , takes arguments, 2 dwords. calling convention __stdcall. name of function "func1";

#include <windows.h> #include <tchar.h>  typedef long (__stdcall *myfunc)(dword, dword); int main() {    // load dll    hmodule hmod = loadlibrary(_t("mydll.dll"));       if ( hmod )  // check if dll loaded    {        dword arg1 = 10;        dword arg2 = 20;        long return_value;         // function        myfunc fn = (myfunc)getprocaddress(hmod, "func1");         // make sure function exists        if ( fn )           return_value = fn(arg1, arg2);  // call function        //...        //...        // unload dll if no longer needed        freelibrary( hmod );     } } 

note calls loadlibrary, getprocaddress, , freelibrary. these windows api functions need familiar call exported dll functions.

also note checks ensure library loads successfully, function exists, etc.

links docs:

loadlibrary

freelibrary

getprocaddress


Comments

Popular posts from this blog

python - No exponential form of the z-axis in matplotlib-3D-plots -

php - Best Light server (Linux + Web server + Database) for Raspberry Pi -

c# - "Newtonsoft.Json.JsonSerializationException unable to find constructor to use for types" error when deserializing class -