View previous topic :: View next topic |
Author |
Message |
Daniel1983 How do I cheat? Reputation: 0
Joined: 27 May 2018 Posts: 2
|
Posted: Sun May 27, 2018 5:07 pm Post subject: How to call C DLL function from Delphi DLL. |
|
|
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 |
|
|
atom0s Moderator Reputation: 198
Joined: 25 Jan 2006 Posts: 8518 Location: 127.0.0.1
|
Posted: Mon May 28, 2018 3:00 am Post subject: |
|
|
... 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 |
|
|
Dark Byte Site Admin Reputation: 458
Joined: 09 May 2003 Posts: 25296 Location: The netherlands
|
Posted: Mon May 28, 2018 4:41 am Post subject: |
|
|
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 |
|
|
Daniel1983 How do I cheat? Reputation: 0
Joined: 27 May 2018 Posts: 2
|
Posted: Mon May 28, 2018 6:39 am Post subject: |
|
|
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. |
|
Back to top |
|
|
|