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
- function name
- function argument types
- return type
- 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 dword
s. 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:
Comments
Post a Comment