Cheat Engine Forum Index Cheat Engine
The Official Site of Cheat Engine
 
 FAQFAQ   SearchSearch   MemberlistMemberlist   UsergroupsUsergroups   RegisterRegister 
 ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 


How to call C DLL function from Delphi DLL.

 
Post new topic   Reply to topic    Cheat Engine Forum Index -> General programming
View previous topic :: View next topic  
Author Message
Daniel1983
How do I cheat?
Reputation: 0

Joined: 27 May 2018
Posts: 2

PostPosted: Sun May 27, 2018 5:07 pm    Post subject: How to call C DLL function from Delphi DLL. Reply with quote

Code:
bool gl_draw_text(uint x, uint y, uint color, uint alpha, char *fmt, ...)

Is the function in C code.

I added:

Code:
__declspec( dllexport ) bool gl_draw_text(uint x, uint y, uint color, uint alpha, char *fmt, ...); 

in the .h file (honestly, I have no clue if that is actually right).

In delphi:

Code:
function DrawFont(
    x: LongWord;
    y: LongWord;
    colour: LongWord;
    alpha: LongWord;
    thetext: AnsiString
 ): boolean; stdcall; external 'test.dll' name 'gl_draw_text';


But when I use DrawFont... crash. I traced in asm and it is finding gl_draw_text in target dll - but clearly I am doing this very wrong.

I don't know what type "..." is either.
Back to top
View user's profile Send private message
atom0s
Moderator
Reputation: 198

Joined: 25 Jan 2006
Posts: 8517
Location: 127.0.0.1

PostPosted: Mon May 28, 2018 3:00 am    Post subject: Reply with quote

... in C++ is used for variable arguments.

Meaning any number of arguments to fulfill the previous parameters formatting in your case.

_________________
- Retired.
Back to top
View user's profile Send private message Visit poster's website
Dark Byte
Site Admin
Reputation: 458

Joined: 09 May 2003
Posts: 25288
Location: The netherlands

PostPosted: Mon May 28, 2018 4:41 am    Post subject: Reply with quote

try
Code:

function DrawFont(
    x: LongWord;
    y: LongWord;
    colour: LongWord;
    alpha: LongWord;
    thetext: AnsiString
 ): boolean; cdecl; vararg; external 'test.dll' name 'gl_draw_text';

_________________
Do not ask me about online cheats. I don't know any and wont help finding them.

Like my help? Join me on Patreon so i can keep helping
Back to top
View user's profile Send private message MSN Messenger
Daniel1983
How do I cheat?
Reputation: 0

Joined: 27 May 2018
Posts: 2

PostPosted: Mon May 28, 2018 6:39 am    Post subject: Reply with quote

Thanks for the response Dark Byte!

That rectified the "..." part - but still crash. I think it's the calling part (delphi) where the fail is happening. Something about this extra argument thing the two languages don't like when one is calling the other.

Variable parameters doesnt seem a very stack friendly thing regardless to me.


edit.


Nope. It was my fault. I was calling the function from inside a different thread. Rookie mistake! It works fine now. Thanks Dark Byte. Very Happy
Back to top
View user's profile Send private message
Display posts from previous:   
Post new topic   Reply to topic    Cheat Engine Forum Index -> General programming All times are GMT - 6 Hours
Page 1 of 1

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum
You cannot attach files in this forum
You can download files in this forum


Powered by phpBB © 2001, 2005 phpBB Group

CE Wiki   IRC (#CEF)   Twitter
Third party websites