Author Topic: Passing an array of float to a dll?  (Read 1991 times)

Offline backspace

  • Mr. Drawsprite
  • **
  • Posts: 53
    • View Profile
Passing an array of float to a dll?
« on: 2013-Jan-04 »
Hi again,
This time I have success. I looked into this wrapper thing, and this is the key to being able to call a dll made in GLBasic. It works and I am elated.
I can't thank you guys enough for your input, this is really totally awesome, and I will be able to build on from here.

Just to share what I have done, so that others may benefit from my effort, and the efforts of all the dll boffs that have posted their stuff on this forum, for people like me to learn from.

The dll source code. This is a project on it's own, and the resulting .dll must be copied into the calling .exe projects ".app" folder.

Code: (glbasic) [Select]
FUNCTION addem#: number1#, number2#
   LOCAL result#
   result# = number1# + number2#
   RETURN result#

EXPORT addem

The wrapper source code and the actual program that uses it. It is as Hemlos mentioned, this has to be included in the same project as the calling exe in order for it to work.

Wrapper source

Code: (glbasic) [Select]

   DECLARE_C_ALIAS(addit, "littledll.dll", "addem", (float, float), float);

FUNCTION addem#: num1#, num2#
LOCAL res#
PRINT ("DLL FOUND", 20,60);
res = addit(num1, num2);


Calling program source code

Code: (glbasic) [Select]
GLOBAL num1#, num2#, res#

num1# = 123.45
num2# = 234.21
res# = 101.01

res# = mydll.addem(num1#, num2#)

PRINT res#, 20,80

I had a lot of reading to do to see how others made their wrappers, and it seems that to embed it into a TYPE is the easiest and best way to go, That's how they seem to do it. And it works perfectly. With the wrapper, the compiled exe can now see the dll, and load it at runtime as is should. And the dll is written in GLBasic, which is what i was after all the time. And it works.

Thanks again for all your help guys. You are the Bomb.

The working exe and dll, as well as their projects are attached to show that it really does work

PS: Edited some typos. :D

[attachment deleted by admin]
« Last Edit: 2013-Jan-04 by backspace »
I came, I saw, I coded.

Offline mentalthink

  • Prof. Inline
  • *****
  • Posts: 3375
  • Integrated Brain
    • View Profile
Re: Passing an array of float to a dll?
« Reply #1 on: 2013-Jan-04 »
Thanks backSpace this it's very usefully, I try sometiago make something whit Dll, but my C++ it's very poor... I think this tutorials can be very good for people whit good skills in C++ and they want try "complex" things whit GLBasic..

Thanks a lot, I will take a look more in deep...   :booze: :booze: