How to access functions in custom DLLs?

How to access functions in custom DLLs? DLL in question would be bundled with my game. It is just simple wrapper for few WinAPI functions that I’d like to have access to.

Could you give me example of doing that using C++ feature?

Bumping question because I still need an answer. Basically I want to get access to Lazarus (Delphi clone based on Free Pascal) DLL that returns string and put that string in a global variable.

Please help me with that, I really need to do that in order to port my GM game to GD as it makes use of my WinAPI wrapper library.


I’ll release a new version fixing a bug related to C++ code and I’ll help you with that.

OK, thanks!

Now that new version is released, could you help me out?

I’ve written an article about using DLL: … ithcppcode :slight_smile:

Thanks! Does this tutorial work both for STDCALL and CDECL calling conventions? My lib uses STDCALL, but I’ve seen DLLs that use both.

Your code is compiled with gcc which uses CDECL so it should work for all dlls using this convention.

Actually library itself is written in Pascal which uses STDCALL. I could send it to you so you can see if it would work with your code and if not adjust it. I can always recompile my lib, but there are many libraries out there that uses STDCALL and which authors either lost sources or just don’t care. Many of those are so good that there aren’t as good C++ equivalents. For instance last month I’ve seen good (unfortunately commercial) terrain generation library (both Terraria-like 2d terrain and voxel world) that was written in Delphi and did most of heavy-lifting usually associated with terrain generation for programmer, leaving him/her to tweak world generation formulas kinda like ones you can use in that game Worlds. I bet it would cost big cash aside of standard license to either change convention (Delphi, Lazarus and free pascal itself are using stdcall by default) or give sources so I could do it myself (from what I read they offer source license, but it is like 10 times like standard - $300 and you must already have standard license)

You should be able to call functions using stdcall by telling the compiler to do so: Try to append __stdcall after the return type when declaring the function type:

typedef int __stdcall (*FuncType)(double parameter1, const char * parameter2);

(Note that I have not tried it by myself, but this is how functions are declared in headers using STDCALL convention)